Fork me on GitHub

Hi, I'm getting a strange error when running the example of "Pet" in Clojure (not Clojurescript). Code here:


(def PetMalli
    [:schema {:registry {"Pet" [:map
                                [:type keyword?]
                                [:name string?]]
                         "Cat" [:merge
                                 [:type [:= "Cat"]]
                                 [:huntingSkill [:enum {:description "The measured skill for hunting"}
                                                 :clueless, :lazy, :adventurous, :aggressive]]]]
                         "Dog" [:merge
                                 [:type [:= "Dog"]]
                                 [:packSize [:int {:min 0,
                                                   :default 0
                                                   :description "the size of the pack the dog is from"}]]]]}}
     [:multi {:dispatch :type} "Cat" "Dog"]])

(m/validate PetMalli {:type "Cat", :name "Viivi", :huntingSkill :adventurous})


Message: Execution error (ExceptionInfo) at malli.core/-fail! (core.cljc:136). :malli.core/invalid-schema {:schema :merge}


Could anyone give me some pointers? We want to use :merge for some inheritance-like constraints in our schema, which is very similar to the "Pet" example.

Ben Sless03:04:43

Merge is in another registry. You need to merge it into the registry you're creating. It's in malli util, I think


My guess, too. But the code might get somewhat cumbersome. It's strange that the same code from the Pet example simply won't work, notice that in the example only local registry was used.

Ben Sless04:04:15

Yeah that's something I'm still iffy about. Will wait for Tommi to chime in