zoedsoupe / peri

Elixir library for declarative data description and validation
MIT License
84 stars 2 forks source link

[BUG] Transforms don't run on nested schemas #12

Open nickdichev-firework opened 4 days ago

nickdichev-firework commented 4 days ago

Describe the bug Transforms do not run on fields if their type is a schema but they do run if the type is :map.

To Reproduce

fun = fn _value -> raise("boom") end

nested_schema = %{
  foo: :string
}

parent_schema = %{
  bar: {nested_schema, {:transform, fun}}
}

map_schema = %{
  bar: {:map, {:transform, fun}}
}

Peri.validate(parent_schema, %{bar: %{foo: "hello"}})
{:ok, %{bar: %{foo: "hello"}}}

Peri.validate(map_schema, %{bar: %{foo: "hello"}})
** (RuntimeError) boom

Expected behavior Transform runs on the validated schema field

Environment • Elixir version: 1.16.3 • Peri version: 0.2.11