Converts JSON Schema validation results into ExParamsSchema error formats.
This internal module integrates with ExJsonSchema. Use parse/2 or parse_detailed/2 in
normal use.
Summary
Functions
Validates JSON-compatible data and normalizes the result to the first declared error reason.
Validates JSON-compatible data and returns all errors with their paths.
Functions
@spec validate(ExParamsSchema.Schema.t(), map()) :: :ok | {:error, ExParamsSchema.error_reason()}
Validates JSON-compatible data and normalizes the result to the first declared error reason.
iex> schema = ExParamsSchema.compile!(%{count: {:integer, minimum: 1, error: :invalid_count}})
iex> ExParamsSchema.Schema.Validator.validate(schema, %{"count" => 2})
:ok
iex> ExParamsSchema.Schema.Validator.validate(schema, %{"count" => 0})
{:error, :invalid_count}
@spec validate_detailed(ExParamsSchema.Schema.t(), map()) :: :ok | {:error, [ExParamsSchema.ValidationError.t()]}
Validates JSON-compatible data and returns all errors with their paths.
iex> schema = ExParamsSchema.compile!(%{count: {:integer, minimum: 1, error: :invalid_count}})
iex> {:error, [error]} = ExParamsSchema.Schema.Validator.validate_detailed(schema, %{"count" => 0})
iex> {error.path, error.keyword, error.reason}
{["count"], :minimum, :invalid_count}