In version 0.2.0, I added cast_func option which allow to define custom casting function for custom type.
In the previous version, tarams only supports built-in types and uses Ecto.Changeset.cast function to cast params value.
def my_array_parser(value) do
if is_binary(value) do
ids =
String.split(value, ",")
|> Enum.map(&String.to_integer(&1))
{:ok, ids}
else
{:error, "Invalid string"}
end
end
schema = %{
user_id: [type: {:array, :integer}, cast_func: &my_array_parser/1]
}
Tarams.parse(schema, %{user_id: "1,2,3"})
I try to support nested schema but using Ecto, it’s hard to support nested schema without some hack.
So I decide to rewrite Tarams and remove dependency on Ecto.
Now you can work with nested params easily like this: