malli icon indicating copy to clipboard operation
malli copied to clipboard

malli.util operations do not properly deref namespaced keyword custom types

Open bortexz opened this issue 2 years ago • 1 comments

The following code blows up with invalid schema:

(defonce registry* (atom (m/default-schemas)))

(mr/set-default-registry! (mr/mutable-registry registry*))

(defn sdef
  "Defines a new schema in mutable [[registry*]]."
  ([type schema] (swap! registry* assoc type schema) schema)
  ([type props schema] (swap! registry* assoc type [:schema props schema]) schema))

(sdef ::thing-nested2 int?)
(sdef ::thing-nested (mu/optional-keys [:map ::thing-nested2]))
(sdef ::thing (mu/optional-keys [:map ::thing-nested]))

(mu/update ::thing ::thing-nested (fn [s] (mu/required-keys s [::thing-nested2])))
=>
; :malli.core/invalid-schema {:schema nil}
; Evaluation of file malli.clj failed: class clojure.lang.Compiler$CompilerException

schemas should be properly deref'd so that the above code works properly

bortexz avatar Oct 27 '22 07:10 bortexz

I just ran into this and wanted to add the current workaround

from :https://clojurians.slack.com/archives/CLDK6MFMK/p1666794918780899

(mu/update (get @registry* ::thing) ::thing-nested (fn [s] (mu/required-keys s [::thing-nested2])))

or:

(mu/update-in ::thing [0 ::thing-nested] (fn [s] (mu/required-keys s [::thing-nested2])))

dvingo avatar Nov 20 '22 16:11 dvingo