Casts input values to the DSL's built-in types.
It is used internally by the parser. Use ExParamsSchema.parse/2 unless you need direct
access to individual type casts.
Summary
Functions
Casts input values to DSL built-in types.
Types
@type cast_result() :: {:ok, value :: ExParamsSchema.value()} | {:error, reason :: ExParamsSchema.error_reason()}
Functions
@spec cast( ExParamsSchema.value(), ExParamsSchema.field_type(), ExParamsSchema.error_reason() ) :: cast_result()
Casts input values to DSL built-in types.
iex> ExParamsSchema.Caster.cast("12", :integer, :invalid_count)
{:ok, 12}
iex> ExParamsSchema.Caster.cast("12px", :integer, :invalid_count)
{:error, :invalid_count}
iex> ExParamsSchema.Caster.cast("1e3", :number, :invalid_number)
{:ok, 1000.0}
iex> ExParamsSchema.Caster.cast("on", :boolean, :invalid_enabled)
{:ok, true}
iex> ExParamsSchema.Caster.cast(" Front ", :string, :invalid_label)
{:ok, "Front"}
iex> ExParamsSchema.Caster.cast("2026-07-23", :date, :invalid_date)
{:ok, ~D[2026-07-23]}
iex> ExParamsSchema.Caster.cast("merge", {:enum, [:merge, :replace]}, :invalid_mode)
{:ok, :merge}Values that cannot be cast return the reason supplied by the caller as an error.