Skip to content
plain data schemas
Branch: master
Clone or download
Latest commit 4c1bb2c Jul 14, 2019

malli Build Status

Plain data Schemas for Clojure/Script.

STATUS: Pre-alpha, in design and prototyping phase.

  • Schemas as data
  • Schema-driven Runtime Validation
  • Schema-driven Transformations
  • Tools for programming with Schemas
  • No global state, explicit everything
  • First class error messages
  • Fast


Definining and validating Schemas:

(require '[malli.core :as m])

(m/validate int? "1")
; => false

(m/validate int? 1)
; => true

(m/validate [:and int? [:> 6]] 7)
; => true

(def valid?
     [:x boolean?]
     [[:opt :y] int?]
     [:z string?]]))

(valid? {:x true, :z "kikka"})
; => true

Schemas can have properties:

(def Age
   {:title "Age"
    :description "It's an age"
    :json-schema/example 20}
   int? [:> 18]])
(m/properties Age)
; => {:title "Age"
;     :description "It's an age"
;     :json-schema/example 20}   

Serializing & Deserializing schemas:

(require '[clojure.edn :as edn])

(-> [:map
     [:x boolean?]
     [[:opt :y] int?]
     [:z string?]]
      {:x true, :z "kikka"}))
; => true


(require '[clojure.spec.alpha :as s])
(require '[criterium.core :as cc])

;; 40ns
(let [spec (s/and int? (s/or :pos-int pos-int? :neg-int neg-int?))
      valid? (partial s/valid? spec)]
  (assert (= [true false true] (map valid? [-1 0 1])))
    (valid? spec 0)))

;; 5ns
(let [valid? (m/validator [:and int? [:or pos-int? neg-int?]])]
  (assert (= [true false true] (map valid? [-1 0 1])))
    (valid? 0)))


Should have:

  • Context dependent pluggable validators
  • Context dependent pluggable coercers
  • Close compatibility to Json Schema 7

Could have:

  • Clojure spec generation
  • Database schema generations


Running tests

We use Kaocha as a test runner. Before running the tests, you need to install NPM dependencies.

npm install
You can’t perform that action at this time.