malli icon indicating copy to clipboard operation
malli copied to clipboard

Check that one schema compatible with another schema

Open khmelevskii opened this issue 2 years ago • 3 comments

For example, there are 2 schemas:

(def person [:map
             [:first-name :string]
             [:last-name {:optional true} :string]
             [:age :int]])

(def person-full-name [:map
                       [:first-name :string]
                       [:last-name {:optional true} :string]])

So, I'm trying to check that person-full-name is fully compatible with person schema and any value which conform person schema will be conform person-full-name schema too.

khmelevskii avatar Jan 05 '23 05:01 khmelevskii

there is no built-in utility at the moment for it, but should be easy to build one, on top of the malli.util, see https://github.com/metosin/malli/issues/82.

for best effort checking, you could also:

(every? (m/validator person-full-name) (mg/sample person {:size 1000}))
; => true

ikitommi avatar Jan 05 '23 08:01 ikitommi

PR most welcome on mu/intersection or such.

ikitommi avatar Jan 10 '23 12:01 ikitommi