This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-08-09
Channels
- # announcements (3)
- # babashka (120)
- # beginners (87)
- # calva (7)
- # clj-kondo (35)
- # cljsrn (25)
- # clojure (94)
- # clojure-austin (4)
- # clojure-europe (53)
- # clojure-nl (2)
- # clojure-norway (6)
- # clojurescript (16)
- # conjure (8)
- # cursive (6)
- # data-oriented-programming (2)
- # data-science (19)
- # datahike (1)
- # datalevin (29)
- # datomic (13)
- # fulcro (50)
- # gratitude (1)
- # honeysql (9)
- # jackdaw (2)
- # kaocha (7)
- # leiningen (3)
- # malli (4)
- # off-topic (4)
- # polylith (3)
- # re-frame (5)
- # reagent (1)
- # releases (1)
- # reveal (4)
- # shadow-cljs (17)
- # tools-deps (10)
- # vim (17)
- # vscode (4)
- # xtdb (3)
Hi, recently started playing with Malli, I am trying to understand why this works:
(def Map1
(mu/optional-keys
(m/schema
[:map ::a ::b]
{:registry (merge
(m/default-schemas)
(mu/schemas)
{::a string?
::b [:merge
[:map [::a [:ref ::a]]]
[:map [:y string?]]]})})
[::b]))
but this fails with enum child error:
(def Map2
(mu/optional-keys
[:map {:registry (merge
(m/default-schemas)
(mu/schemas)
{::a string?
::b [:merge
[:map [::a [:ref ::a]]]
[:map [:y string?]]]})}
::a
::b]
[::b]))
=>
; Execution error (ExceptionInfo) at malli.core/-fail! (core.cljc:138).
; :malli.core/child-error {:type :enum, :properties nil, :children nil, :min 1, :max nil}
Is it a bug? Am I missing something?
Edit: Another question that is slightly related (involves registries too) malli.util derivative transforms like mu/optional-keys obfuscate the refs when used inside registry:
(def Map1
[:map {:registry {::b string?
::a (mu/optional-keys
[:map [::b [:ref ::b]]])}}
::a])
=>
; Execution error (ExceptionInfo) at malli.core/-fail! (core.cljc:138).
; :malli.core/invalid-ref {:type :ref, :ref :malli-domain-lab/b}
Is there any workaround for this?Robust way to define a schema space for an application is to use the global scope, e.g.:
(mr/set-default-registry!
;; linear search
(mr/composite-registry
;; default schemas
(m/default-schemas)
;; utils
(mu/schemas)))
(mu/optional-keys
[:map {:registry {::a string?
::b [:merge
[:map [::a [:ref ::a]]]
[:map [:y string?]]]}}
::a
::b]
[::b])
Done! https://github.com/metosin/malli/issues/736 Thank you, I’ll rearrange how the registries are defined to make it work