malli

2025-08-08T16:19:06.825659Z

hey y'all, is there a built-in schema that checks whether a value is a malli schema? I want to be able to write something like

[:map
 [:out-schema malli.core/schema?]]

respatialized 2025-08-08T18:22:26.214879Z

This question periodically comes up (I call it a "self-describing meta-schema") here - as far as I know, the answer is still officially "no." There's no malli schema that checks whether a given vector or keyword describes a valid malli schema - but what I have done in the past when I need to have a predicate for this is just wrap malli.core/schema and catch the error for invalid values:

(defn schema? [v]
  (try (do (m/schema v) true)
       (catch Exception e false)))

👍 2
escherize 2025-08-08T19:50:39.108219Z

There's a good technically right non answer tho:

(mapv (juxt #(mc/validate [:fn (fn [mschema] (try (mc/schema mschema) true
                                                  (catch Exception _ false)))] %)
            identity)
      [:int
       3
       [:map [:a :int] [:b :string]]
       [:map [:a :int] [:b :string] [:c {:optional true} :string]]
       [:sequential :int]
       [:sequential [:map [:a :int] [:b :string]]]])
;; => [[true :int]
;;     [false 3]
;;     [true [:map [:a :int] [:b :string]]]
;;     [true [:map [:a :int] [:b :string] [:c {:optional true} :string]]]
;;     [true [:sequential :int]]
;;     [true [:sequential [:map [:a :int] [:b :string]]]]]