Fork me on GitHub
#malli
<
2022-10-28
>
ikitommi09:10:26

Anyone interested in doing / sharing a Schema for def syntax? like the https://github.com/metosin/malli/blob/master/src/malli/destructure.cljc#L11-L55 here.

ikitommi10:10:55

nevermind, already working on it 🙂

dvingo14:10:47

if you're touching that code, i think there is an edge case for cljs (maybe clj too) if you have a custom registry - the schemas used for parsing the experimental defn form may not be available - https://github.com/metosin/malli/pull/702/files#diff-8fa8701bc52f9f699e5512b8ea028a44c05033b134751af5f789cd57edcf05ad had to add that line to get it working.

sashton15:10:37

Are closed-schema and multi incompatible? I am calling closed-schema on a schema which includes a multi nested in it. It fails to validate correctly, but if I remove the closed-schema , it works as expected. Example:

(def operator-schema 
  (malli/schema
   [:multi {:dispatch :op}
    [:addition [:map
                [:summand-1 :int]
                [:summand-2 :int]]]
    [:multiplication [:map
                      [:factor-1 :int]
                      [:factor-2 :int]]]]))

(def equation-schema
  (mallu/closed-schema
   [:map
    [:left-hand-side operator-schema]
    [:right-hand-side :int]]))

(malle/humanize (malli/explain equation-schema {:left-hand-side {:op :addition
                                                                 :summand-1 1
                                                                 :summand-2 2}
                                                :right-hand-side 3}))

=> {:left-hand-side {:op ["disallowed key"]}}

sashton15:10:24

Never mind, user error: I forgot to include the [:op :keyword] declaration in each of the submaps in operator-schema

👌 1