-
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
Schema Parsing #241
Comments
I would also like to see something like |
ported the (def Schema1 [:string {:encode/conform #(mapv str (seq %))}])
(def Schema2 [:sequential {:encode/conform #(apply str %)} [:enum "0" "1"]])
(def conformer (mt/transformer {:name :conform}))
(as-> "1011" $
(do (println $ "=>" (m/validate Schema1 $)) $)
(m/encode Schema1 $ conformer)
(do (println (pr-str $) "=>" (m/validate Schema2 $)) $)
(m/encode Schema2 $ conformer)
(= "1011" $))
; 1011 => true
; ["1" "0" "1" "1"] => true
; => true |
#312 has most of the required logic, but only for regex schemas so I haven't added any public API. Destructuring other schemas should be much more straightforward though. |
Working on this in #317. Although maybe this should have a separate PR but I'll see how it goes. |
And I put zero thought into the design, just trying to get something workable to demonstrate that #317 can also support this. So it is just the obvious cross between |
explain & parse can be merged later. This is in master. Thanks!! |
Currently,
m/explain
parses the values in align to the Schemas, producing:in
and:path
paths pointing paths in both values and schemas. This is a good base for generic parsing, e.g. Clojure Spec conform. We could reuse them/-explain
to collect paths for valid & invalid errors. The resulting ~conformed data structure could be self-describing, so that nom/-unexplain
would be needed to turn the parsed data structure back into value, like spec hass/unform
. This could be achieved using special types/records to mark branching, instead of just maps and vectors (which can't be found from values without per-schema method).From spec:
Would be ~:
And with named branches:
As a bonus, we could present errors in the parse tree in-place.
See also #180.
The text was updated successfully, but these errors were encountered: