-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Composing schemas #37
Comments
There are a couple of ways around this in Norm's current form. The most straightforward is to compose the maps before passing them to quick_checks = %{
id: spec(is_integer()),
name: spec(is_string())
}
expensive_checks = %{
id: spec(some_complex_calculation()),
age: spec(another_complex_calculation())
}
checks = schema(Map.merge(quick_checks, expensive_checks)) This obviously only works for schemas and is still pretty limited. We're working on a more general way to compose arbitrary specs. This might be something like an |
Thanks Chris, I hadn't thought of Map.merge - that's helpful. If you do go down this road, I think Thanks again! |
Speaking of
|
Thank you so much for this library!
I'm not sure if I just missed this, or if it's a bad idea, or if there's a better way to achieve it - but does Norm include an "and" for specs/schemas, corresponding to the "or" provided by
one_of
?For example, say I have two schemas like:
Perhaps most of the time I only want to do the
quick_checks
, but on some occasions I want to do ALL the checks. Is there (/should there be) a way to compose the two schemas so that I end up with something like the following?I guess if you're using
conform!/2
it doesn't really matter, because you can just doand you'll get an exception if something goes wrong.
But with
conform/2
it's a bit trickier if you want to catch all the validation errors in one output. I wrote a helper function calledconform_all
, but it doesn't seem like a very elegant approach.Apologies if I'm missed something obvious, and thanks so much again for Norm!
The text was updated successfully, but these errors were encountered: