Skip to content
A data serialization/contract library for common lisp
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
t Class-based schemas (#5) Jul 6, 2019
.gitignore Very WIP, but hey, here goes Aug 19, 2018
.travis.yml Turn on new rove coverage support (#6) Apr 13, 2019
README.rst Class-based schemas (#5) Jul 6, 2019
sanity-clause.asd Class-based schemas (#5) Jul 6, 2019


Travis CI status badge Coveralls status badge


There's no such thing as Sanity Clause -- Groucho Marx

Sanity clause is a data validation/contract library. You might use it for configuration data, validating an api response, or documents from a datastore. In a dynamically typed langauge, it helps you define clearly defined areas of doubt and uncertainty. We should love our users, but we should never blindly trust their inputs.

To make use of it, you define schemas, which can be property lists with symbols for keys and instances of :class:`sanity-clause.field:field` subclasses that dictate the type of values you expect as well as the shape of the property list to be returned after deserializing and validating data. For example:

(list :name (make-field :string) :age (make-field :integer))

You can load these sorts of schemas from a file by writing them as sexps with keywords, like this:


(:key (:string :validator (:not-empty) :default "potato")
 :key2 (:integer :validator ((:int :min 0)) :default 2))

and then loading them using :function:`sanity-clause.loadable-schema:load` to load them.

Finally, you can also define class-based schemas using :class:`sanity-clause.metaclass:validated-metaclass` like:

(defclass person ()
     ((favorite-dog :type symbol
                    :field-type :member
                    :members (:wedge :walter)
                    :initarg :favorite-dog
                    :required t)
      (age :type (integer 0)
           :initarg :age
           :required t)
      (potato :type string
              :initarg :potato
              :required t))
     (:metaclass sanity-clause.metaclass:validated-metaclass))

which will validate thier initargs when you instantiate them (BUT NOT WHEN YOU SET SLOTS). Hopefully, that will be added eventually, perhaps as an optional feature.

You can’t perform that action at this time.