Skip to content
This repository has been archived by the owner on Dec 24, 2019. It is now read-only.
/ hello_jesse Public archive

JSON Schema validations for Hello JSON-RPC framework

License

Notifications You must be signed in to change notification settings

sumup/hello_jesse

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hello_jesse

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.

Build Status

Dependencies

Usage

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().

Rebar plugin

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}
]}

Notes

Currently, parameters as array are not supported. In that case, {error, <<"unsuported_params_as_array">>} is returned.

About

JSON Schema validations for Hello JSON-RPC framework

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages