Hi, i’m not 100% clear on how far down the rabbit hole you can go in terms of defining schemas in terms of other schemas. I’m using a mutable custom registry ‘spec’ishly’ per the docs, and i’m running into some issues, but not sure why. Perhaps some ‘type’ v ‘instance’ thing? For something like the following:
(register! :bigdec (m/simple-schema ...))
(register! :money [:map {:someprop ..}
[::amount :bigdec]
[::currency [:enum :USD :CAN ..]]])
(register! ::annual-income [:money {:propa ..}])
(def x {::amount 1.23M ::currency :USD})
(m/validate :money x)
;=> true
(m/validate ::annual-income x)
;Exception => :malli.core/invalid-schema {:schema [:map {:someprop ..} ....
Question about the schema walker functionality. I am trying to change all the :optional
properties of a nested schema to false
with this:
(mi/walk schema ;; malli.core aliased as `mi`
(mi/schema-walker
#(mu/update-properties % assoc :optional false)))
However, this only works if maps have a single key. If the schema is something like this:
(def schema
[:map
[:teams
[:vector
[:map
[:team
[:map
[:id uuid?]
[:name string?]
[:logoUrl {:optional true}
string?]]]
[:health {:optional true}
[:map
[:injuries {:optional true}
[:map
[:playerInjuries
[:vector
[:map
[:playerName string?]
[:position {:optional true}
string?]
[:status string?]]]]]]]]]])
Only only the values under the :teams
key are updated; the :health
key and all the values under it are unaffected. Am I using the schema walker incorrectly, or is this possibly a bug? This is on version 0.5.1
Edit: After looking at this more, I think it's just that update-properties
doesn't work on keys, so I was using it incorrectly.