JESSE (JSon Schema Erlang)
This is an interface module which provides an access to the main functionality of jesse, such as 1) updating of the schema definitions cache; 2) validation json data against a schema.allowed_errors() = non_neg_integer() | infinity
error_handler() = fun((jesse_error:error_reason(), [jesse_error:error_reason()], non_neg_integer()) -> list() | no_return())
error_list() = list()
external_validator() = fun((json_term(), any()) -> any()) | undefined
http_uri_uri() = string() | unicode:unicode_binary()
json_term() = term()
option() = {allowed_errors, allowed_errors()} | {default_schema_ver, schema_ver()} | {error_handler, error_handler()} | {external_validator, external_validator()} | {meta_schema_ver, schema_ver()} | {parser_fun, parser_fun()} | {schema_loader_fun, schema_loader_fun()}
options() = [option()]
parser_fun() = fun((json_term() | binary()) -> json_term())
schema() = json_term()
schema_id() = http_uri_uri() | undefined
schema_loader_fun() = fun((string()) -> {ok, schema()} | schema() | not_found)
schema_ref() = binary()
schema_ver() = binary()
validation_fun() = fun((any()) -> boolean())
add_schema/2 | Adds a schema definition Schema to in-memory storage associated with
a key Key . |
add_schema/3 | Equivalent to add_schema/2 , but Schema is a binary string, and
the third agument is a parse function to convert the binary string to
a supported internal representation of json. |
del_schema/1 | Deletes a schema definition from in-memory storage associated with
the key Key . |
load_schemas/2 | Loads schema definitions from filesystem to in-memory storage. |
load_schemas/3 | Loads schema definitions from filesystem to in-memory storage. |
main/1 | Run from CLI with arguments. |
validate/2 | Equivalent to validate/3 where Options is an empty list. |
validate/3 | Validates json Data against a schema with the same key as Schema
in the internal storage, using Options . |
validate_with_schema/2 | Equivalent to validate_with_schema/3 where Options
is an empty list. |
validate_with_schema/3 | Validates json Data agains the given schema Schema , using Options . |
add_schema(Key::string(), Schema::schema()) -> ok | jesse_error:error()
Adds a schema definition Schema
to in-memory storage associated with
a key Key
. It will overwrite an existing schema with the same key if
there is any.
add_schema(Key::string(), Schema::binary(), Options::options()) -> ok | jesse_error:error()
Equivalent to add_schema/2
, but Schema
is a binary string, and
the third agument is a parse function to convert the binary string to
a supported internal representation of json.
del_schema(Key::string()) -> ok
Deletes a schema definition from in-memory storage associated with
the key Key
.
load_schemas(Path::string(), ParserFun::fun((binary()) -> json_term())) -> jesse_database:store_result()
Loads schema definitions from filesystem to in-memory storage.
Equivalent toload_schemas(Path, ParserFun, ValidationFun)
where ValidationFun
is fun jesse_json:is_json_object/1
.
load_schemas(Path::string(), ParserFun::parser_fun(), ValidationFun::validation_fun()) -> jesse_database:store_result()
Loads schema definitions from filesystem to in-memory storage.
The function loads all the files from directory Path
, then each schema
entry will be checked for a validity by function ValidationFun
, and
will be stored in in-memory storage.
In addition to a schema definition, a timestamp of the schema file will be stored, so, during the next update timestamps will be compared to avoid unnecessary updates.
Schema definitions are stored in the format which json parsing function
ParserFun
returns.
main(Args::[string()]) -> ok
Run from CLI with arguments.
validate(Schema::schema() | binary(), Data::json_term() | binary()) -> {ok, json_term()} | jesse_error:error() | jesse_database:error()
Equivalent to validate/3
where Options
is an empty list.
validate(Schema::schema() | binary(), Data::json_term() | binary(), Options::options()) -> {ok, json_term()} | jesse_error:error() | jesse_database:error()
Validates json Data
against a schema with the same key as Schema
in the internal storage, using Options
. If the given json is valid,
then it is returned to the caller, otherwise an error with an appropriate
error reason is returned. If the parser_fun
option is provided, then
Data
is considered to be a binary string, so parser_fun
is used
to convert the binary string to a supported internal representation of json.
If parser_fun
is not provided, then Data
is considered to already be a
supported internal representation of json.
validate_with_schema(Schema::schema() | binary(), Data::json_term() | binary()) -> {ok, json_term()} | jesse_error:error()
Equivalent to validate_with_schema/3
where Options
is an empty list.
validate_with_schema(Schema::schema() | binary(), Data::json_term() | binary(), Options::options()) -> {ok, json_term()} | jesse_error:error()
Validates json Data
agains the given schema Schema
, using Options
.
If the given json is valid, then it is returned to the caller, otherwise
an error with an appropriate error reason is returned. If the parser_fun
option is provided, then both Schema
and Data
are considered to be a
binary string, so parser_fun
is used to convert both binary strings to a
supported internal representation of json.
If parser_fun
is not provided, then both Schema
and Data
are considered
to already be a supported internal representation of json.
Generated by EDoc