metosin / malli

High-performance data-driven data specification library for Clojure/Script.
Eclipse Public License 2.0
1.5k stars 211 forks source link

Check that one schema compatible with another schema #811

Open khmelevskii opened 1 year ago

khmelevskii commented 1 year ago

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.

ikitommi commented 1 year ago

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 commented 1 year ago

PR most welcome on mu/intersection or such.