Module jesse

JESSE (JSon Schema Erlang).

Description

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.

Data Types

allowed_errors()

allowed_errors() = non_neg_integer() | infinity

error_handler()

error_handler() = fun((jesse_error:error_reason(), [jesse_error:error_reason()], non_neg_integer()) -> list() | no_return())

error_list()

error_list() = list()

external_validator()

external_validator() = fun((json_term(), any()) -> any()) | undefined

http_uri_uri()

http_uri_uri() = string() | unicode:unicode_binary()

json_term()

json_term() = term()

option()

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

options() = [option()]

parser_fun()

parser_fun() = fun((json_term() | binary()) -> json_term())

schema()

schema() = json_term()

schema_id()

schema_id() = http_uri_uri() | undefined

schema_loader_fun()

schema_loader_fun() = fun((string()) -> {ok, schema()} | schema() | not_found)

schema_ref()

schema_ref() = binary()

schema_ver()

schema_ver() = binary()

validation_fun()

validation_fun() = fun((any()) -> boolean())

Function Index

add_schema/2Adds a schema definition Schema to in-memory storage associated with a key Key.
add_schema/3Equivalent 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/1Deletes a schema definition from in-memory storage associated with the key Key.
load_schemas/2Loads schema definitions from filesystem to in-memory storage.
load_schemas/3Loads schema definitions from filesystem to in-memory storage.
main/1Run from CLI with arguments.
validate/2Equivalent to validate/3 where Options is an empty list.
validate/3Validates json Data against a schema with the same key as Schema in the internal storage, using Options.
validate_with_schema/2Equivalent to validate_with_schema/3 where Options is an empty list.
validate_with_schema/3Validates json Data agains the given schema Schema, using Options.

Function Details

add_schema/2

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/3

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/1

del_schema(Key::string()) -> ok

Deletes a schema definition from in-memory storage associated with the key Key.

load_schemas/2

load_schemas(Path::string(), ParserFun::fun((binary()) -> json_term())) -> jesse_database:store_result()

Loads schema definitions from filesystem to in-memory storage.

Equivalent to load_schemas(Path, ParserFun, ValidationFun) where ValidationFun is fun jesse_json:is_json_object/1.

load_schemas/3

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.

NOTE: it's impossible to automatically update schema definitions added by add_schema/2, the only way to update them is to use add_schema/2 again with the new definition.

main/1

main(Args::[string()]) -> ok

Run from CLI with arguments.

validate/2

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/3

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/2

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/3

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