-
Notifications
You must be signed in to change notification settings - Fork 216
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
Introduce schemas for map key constraints #1161
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, thanks for working on this and sorry for being out of reach for a month+. I read the code and tested the branch, like the approach and if this is a step forward in simplification etc, let's do this. But the code should be finished first. Some notes:
- some TODOs (like transformers)
- schema walking doesn't work, e.g.
(m/walk
[:if [:has :user] [:has :pass] [:has :secret]]
(m/schema-walker identity))
Also I json-schema
mappings need to be done.
|
||
(deftest xor-test | ||
(is (= [:xor [:= 1] [:= 2]] | ||
(m/form (m/schema [:xor [:= 1] [:= 2]] {:registry (merge (mu/schemas) (m/default-schemas))})))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR adds new schemas to default registry, here expectation is that they are in malli.util
.
This PR adds some schemas to help constrain the keysets of
:map
schemas. Instead of[:and [:map ..] [:fn <OPAQUE>]]
, you now write[:and [:map ...] [:xor ..] [:iff ..] ...]
.The next step is to improve the generators for these schemas. The basic strategy to generate
[:and S T]
will be to generateS
but propagateT
as a hint to theS
generator. Most of the work will be to canonicalizeT
by expanding into disjunctive normal form.Humanization comes with the usual caveats of not being able to represent the difference between a conjunction or disjunction of errors, so some of the humanizers are a little strange. I'm not sure if this can be fixed without a breaking change to the humanization representation.
There are more general abstractions here (like the idea of simplifying a schema) but we can build towards that later. I have sketches of using such abstractions to compile optimal validators and generators. For now, concentrating on map keyset constraints is helping move this work along.
Note: the
:max-tries
change is to fix an unrelated flaky test: