Liking cljdoc? Tell your friends :D

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

covered-by-wildcard-path?clj

(covered-by-wildcard-path? [path-first & path-rest :as path-to-check]
                           [wildcard-first & wildcard-rest :as wildcard-path])
source

def-loose-schemacljmacro

(def-loose-schema name & schema-vectors)

Creates a named var for a loose schema that can be used within other schemas.

Creates a named var for a loose schema that can be used within other schemas.
sourceraw docstring

defschemacljmacro

(defschema name & schema-vectors)

Creates a named var for a strict schema that can be used within other schemas.

Creates a named var for a strict schema that can be used within other schemas.
sourceraw docstring

errors-for-path-contentcljmultimethod

source

filter-schemaclj

(filter-schema pred schema)

Takes a pred like (fn [[path validator]] ...) and selects all schema rows that match.

Takes a pred like (fn [[path validator]] ...) and selects all schema rows that match.
sourceraw docstring

loose-schemaclj

(loose-schema & vs)

From a seq of vectors, creates a schema that can be used within other schemas. Checks for the presence of all paths; other paths may also exist.

From a seq of vectors, creates a schema that can be used within other schemas.
Checks for the presence of all paths; other paths may also exist.
sourceraw docstring

loose-schema?clj

(loose-schema? x)
source

matches-any-wildcard-path?clj

(matches-any-wildcard-path? all-wild-card-paths path)
source

ns->schemasclj

(ns->schemas the-ns)

All schemas in a namespace

All schemas in a namespace
sourceraw docstring

num-schema-pathsclj

(num-schema-paths schema)
source

optional-pathclj

(optional-path schema-path)

Takes a schema path and morphs it into a path that is optional. Optional paths may or may not be present on the validated map, but if they are present they must be valid against the given validator.

Takes a schema path and morphs it into a path that is optional.
Optional paths may or may not be present on the validated map, but
if they are present they must be valid against the given validator.
sourceraw docstring

optional-path?clj

(optional-path? schema-path)
source

remove-subpathsclj

(remove-subpaths paths)
source

schema-rowsclj

(schema-rows schema)
source

schema?clj

(schema? x)
source

select-schema-keysclj

(select-schema-keys schema & ks)

Returns a new schema with only the paths starting with the specified keys.

Returns a new schema with only the paths starting with the specified keys.
sourceraw docstring

sequence-ofclj

(sequence-of single-item-validator)
source

sequence-of?clj

(sequence-of? validator)
source

strict-schemaclj

(strict-schema & vs)

From a seq of vectors, creates a schema that can be used within other schemas. Any paths found in addition to the ones specified are considered a violation.

From a seq of vectors, creates a schema that can be used within other schemas.
Any paths found in addition to the ones specified are considered a violation.
sourceraw docstring

strict-schema?clj

(strict-schema? x)
source

subtract-pathsclj

(subtract-paths schema & paths)

Returns a new schema minus some paths.

Returns a new schema minus some paths.
sourceraw docstring

subtract-wildcard-pathsclj

(subtract-wildcard-paths schema)

Returns a schema that is the same in all respects, except it has none of the wildcard paths.

Returns a schema that is the same in all respects, except it has none of the wildcard paths.
sourceraw docstring

valid?clj

(valid? schema m)
source

validation-errorsclj

(validation-errors schema m)
(validation-errors parent-path schema m)

Returns a set of all the validation errors found when comparing a given map m, against the supplied schema.

A validator is either a schema, predicate, Class or vector of them. See this ns's :doc meta for more details.

Returns a set of all the validation errors found when comparing a given
map m, against the supplied schema.

A validator is either a schema, predicate, Class or vector of them.
See this ns's :doc meta for more details.
sourceraw docstring

wildclj

(wild validator)

Upgrades a validator to be used within a path as a wildcard. Ex. [:a (wild Integer) (wild String)], matches all paths like [:a 1 "product-1"] or [:a 42 "product-2"]

Upgrades a validator to be used within a path as a wildcard.
Ex. [:a (wild Integer) (wild String)], matches all paths like [:a 1 "product-1"] or [:a 42 "product-2"]
sourceraw docstring

wildcard-path->concrete-pathsclj

(wildcard-path->concrete-paths m [path-first & path-rest :as the-wildcard-path])
source

wildcard-path?clj

(wildcard-path? schema-path)
source

wildcard-validator?clj

(wildcard-validator? validator)
source

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

× close