Skip to main content

Module validate

Module validate 

Source
Expand description

Checking a value against a JSON Schema type of a bundle (spec core.md §7.3), for tools that build a payload from JSON and were never compiled against the contract (#671).

The subset is small on purpose (§7.3): type, properties, required, additionalProperties, items, prefixItems, enum, const, the numeric bounds, minLength/maxLength, minItems/maxItems, $ref and oneOf/anyOf, plus boolean schemas. None of them needs a regular-expression dialect, which is why the subset refuses pattern. This module implements those keywords as JSON Schema 2020-12 defines them, and nothing else: an annotation is ignored, and a keyword outside the subset cannot occur, because a contract that uses one does not load (E037).

The core requires no owner to evaluate a schema (§5.1, “The request”), and a caller MUST NOT depend on a refusal of what the schema refuses: a writer sends only what its schema declares (§9.8). This is how a tool keeps that side of the rule before it sends.

Structs§

Violation
One way a value fails its schema.

Functions§

resolve_ref
Resolves a $ref written in doc, one of bundle’s JSON Schema documents (§9.4): the file part names another of them by its stem (the last path segment, without .json), and an empty one names doc itself. Returns the schema it points at and the document holding it, from which that schema’s own $refs resolve.
satisfies
Whether value satisfies schema, one schema position inside doc, a JSON Schema document of bundle: its $refs resolve from doc, as resolve_ref says.
validate
Checks value against the JSON Schema type ty, a canonical type reference of bundle ({"kind": "jsonschema", "name", "schema"}). Err lists every violation found, in the order met; a type that is not a JSON Schema type of the bundle, or a $ref that resolves to nothing, is one violation at the root.