Open xxdavid opened 1 year ago
Hi @xxdavid!
I agree that would be nice indeed.
We're not really using this library (nor Elixir) anymore so it's unlikely that I'll have time to fix it, but PRs and contributions are very welcome! 🙏
Hi @frekw, thanks for replying even though you aren't interested in this library anymore (unfortunately, such behaviour is not very common).
If I find some time, I might come up with a PR. 🙂
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: