json_xema v0.1.3 JsonXema View Source
A JSON Schema validator.
Link to this section Summary
Functions
This callback initialize the schema. The function gets the data given to
Xema.new/1 and returns a Xema.Schema
Returns true if the value is a valid value against the given schema;
otherwise returns false
This function creates a new JsonXema from the given schema
Converts a %JsonXema{} into a %Xema{}
Returns true if the value is a valid value against the given schema;
otherwise returns false
Returns :ok if the value is a valid value against the given schema;
otherwise returns an error tuple
Returns :ok if the value is a valid value against the given schema;
otherwise raises a Xema.ValidationError
Link to this section Types
Link to this section Functions
init(bool)
View Source
init(boolean() | map()) :: Xema.Schema.t()
init(boolean() | map()) :: Xema.Schema.t()
This callback initialize the schema. The function gets the data given to
Xema.new/1 and returns a Xema.Schema.
Callback implementation for Xema.Behaviour.init/1.
is_valid?(schema, value)
View Source
is_valid?(JsonXema.t() | Xema.Schema.t(), any()) :: boolean()
is_valid?(JsonXema.t() | Xema.Schema.t(), any()) :: boolean()
Returns true if the value is a valid value against the given schema;
otherwise returns false.
new(data, opts \\ []) View Source
This function creates a new JsonXema from the given schema.
Possible options:
:resolver- a resolver for remote schemas. This option will overwrite the resolver from the config. See Configure a resolver to how to define a resolver.
Examples
iex> ~s({"type": "string"})
...> |> Jason.decode!()
...> |> JsonXema.new()
%JsonXema{refs: %{}, schema: %Xema.Schema{type: :string}}
to_xema(json_xema) View Source
Converts a %JsonXema{} into a %Xema{}.
valid?(schema, value)
View Source
valid?(JsonXema.t() | Xema.Schema.t(), any()) :: boolean()
valid?(JsonXema.t() | Xema.Schema.t(), any()) :: boolean()
Returns true if the value is a valid value against the given schema;
otherwise returns false.
validate(schema, value)
View Source
validate(JsonXema.t() | Xema.Schema.t(), any()) :: Xema.Validator.result()
validate(JsonXema.t() | Xema.Schema.t(), any()) :: Xema.Validator.result()
Returns :ok if the value is a valid value against the given schema;
otherwise returns an error tuple.
validate!(xema, value)
View Source
validate!(JsonXema.t() | Xema.Schema.t(), any()) :: :ok
validate!(JsonXema.t() | Xema.Schema.t(), any()) :: :ok
Returns :ok if the value is a valid value against the given schema;
otherwise raises a Xema.ValidationError.