jvalid v0.5.1 JValid
Macro allows to include JSON Schema into your code and validate maps based on them.
Summary
Functions
Load schema at compile time to be later used in validator. This macro will include in inline in a function scope
Load schema at compile time to be later used in validator. This macro will include in inline in a module scope. It can save resources and reduce application size
Validate map using previously loaded schema. Returns true if schema is valid
Validate map using previously loaded schema.
Returns :ok
if map is valid, otherwise - {:error, reason}
Functions
Load schema at compile time to be later used in validator. This macro will include in inline in a function scope.
Example:
schema = load_schema "test/support/schema.json"
Load schema at compile time to be later used in validator. This macro will include in inline in a module scope. It can save resources and reduce application size.
Example:
defmodule Sample
use_schema :schema, "test/support/schema.json"
end
Validate map using previously loaded schema. Returns true if schema is valid.
Example:
use JValid
# Include schema in a module scope
use_schema :schema, "test/support/schema.json"
# ...
valid_schema?(:schema, map)
# Include schema in a function scope
"test/support/schema.json"
|> load_schema
|> valid_schema?(map)
Validate map using previously loaded schema.
Returns :ok
if map is valid, otherwise - {:error, reason}
.
Example:
use JValid
# Include schema in a module scope
use_schema :schema, "test/support/schema.json"
# ...
validate_schema?(:schema, map)
# Include schema in a function scope
"test/support/schema.json"
|> load_schema
|> validate_schema?(map)