View Source JsonXema (json_xema v0.6.1)

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 raises a Elixir.JsonXema.ValidationError. See validate3 for available options.

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

Link to this section Types

@type result() :: Xema.Validator.result()

The return type of a validation run.

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

This struct contains the schema and references of the schema.

Link to this section Functions

@spec 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

Examples

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

Converts %JsonXema{} to %Xema{}.

@spec 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!(xema, value, opts \\ [])

View Source
@spec 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.

Link to this function

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

View Source
@spec 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.