JSON Schema 2020-12 evaluation.
The evaluator answers ANNOTATIONS as well as errors, from the first line and
not as a later addition: unevaluatedProperties and unevaluatedItems are
defined in terms of what the ADJACENT keywords and the in-place applicators
already evaluated, so a validator that answers only true/false cannot grow
them without being rewritten. Every evaluation therefore returns
{:valid? :props :items :errors} - the property names and item indices that
were evaluated AT THIS INSTANCE LOCATION, plus every fault found underneath.
Two kinds of applicator, and the difference is the whole design:
$ref, $dynamicRef, allOf, anyOf, oneOf, if/then/
else, dependentSchemas) apply another schema to the SAME instance
location, so their annotations belong to this location and bubble up.properties, patternProperties, additionalProperties, items,
prefixItems, contains, propertyNames) apply to a location BELOW, so
their annotations stay there and this location records only which member
was covered.Identifiers are resolved once, when the schema is compiled: $id moves the
base URI, $anchor and $dynamicAnchor name a place inside it, and the
index that comes out is what $ref and $dynamicRef read. Nothing is
fetched over the network, ever - a schema that references a document the
caller did not supply is a compile error, not a silent pass.
JSON Schema 2020-12 evaluation.
The evaluator answers ANNOTATIONS as well as errors, from the first line and
not as a later addition: `unevaluatedProperties` and `unevaluatedItems` are
defined in terms of what the ADJACENT keywords and the in-place applicators
already evaluated, so a validator that answers only true/false cannot grow
them without being rewritten. Every evaluation therefore returns
`{:valid? :props :items :errors}` - the property names and item indices that
were evaluated AT THIS INSTANCE LOCATION, plus every fault found underneath.
Two kinds of applicator, and the difference is the whole design:
- IN PLACE (`$ref`, `$dynamicRef`, `allOf`, `anyOf`, `oneOf`, `if`/`then`/
`else`, `dependentSchemas`) apply another schema to the SAME instance
location, so their annotations belong to this location and bubble up.
- CHILD (`properties`, `patternProperties`, `additionalProperties`, `items`,
`prefixItems`, `contains`, `propertyNames`) apply to a location BELOW, so
their annotations stay there and this location records only which member
was covered.
Identifiers are resolved once, when the schema is compiled: `$id` moves the
base URI, `$anchor` and `$dynamicAnchor` name a place inside it, and the
index that comes out is what `$ref` and `$dynamicRef` read. Nothing is
fetched over the network, ever - a schema that references a document the
caller did not supply is a compile error, not a silent pass.(compile-ref compiled ref)A compiled schema that validates against ref, resolved from the root of
compiled. It shares the index, options and reference cache of compiled,
so the definitions of one document cost one compile. It validates with the
complete evaluator.
A compiled schema that validates against `ref`, resolved from the root of `compiled`. It shares the index, options and reference cache of `compiled`, so the definitions of one document cost one compile. It validates with the complete evaluator.
(compile-schema schema)(compile-schema schema opts)Compile and index a schema once so repeated validation does not walk its
structure. Options: :base, :registry, and :format-assertion. Referenced
documents are resolved only from the supplied registry.
Compile and index a schema once so repeated validation does not walk its structure. Options: `:base`, `:registry`, and `:format-assertion`. Referenced documents are resolved only from the supplied registry.
(explain schema instance)(explain schema instance opts)Nil when instance satisfies the schema, otherwise JSON Schema BASIC output -
{:valid false :errors [...]} - where every error keeps its instance and
keyword locations and adds :keyword plus keyword-specific :params, so a
caller can render or act on it without parsing the human :error string. The
entire answer is a JSON value, and it carries the first ten errors of the
instance: a reader acts on those, and the rest only cost the walk that finds
them.
Nil when `instance` satisfies the schema, otherwise JSON Schema BASIC output -
`{:valid false :errors [...]}` - where every error keeps its instance and
keyword locations and adds `:keyword` plus keyword-specific `:params`, so a
caller can render or act on it without parsing the human `:error` string. The
entire answer is a JSON value, and it carries the first ten errors of the
instance: a reader acts on those, and the rest only cost the walk that finds
them.(explainer schema)(explainer schema opts)The reasons as a bare function of the instance: nil when it validates, else
JSON Schema BASIC output, at most ten errors of it. The counterpart of
validator for the same schema.
The reasons as a bare function of the instance: nil when it validates, else JSON Schema BASIC output, at most ten errors of it. The counterpart of `validator` for the same schema.
(read-schema source)Read a JSON Schema from JSON text, a Path, File, URL/resource, InputStream, or Reader. Objects keep their JSON string keys.
Read a JSON Schema from JSON text, a Path, File, URL/resource, InputStream, or Reader. Objects keep their JSON string keys.
(validate schema instance)(validate schema instance opts)True when instance satisfies the schema. validator is the same answer
without the per-call dispatch.
True when `instance` satisfies the schema. `validator` is the same answer without the per-call dispatch.
(validator schema)(validator schema opts)The verdict as a bare function of the instance. It closes over the compiled predicate, so a call reaches it without a map lookup - take this when the same schema validates more than once. Evaluation stops at the first keyword that refuses and no error is built on the way.
The verdict as a bare function of the instance. It closes over the compiled predicate, so a call reaches it without a map lookup - take this when the same schema validates more than once. Evaluation stops at the first keyword that refuses and no error is built on the way.
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 |