json_xema v0.6.0 JsonXema View Source

A JSON Schema validator.

Link to this section Summary

Types

The return type of a validation run.

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. See validate3 for available options.

Link to this section Types

Specs

result() :: Xema.Validator.result()

The return type of a validation run.

Specs

schema() :: Xema.Schema.t()

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() | schema(), any()) :: boolean()

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

Link to this function

validate(schema, value, opts \\ [])

View Source

Specs

validate(t() | schema(), any(), keyword()) :: result()

Returns :ok if the value is a valid value against the given schema; otherwise returns an error tuple.

With the option :fail, you can define when the validation is aborted. This also influences how many error reasons are returned.

  • :immediately aborts the validation when the first validation fails.
  • :early (default) aborts on failed validations, but runs validations for all properties and items.
  • :finally aborts after all possible validations.
Link to this function

validate!(xema, value, opts \\ [])

View Source

Specs

validate!(t() | schema(), any(), keyword()) :: :ok

Returns :ok if the value is a valid value against the given schema; otherwise raises a Elixir.JsonXema.ValidationError. See validate3 for available options.