Nova plugin for validating input data against JSON schema.
First include nova_json_schemas
in your rebar.config
file:
{deps, [
{nova_json_schemas, {git, "https://github.com/novaframework/nova_json_schemas.git", {branch, "master"}}}
]}.
Update your router to make use of this plugin and to tell where JSON-schemas for each route will be located:
routes(_Environment) ->
[
#{prefix => "",
security => false,
plugins => [
{pre_request, nova_json_schemas, #{render_errors => true}},
{pre_request, nova_request_plugin, #{decode_json_body => true}}
],
routes => [
{"/my_route", {my_controller, do_something}, #{extra_state => #{json_schema => "./schemas/my_schema.jsons"}}}
]
}
].
Note! You need to invoke the nova_request_plugin
with decode_json_body
set to true AFTER the nova_json_schemas
in the list since Nova runs the plugins bottom-up.
Then put my_schema.jsons
that contains the schema in your priv/schemas/
directory (json schemas is read related from priv-directory of your main nova application).
If you find a bug or want to contribute either open a issue (Bug) or create a pull request :)