-
Notifications
You must be signed in to change notification settings - Fork 215
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
Consider Merging Predicate and Type Schemas #327
Comments
Thinking aloud, either:
The predicate-schemas are currently listed using (defn default-schemas []
(merge (class-schemas) (comparator-schemas) (type-schemas) (base-schemas))) It would be easy to implement all the core predicates as new/existing |
I personally lean toward using a shared implementation with a potentially different Number 2. above sounds like a useful enhancement but potentially tangential to this issue. |
Upon further thought, while the solution proposed in number 1 solves the issue for malli, it still makes transformer authors have to register the duplicate keys (eg. |
Maybe transformers (and JSON schemas etc.) should be mapped to the schema class (or even instance?) instead of the name? Compilers (and Datomic) get rid of names as soon as possible to eliminate aliasing (like here) and scoping (like #326) concerns. |
Good points. That said, type definitions should be portable between clj & cljs, right? (related: #264). There was an online discussion about having a custom map Schema in user space, that would work like a map with JSON Schema, Swagger and Value generation => "just add a I think the core predicates could be rewritten using a new proxy-schema (just new options into {'pos-int? (m/-simple-schema {:form 'pos-int?, :schema [:int {:min 1}]})
pos-int? (m/-simple-schema {:form 'pos-int?, :schema [:int {:min 1}]})} as validators, explainers etc. use the factual predicate, there would not be any performance penalty from this extra abstraction. And EDIT: ... and the transformers could be written against just the |
An approach using |
Right now type schemas and predicate schemas are entirely different schemas and don't behave the same. This can create some surprising behaviors:
Writing a transformer for one doesn't target the other. eg. Writing a transformer for
:string
won't apply tostring?
. This means that transformer authors either need to provide duplicate entries for the encoders and decoders, or that application authors need to be consistent in which schema annotation they use.Similarly, writing a schema walker requires knowing and handling each variant.
Malli as a library suffers from the same potential for inconsistency, as seen between the property-based validation available on
:string
and:int
, but not held for predicate schemas.A potential solution to this is having the predicate-schemas just be aliases to the type schemas in the default registry, eg:
The downsides I see with this are:
Schemas potentially lose their homoiconicity. Taking the value of a schema written as
string?
and seralizing it would yield:string
. Still, this is a problem of any schema that makes use of the registry, so I'm not sure it's that big of an issue.Some predicate-schema based types don't have analogs in typed schemas. Eg.
double?
. I'd be eager to hear ideas on how best to resolve this.The text was updated successfully, but these errors were encountered: