This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-05-17
Channels
- # announcements (1)
- # beginners (44)
- # calva (20)
- # cljs-dev (22)
- # cljsrn (5)
- # clojars (24)
- # clojure (33)
- # clojure-europe (36)
- # clojure-filipino (1)
- # clojure-indonesia (1)
- # clojure-my (1)
- # clojure-nl (2)
- # clojure-sg (2)
- # clojure-uk (8)
- # clojurescript (73)
- # code-reviews (21)
- # conjure (13)
- # cursive (46)
- # datahike (16)
- # datomic (5)
- # depstar (1)
- # graalvm (7)
- # honeysql (22)
- # jobs (2)
- # jobs-discuss (2)
- # kaocha (3)
- # luminus (2)
- # malli (2)
- # nrepl (17)
- # off-topic (46)
- # pathom (14)
- # re-frame (7)
- # remote-jobs (1)
- # sci (8)
- # shadow-cljs (33)
- # sql (14)
- # vim (48)
- # xtdb (1)
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.