public final class SchemaValidator extends Object
Supported: $ref (to the root # or a top-level #/$defs/... only), type,
enum, const, required, properties, additionalProperties,
items, propertyNames, allOf, anyOf, oneOf, not,
if/then/else, unevaluatedProperties, pattern, minItems,
minLength, minimum, maximum, and boolean schemas. format is an annotation and
asserts nothing, which is the Draft 2020-12 default and what the reference runner does. Annotation keywords
(description, title, $schema, $id, $comment, examples,
default, x-*, and $defs at the root) are ignored. Any other keyword, a nested
$defs, a $ref cycle, or a pattern outside the supported regex subset makes the constructor
throw, so a schema change that needs more of the specification cannot be validated silently wrong.
unevaluatedProperties follows the 2020-12 annotation model: a property counts as evaluated when
properties or additionalProperties of the same schema object, or of a subschema applied in
place that validated ($ref, allOf, anyOf, oneOf, if/then/
else, a nested unevaluatedProperties), covered it. Every branch of anyOf is
evaluated for its annotations.
Errors form the tree the reference runner inspects (python-jsonschema): an error per failing keyword (per
missing member for required), nested errors of the subschemas descended into, and for a failing
anyOf or oneOf the errors of every branch as its context. A subschema reached twice at one
instance location is reported once. Patterns are searched (not anchored unless they anchor themselves), with
Python's re meaning of \s and $.
The validator copies the schema and is immutable; one instance may serve concurrent callers.
| Modifier and Type | Class and Description |
|---|---|
static class |
SchemaValidator.SchemaError
One validation error: the failing keyword, its schema object, the instance and where it is.
|
| Constructor and Description |
|---|
SchemaValidator(Object schema)
A validator for a parsed schema (an object or a boolean), copied so later changes to the argument have no
effect.
|
| Modifier and Type | Method and Description |
|---|---|
List<SchemaValidator.SchemaError> |
errors(Object instance)
Every error of an instance against the schema; empty when it is valid.
|
List<SchemaValidator.SchemaError> |
errors(Object instance,
String definition)
Every error of an instance against one definition of the schema, such as
Fact. |
boolean |
isValid(Object instance)
True when the instance is valid against the schema.
|
boolean |
isValid(Object instance,
String definition)
True when the instance is valid against one definition of the schema, such as
Fact. |
static SchemaValidator |
lineageDocument()
A validator for the lineage document schema this library ships.
|
public SchemaValidator(Object schema)
IllegalStateException - when the schema uses a keyword this validator does not implement, a
$ref it cannot resolve, a $ref cycle, or a pattern outside
the supported regex subsetpublic static SchemaValidator lineageDocument()
public List<SchemaValidator.SchemaError> errors(Object instance)
public List<SchemaValidator.SchemaError> errors(Object instance, String definition)
Fact.IllegalArgumentException - when the schema has no such definitionpublic boolean isValid(Object instance, String definition)
Fact.IllegalArgumentException - when the schema has no such definition