Xema.Builder.any_of

You're seeing just the function any_of, go back to Xema.Builder module for more information.
Link to this function

any_of(type \\ :any, schemas)

View Source

Specs

any_of(type, [schema]) :: {type, [{:any_of, [schema]}]}
when type: Xema.Schema.type(),
     schema: Xema.Schema.t() | Xema.Schema.type() | tuple() | atom() | keyword()

Returns a tuple with the given type (default :any) and the given schemas tagged by the keyword :any_of. This function provides a shortcut for something like integer(any_of: [...]) or any(any_of: [...]).

Examples

iex> Xema.Builder.any_of([:integer, :string])
{:any, any_of: [:integer, :string] }

iex> Xema.Builder.any_of(:integer, [[minimum: 10], [maximum: 5]])
{:integer, any_of: [[minimum: 10], [maximum: 5]]}
defmodule MySchema do
  use Xema

  xema do
    any_of [
      list(items: integer(minimum: 1, maximum: 66)),
      list(items: integer(minimum: 33, maximum: 100))
    ]
  end
end

MySchema.valid?([20, 30]) #=> true
MySchema.valid?([40, 50]) #=> true
MySchema.valid?([60, 70]) #=> true
MySchema.valid?([10, 90]) #=> false