Defines data structure, coerces, validates.
Defines data structure, coerces, validates.
(->coerce-fn v)Resolves a value, lex name, factory invocation, or inline lex map to a coerce fn.
Resolves a value, lex name, factory invocation, or inline lex map to a coerce fn.
Resolves a value, lex name, factory invocation, or inline lex map to a validate fn. Combinator factories use this to accept inline fns, registered lexes, or resolved lex maps.
Resolves a value, lex name, factory invocation, or inline lex map to a validate fn. Combinator factories use this to accept inline fns, registered lexes, or resolved lex maps.
(-process-entity-level-spec process key spec entity)(-process-error process options)(-process-field-spec process spec value)(-process-spec-on-value process spec value)(coerce schema entity)Returns coerced entity or SchemaError if any coercion failed. Use error? to check result. Use Case: 'I want to change my data into the types specified by the schema.'
Returns coerced entity or SchemaError if any coercion failed. Use error? to check result. Use Case: 'I want to change my data into the types specified by the schema.'
(coerce! schema entity)Returns a coerced entity or throws an exception if there are errors.
Returns a coerced entity or throws an exception if there are errors.
(coerce-message-map schema entity)Runs coerce on the entity and returns a map of error message, or nil if none.
Runs coerce on the entity and returns a map of error message, or nil if none.
(coerce-value! spec value)(coerce-value! schema key value)returns coerced value or throws an exception
returns coerced value or throws an exception
(coerce-with lexicons schema entity)(conform schema entity)Returns coerced entity or SchemaError upon any coercion or validation failure. Use error? to check result. Use Case: 'I want to coerce my data then validate the coerced data, all according to the schema.' Use Case: Data comes in from a web-form so strings have to be coerced into numbers, etc., then we need to validate that the data is good.
Returns coerced entity or SchemaError upon any coercion or validation failure. Use error? to check result.
Use Case: 'I want to coerce my data then validate the coerced data, all according to the schema.'
Use Case: Data comes in from a web-form so strings have to be coerced into numbers, etc., then
we need to validate that the data is good.(conform! schema entity)Returns a conformed entity or throws an exception if there are errors.
Returns a conformed entity or throws an exception if there are errors.
(conform-message-map schema entity)Runs conform on the entity and returns a map of error message, or nil if none.
Runs conform on the entity and returns a map of error message, or nil if none.
(conform-schema! schema)Normalizes, coerces, and validates all the specs in the schema. Any problems in the schema will throw an exception. Any extra fields in the spec (:value, :db, ...) will be preserved.
Normalizes, coerces, and validates all the specs in the schema. Any problems in the schema will throw an exception. Any extra fields in the spec (:value, :db, ...) will be preserved.
(conform-value! spec value)(conform-value! schema key value)coerce and validate, returns coerced value or throws
coerce and validate, returns coerced value or throws
(conform-with lexicons schema entity)(error-data field-error)Return the data map associated with the FieldError.
Return the data map associated with the FieldError.
(error-exception field-error)Return the exception attached to a FieldError if any, otherwise nil.
Return the exception attached to a FieldError if any, otherwise nil.
(error-map result)(error-message error)Return the message of an error.
Return the message of an error.
(error-seq entity)Returns a sequence of all the FieldErrors in a processed entity.
Returns a sequence of all the FieldErrors in a processed entity.
(error-type field-error)Return the target type of a CoerceError, if any, otherwise nil.
Return the target type of a CoerceError, if any, otherwise nil.
(error-value field-error)Return the value that caused the FieldError, if any, otherwise nil.
Return the value that caused the FieldError, if any, otherwise nil.
(error? entity)Return true if the processed entity has errors, false otherwise.
Return true if the processed entity has errors, false otherwise.
(field-error? value)Returns true if the value is a FieldError, false otherwise.
Returns true if the value is a FieldError, false otherwise.
(kind key)(lex slot name)Returns the lex named by name in the given lexicon slot, or nil if
not found. slot is one of :types, :validations, :coercions,
:presentations. name is a keyword/symbol/string, or [name & args]
for a factory invocation. A lex is the unit stored under each slot
key — for :validations and :coercions it's a {:validate ...} or
{:coerce ...} map; for factories, a fn returning such a map.
Returns the lex named by `name` in the given lexicon `slot`, or nil if
not found. `slot` is one of :types, :validations, :coercions,
:presentations. `name` is a keyword/symbol/string, or [name & args]
for a factory invocation. A lex is the unit stored under each slot
key — for :validations and :coercions it's a {:validate ...} or
{:coerce ...} map; for factories, a fn returning such a map.(lex! slot name)Like lex, but throws if name is not found in slot.
Like lex, but throws if `name` is not found in `slot`.
(merge-schemas & schemas)(merge-specs a b)(message-map result)nil when there are no errors, otherwise a map {<field> <error message>}.
nil when there are no errors, otherwise a map {<field> <error message>}.
(message-seq result)seq of 'friendly' error messages; nil if none.
seq of 'friendly' error messages; nil if none.
(normalize-schema schema)Returns the schema with all shorthand specs expanded.
Returns the schema with all shorthand specs expanded.
(normalize-spec spec)If the spec is using a shorthand, it will be expanded.
If the spec is using a shorthand, it will be expanded.
(normalized? schema-or-spec)Returns true if the schema-or-spec has been normalized, false otherwise.
Returns true if the schema-or-spec has been normalized, false otherwise.
Used as a :present value to remove the entry from presentation
Used as a :present value to remove the entry from presentation
(present schema entity)Returns presented entity with FieldErrors where the process failed. Use error? to check result.
Returns presented entity with FieldErrors where the process failed. Use error? to check result.
(present! schema entity)Returns a presented entity or throws an exception if there are errors.
Returns a presented entity or throws an exception if there are errors.
(present-value! spec value)(present-value! schema key value)returns a presentable representation of the value, or throws
returns a presentable representation of the value, or throws
(present-with lexicons schema entity)(process-map-spec-on-value process spec value)(process-one-of-on-value process spec value)(update-lexicon! slot f & args)Updates a slot in the lexicon root binding. slot is :types, :validations, :coercions, or :presentations. Intended for load-time extension by client namespaces; for scoped overrides (e.g. tests, request-local), use with-lexicon.
Updates a slot in the lexicon root binding. slot is :types, :validations, :coercions, or :presentations. Intended for load-time extension by client namespaces; for scoped overrides (e.g. tests, request-local), use with-lexicon.
(valid-types)Returns the set of type names currently in (:types lexicon). Dynamic — picks up types added via update-lexicon! or with-lexicon.
Returns the set of type names currently in (:types *lexicon*). Dynamic — picks up types added via update-lexicon! or with-lexicon.
(valid-value? spec value)(valid-value? schema key value)return true or false
return true or false
(validate schema entity)Returns entity with all values true, or SchemaError when one or more invalid fields. Use error? to check result. Use Case: 'I want to make sure all the data is valid according to the schema.'
Returns entity with all values true, or SchemaError when one or more invalid fields. Use error? to check result. Use Case: 'I want to make sure all the data is valid according to the schema.'
(validate! schema entity)Returns a validated entity or throws an exception if there are errors.
Returns a validated entity or throws an exception if there are errors.
(validate-message-map schema entity)Runs validate on the entity and returns a map of error message, or nil if none.
Runs validate on the entity and returns a map of error message, or nil if none.
(validate-value! spec value)(validate-value! schema key value)throws an exception when validation fails, value otherwise
throws an exception when validation fails, value otherwise
(validate-with lexicons schema entity)(verify-schema-lexes schema)Walks schema; throws on the first :validations, :coercions, or :presentations lex that doesn't resolve or is in the wrong slot. Returns true on success.
Walks schema; throws on the first :validations, :coercions, or :presentations lex that doesn't resolve or is in the wrong slot. Returns true on success.
(walk-schema emit spec)Post-order walk over a spec tree. Normalizes each node, recurses into its children (by :type), and calls (emit spec children) where children is a map of already-walked sub-results shaped for the node's :type:
:one-of -> {:specs [walked...]} :seq -> {:spec walked} :map -> {:schema {k walked ...} :key-spec walked :value-spec walked} leaf -> nil
The :* entity-level-spec key inside :schema is skipped (it is not a field spec). Each sub-result is whatever the emit fn returned for that child, so emit controls the output type (OpenAPI, markdown, docs data, ...).
Post-order walk over a spec tree. Normalizes each node, recurses into
its children (by :type), and calls (emit spec children) where children
is a map of already-walked sub-results shaped for the node's :type:
:one-of -> {:specs [walked...]}
:seq -> {:spec walked}
:map -> {:schema {k walked ...} :key-spec walked :value-spec walked}
leaf -> nil
The :* entity-level-spec key inside :schema is skipped (it is not a field
spec). Each sub-result is whatever the emit fn returned for that child, so
emit controls the output type (OpenAPI, markdown, docs data, ...).(with-lexicon overrides & body)Scopes lexicon overrides for the duration of body. Takes a partial lexicon map (with :types / :validations / :coercions / :presentations keys); each sub-map merges over the current binding.
Scopes lexicon overrides for the duration of body. Takes a partial lexicon map (with :types / :validations / :coercions / :presentations keys); each sub-map merges over the current binding.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |