You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Notice that the call was successful and :name is set to nil even though it is in @enforced_keys and its type is not nullable.
Instead, if you evaluate %Person{age: 42, happy?: true, phone: "(206) 342-8631"}, you get this error: (ArgumentError) the following keys must also be given when building struct Person: [:name].
I think Forma should enforce :name being present in data as well. What do you think?
I think it could be achieved by changing the struct clause for Forma.Parser.parse!/3 from this:
defparse!(input,parsers,{:struct,name,fields})docaseinputdoinputwhenis_map(input)->map_exact_fields!(input,parsers,struct(name),fields)_->raise"not a map #{inspect(input)}"endend
to something like this:
defparse!(input,parsers,{:struct,name,fields})docaseinputdoinputwhenis_map(input)->map_exact_fields!(input,parsers,%{},fields)|>then(&struct!(name,&1))_->raise"not a map #{inspect(input)}"endend
The text was updated successfully, but these errors were encountered:
Hi, thanks for this library. 🙂
It works well but it does not enforce fields that are declared in the struct to be enforced.
Imagine this struct:
Now if you evaluate
you get
Notice that the call was successful and
:name
is set tonil
even though it is in@enforced_keys
and its type is not nullable.Instead, if you evaluate
%Person{age: 42, happy?: true, phone: "(206) 342-8631"}
, you get this error:(ArgumentError) the following keys must also be given when building struct Person: [:name]
.I think Forma should enforce
:name
being present indata
as well. What do you think?I think it could be achieved by changing the struct clause for
Forma.Parser.parse!/3
from this:to something like this:
The text was updated successfully, but these errors were encountered: