View Source MapSchemaValidator (map_schema_validator v0.1.8)

It's a map format verifier, verify if keys/values exist in a given map, short and quick, you can specify more than one format and verify list of values.

Just use the function MapSchemaValidator.validate/2 or MapSchemaValidator.validate!/2

Summary

Functions

By param schema validates the param data and compares the format and values to ensure follows a specific format.

Same as MapSchemaValidator.validate/2 but raises in fail.

Functions

@spec validate(map(), map()) :: {:ok | :error, any()}

By param schema validates the param data and compares the format and values to ensure follows a specific format.

Examples

iex> MapSchemaValidator.validate(%{key: :string}, %{key: "value"})
{:ok, nil}

iex> MapSchemaValidator.validate(%{key: [:string, :number]}, %{key: 1})
{:ok, nil}

iex> MapSchemaValidator.validate(%{key: [%{inner_key: :string}]}, %{key: [%{inner_key: "value_1"}, %{inner_key: "value_2"}]})
{:ok, nil}

iex> MapSchemaValidator.validate(%{key: [%{inner_key: :string}]}, %{key: [%{inner_key: 1}, %{inner_key: "value_2"}]})
{:error, %MapSchemaValidator.InvalidMapError{message: "error at: key -> inner_key"}}
@spec validate!(map(), map()) :: :ok

Same as MapSchemaValidator.validate/2 but raises in fail.

Examples

iex> MapSchemaValidator.validate!(%{key: :string}, %{key: "value"})
:ok

iex> MapSchemaValidator.validate!(%{key: [:string, :number]}, %{key: 1})
:ok

iex> MapSchemaValidator.validate!(%{key: [%{inner_key: :string}]}, %{key: [%{inner_key: "value_1"}, %{inner_key: "value_2"}]})
:ok

iex> MapSchemaValidator.validate!(%{key: [%{inner_key: :string}]}, %{key: [%{inner_key: 1}, %{inner_key: "value_2"}]})
** (MapSchemaValidator.InvalidMapError) error at: key -> inner_key
Link to this function

validate_json!(schema, json, steps \\ [])

View Source