Liking cljdoc? Tell your friends :D

clj-schema.fixtures

Ways to create fixture test data that must match a given schema

Ways to create fixture test data that must match a given schema
raw docstring

clj-schema.schema

Define validation schemas for validating maps.

Schemas are any number of paths through a nested map, paired with a validator.

Validators are either a single predicate or schema, or a seq of predicates or schems (or a mix of predicates or schemas).

A path may also be marked as an optional-path. By default a value at a given path is assumed to be a single value; to mark it sequential, wrap the validator in the 'sequence-of' function. NOTE: 'nil' is a passing value for a 'sequence-of' validator.

Example Schema:

[[:a :b :c] pred [:x :y :z] [pred2 pred3 z-schema] ;; implicit 'and' - all three must pass [:p :q :r] [:or nil? r-schema] ;; an 'or' statement - need just one to pass (optional-path [:z]) (sequence-of string?) [:a b :d] (loose-valdiation-schema [[:cat :name] String ;; can use Java Class objects directly [:cat :color] String]) ... ]

defschema creates a strict schema, which expects only the paths it describes to be present on the given map.

def-loose-schema creates a loose schema, which expects its paths to be present but does not complain about extra paths.

Define validation schemas for validating maps.

Schemas are any number of paths through a nested map, paired with a validator.

Validators are either a single predicate or schema, or a seq of predicates
or schems (or a mix of predicates or schemas).

A path may also be marked as an `optional-path`. By default a value at a given
path is assumed to be a single value; to mark it sequential, wrap the validator
in the 'sequence-of' function. NOTE: 'nil' is a passing value for a 'sequence-of' validator.

Example Schema:

[[:a :b :c] pred
 [:x :y :z] [pred2 pred3 z-schema] ;; implicit 'and' - all three must pass
 [:p :q :r] [:or nil? r-schema]    ;; an 'or' statement - need just one to pass
 (optional-path [:z]) (sequence-of string?)
 [:a b :d] (loose-valdiation-schema [[:cat :name] String ;; can use Java Class objects directly
                                     [:cat :color] String])
... ]

`defschema` creates a strict schema, which expects only the paths it
describes to be present on the given map.

`def-loose-schema` creates a loose schema, which expects its paths to
be present but does not complain about extra paths.
raw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close