json_xema v0.3.1 JsonXema View Source
A JSON Schema validator.
Link to this section Summary
Functions
This function creates a new JsonXema
from the given schema
.
Converts %JsonXema{}
to %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 Elixir.JsonXema.ValidationError
.
Link to this section Types
t()
View Source
t() :: %JsonXema{refs: map(), schema: Xema.Schema.t()}
t() :: %JsonXema{refs: map(), schema: Xema.Schema.t()}
This struct contains the schema and references of the schema.
Link to this section Functions
new(data, opts \\ []) View Source
This function creates a new JsonXema
from the given schema
.
Possible options:
:loader
- a loader for remote schemas. This option will overwrite the loader from the config. See Configure a loader to how to define a loader.
Examples
iex> ~s({"type": "string"})
...> |> Jason.decode!()
...> |> JsonXema.new()
%JsonXema{refs: %{}, schema: %Xema.Schema{type: :string}}
to_xema(json_xema) View Source
Converts %JsonXema{}
to %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 Elixir.JsonXema.ValidationError
.