litmus v0.5.0 Litmus.Type.List View Source
This type validates that a value is list.
Options
:min_length
- Specifies the minimum list length. Allowed values are non-negative integers.:max_length
- Specifies the maximum list length. Allowed values are non-negative integers.:length
- Specifies the exact list length. Allowed values are non-negative integers.:required
- Setting:required
totrue
will cause a validation error when a field is not present or the value isnil
. Allowed values for required aretrue
andfalse
. The default isfalse
.:type
- Specifies the data type of elements in the list. Allowed values are are atoms:atom, :boolean, :number and :string
. Default value isnil
. Ifnil
, any element type is allowed in the list.
Examples
iex> schema = %{
...> "ids" => %Litmus.Type.List{
...> min_length: 1,
...> max_length: 5,
...> type: :number
...> }
...> }
iex> Litmus.validate(%{"ids" => [1, 2]}, schema)
{:ok, %{"ids" => [1, 2]}}
iex> Litmus.validate(%{"ids" => [1, "a"]}, schema)
{:error, "ids must be a list of numbers"}
Link to this section Summary
Link to this section Types
Link to this type
t()
View Source
t() :: %Litmus.Type.List{ length: non_neg_integer() | nil, max_length: non_neg_integer() | nil, min_length: non_neg_integer() | nil, required: boolean(), type: String.t() | atom() | nil }