malli
malli copied to clipboard
Make it possible to add properties to an existing custom schema
See the below code example for usage.
(def registry
(atom {}))
(defn register! [type ?schema]
(swap! registry assoc type ?schema))
;; Combine the default registry with our own mutable registry.
(mreg/set-default-registry!
(mreg/composite-registry
(mreg/fast-registry (malli/default-schemas))
(mreg/mutable-registry registry)))
(register! :non-empty-string [:string {:min 1}])
(malli/validate :non-empty-string "Bengt")
;; => true
(malli/validate [:map [:namn :non-empty-string]] {:namn "Bengt"})
;; => true
(malli/validate [:map [:namn [:non-empty-string {:max 2}]]] {:namn "Bengt"})
;; Throws:
;; Execution error (IllegalArgumentException) at malli.core/eval15223$fn$G (core.cljc:22).
;; No implementation of method: :-into-schema of protocol: #'malli.core/IntoSchema found for class: clojure\
.lang.PersistentVector
;; While this works:
(malli/validate [:map [:namn [:string {:max 2}]]] {:namn "Bengt"})