hello_jesse is JSON Schema (Draft 03) to Hello JSON-RPC parameter validation functions compiler. It uses jesse for validations against the schema. The project also includes rebar plugin for compiling schema files.
First of all, a valid schema file with .schema extension should be created. The file provides multiple schemas wrapped into array. Each schema must contain "title" property which corresponds to JSON-RPC method name.
// "math.schema"
[
{
"title" : "subtract",
"type" : "object",
"properties" : {
"subtrahend" : {
"type" : "number",
"required" : true
},
"minuend" : {
"type" : "number",
"required" : true
}
}
},
{
"title" : "add",
"type" : "object",
"properties" : {
"addends" : {
"type" : "array",
"items" : {
"type" : "number"
}
}
}
}
]
A schema file can be compiled with either hello_jesse:compile(PathToSchema, Options)
or hello_jesse:compile_dir(SchemasDir, Options)
. In both cases,
Options
is a list which can contain {outdir, Dir :: file:filename()}
option
denoting a target dir (default is "ebin").
The compiled schema is being written to hj_SCHEMA_NAME_schema module file.
The module exports a function per method which can be included directly into
Hello param_info/1
callback function.
param_info(subtract) -> hj_math_schema:subtract().
param_info(add) -> hj_math_schema:add().
Compilation can be done by rebar compile
if the following line is included in
rebar.config:
{plugins, [hello_jesse_plugin]}
The following config parameters can be specified:
{hello_jesse_plugin, [
{src, SchemaSrcDir},
{outdir, OutDir}
]}
Currently, parameters as array are not supported. In that case,
{error, <<"unsuported_params_as_array">>}
is returned.