Fork me on GitHub
#malli
<
2022-04-24
>
minosniu03:04:32

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

1
minosniu03:04:00

(def PetMalli
    [:schema {:registry {"Pet" [:map
                                [:type keyword?]
                                [:name string?]]
                         "Cat" [:merge
                                "Pet"
                                [:map
                                 [:type [:= "Cat"]]
                                 [:huntingSkill [:enum {:description "The measured skill for hunting"}
                                                 :clueless, :lazy, :adventurous, :aggressive]]]]
                         "Dog" [:merge
                                "Pet"
                                [:map
                                 [: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})

minosniu03:04:54

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

minosniu03:04:22

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

minosniu04:04:21

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