malli icon indicating copy to clipboard operation
malli copied to clipboard

Custom registries inside malli.util derivations fails (e.g. mu/optional-keys)

Open bortexz opened this issue 2 years ago • 0 comments

When using operations like mu/optional-keys, and a custom registry merging m/default-schemas and mu/schemas, it doesn't work properly.

(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}

Extracting the registry outside and using it as options to m/schema seems to fix the issue.

(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]))
=> ok!

bortexz avatar Aug 10 '22 08:08 bortexz