json_xema v0.5.0 JsonXema View Source

A JSON Schema validator.

Link to this section Summary

Types

t()

This struct contains the schema and references of the schema.

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

Specs

t() :: %JsonXema{refs: map(), schema: Xema.Schema.t()}

This struct contains the schema and references of the schema.

Link to this section Functions

Specs

new(boolean() | map(), keyword()) :: t()

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](loader.html) to how to define a
              loader.

Examples

iex> ~s({"type": "string"})
...> |> Jason.decode!()
...> |> JsonXema.new()
%JsonXema{refs: %{}, schema: %Xema.Schema{type: :string}}

Specs

to_xema(%JsonXema{refs: term(), schema: term()}) :: %Xema{
  refs: term(),
  schema: term()
}

Converts %JsonXema{} to %Xema{}.

Specs

valid?(t() | Xema.Schema.t(), any()) :: boolean()

Returns true if the value is a valid value against the given schema; otherwise returns false.

Specs

validate(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.

Specs

validate!(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.