Package com.networknt.schema
Class BaseJsonValidator
java.lang.Object
com.networknt.schema.ValidationMessageHandler
com.networknt.schema.BaseJsonValidator
- All Implemented Interfaces:
JsonValidator
,JsonSchemaWalker
- Direct Known Subclasses:
AdditionalPropertiesValidator
,AllOfValidator
,AnyOfValidator
,BaseFormatJsonValidator
,ConstValidator
,ContainsValidator
,ContentEncodingValidator
,ContentMediaTypeValidator
,DependenciesValidator
,DependentRequired
,DependentSchemas
,DiscriminatorValidator
,DynamicRefValidator
,EnumValidator
,ExclusiveMaximumValidator
,ExclusiveMinimumValidator
,FalseValidator
,IfValidator
,ItemsValidator
,ItemsValidator202012
,JsonSchema
,MaximumValidator
,MaxItemsValidator
,MaxLengthValidator
,MaxPropertiesValidator
,MinimumValidator
,MinItemsValidator
,MinLengthValidator
,MinMaxContainsValidator
,MinPropertiesValidator
,MultipleOfValidator
,NotAllowedValidator
,NotValidator
,OneOfValidator
,PatternPropertiesValidator
,PatternValidator
,PrefixItemsValidator
,PropertiesValidator
,PropertyNamesValidator
,ReadOnlyValidator
,RecursiveRefValidator
,RefValidator
,RequiredValidator
,TrueValidator
,TypeValidator
,UnevaluatedItemsValidator
,UnevaluatedPropertiesValidator
,UnionTypeValidator
,UniqueItemsValidator
,WriteOnlyValidator
Base
JsonValidator
.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
static class
static class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final com.fasterxml.jackson.databind.JsonNode
protected final boolean
protected final ValidationContext
Fields inherited from class com.networknt.schema.ValidationMessageHandler
errorMessage, errorMessageKeyword, errorMessageType, evaluationParentSchema, evaluationPath, keyword, messageSource, parentSchema, schemaLocation
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
BaseJsonValidator
(boolean suppressSubSchemaRetrieval, com.fasterxml.jackson.databind.JsonNode schemaNode, ValidationContext validationContext, ErrorMessageType errorMessageType, String errorMessageKeyword, MessageSource messageSource, Keyword keyword, JsonSchema parentSchema, SchemaLocation schemaLocation, JsonNodePath evaluationPath, JsonSchema evaluationParentSchema, Map<String, String> errorMessage) Constructor to create a copy using fields.BaseJsonValidator
(SchemaLocation schemaLocation, JsonNodePath evaluationPath, com.fasterxml.jackson.databind.JsonNode schemaNode, JsonSchema parentSchema, ErrorMessageType errorMessageType, Keyword keyword, ValidationContext validationContext, boolean suppressSubSchemaRetrieval) BaseJsonValidator
(SchemaLocation schemaLocation, JsonNodePath evaluationPath, com.fasterxml.jackson.databind.JsonNode schemaNode, JsonSchema parentSchema, ValidatorTypeCode validatorType, ValidationContext validationContext) -
Method Summary
Modifier and TypeMethodDescriptionprotected JsonNodePath
atRoot()
Get the root path.protected static void
checkDiscriminatorMatch
(DiscriminatorContext currentDiscriminatorContext, com.fasterxml.jackson.databind.node.ObjectNode discriminator, String discriminatorPropertyValue, JsonSchema jsonSchema) Checks based on the currentDiscriminatorContext
whether the providedJsonSchema
a match against the current discriminator.protected boolean
collectAnnotations
(ExecutionContext executionContext) Determine if annotations should be reported.protected boolean
collectAnnotations
(ExecutionContext executionContext, String keyword) Determine if annotations should be reported.static void
debug
(org.slf4j.Logger logger, ExecutionContext executionContext, com.fasterxml.jackson.databind.JsonNode node, com.fasterxml.jackson.databind.JsonNode rootNode, JsonNodePath instanceLocation) protected static boolean
equals
(double n1, double n2) protected JsonSchema
fetchSubSchemaNode
(ValidationContext validationContext) Gets the evaluation parent schema.The evaluation path is the set of keys, starting from the schema root, through which evaluation passes to reach the schema object that produced a specific result.The keyword of the validator.protected String
Gets the parent schema.The schema location is the canonical URI of the schema object plus a JSON Pointer fragment indicating the subschema that produced a result.com.fasterxml.jackson.databind.JsonNode
protected boolean
hasAdjacentKeywordInEvaluationPath
(String keyword) Determines if the keyword exists adjacent in the evaluation path.protected MessageSourceValidationMessage.Builder
message()
protected void
preloadJsonSchemas
(Collection<JsonSchema> schemas) protected void
putAnnotation
(ExecutionContext executionContext, Consumer<JsonNodeAnnotation.Builder> customizer) Puts an annotation.protected static void
registerAndMergeDiscriminator
(DiscriminatorContext currentDiscriminatorContext, com.fasterxml.jackson.databind.node.ObjectNode discriminator, JsonSchema schema, JsonNodePath instanceLocation) Rolls up all nested and compatible discriminators to the root discriminator of the type.toString()
validate
(ExecutionContext executionContext, com.fasterxml.jackson.databind.JsonNode node) Methods inherited from class com.networknt.schema.ValidationMessageHandler
getErrorMessage, getErrorMessageType, getMessageNode
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface com.networknt.schema.JsonValidator
preloadJsonSchema, validate, walk
-
Field Details
-
suppressSubSchemaRetrieval
protected final boolean suppressSubSchemaRetrieval -
schemaNode
protected final com.fasterxml.jackson.databind.JsonNode schemaNode -
validationContext
-
-
Constructor Details
-
BaseJsonValidator
public BaseJsonValidator(SchemaLocation schemaLocation, JsonNodePath evaluationPath, com.fasterxml.jackson.databind.JsonNode schemaNode, JsonSchema parentSchema, ValidatorTypeCode validatorType, ValidationContext validationContext) -
BaseJsonValidator
public BaseJsonValidator(SchemaLocation schemaLocation, JsonNodePath evaluationPath, com.fasterxml.jackson.databind.JsonNode schemaNode, JsonSchema parentSchema, ErrorMessageType errorMessageType, Keyword keyword, ValidationContext validationContext, boolean suppressSubSchemaRetrieval) -
BaseJsonValidator
protected BaseJsonValidator(boolean suppressSubSchemaRetrieval, com.fasterxml.jackson.databind.JsonNode schemaNode, ValidationContext validationContext, ErrorMessageType errorMessageType, String errorMessageKeyword, MessageSource messageSource, Keyword keyword, JsonSchema parentSchema, SchemaLocation schemaLocation, JsonNodePath evaluationPath, JsonSchema evaluationParentSchema, Map<String, String> errorMessage) Constructor to create a copy using fields.- Parameters:
suppressSubSchemaRetrieval
- to suppress sub schema retrievalschemaNode
- the schema nodevalidationContext
- the validation contexterrorMessageType
- the error message typeerrorMessageKeyword
- the error message keywordmessageSource
- the message sourcekeyword
- the keywordparentSchema
- the parent schemaschemaLocation
- the schema locationevaluationPath
- the evaluation pathevaluationParentSchema
- the evaluation parent schemaerrorMessage
- the error message
-
-
Method Details
-
equals
protected static boolean equals(double n1, double n2) -
debug
public static void debug(org.slf4j.Logger logger, ExecutionContext executionContext, com.fasterxml.jackson.databind.JsonNode node, com.fasterxml.jackson.databind.JsonNode rootNode, JsonNodePath instanceLocation) -
checkDiscriminatorMatch
protected static void checkDiscriminatorMatch(DiscriminatorContext currentDiscriminatorContext, com.fasterxml.jackson.databind.node.ObjectNode discriminator, String discriminatorPropertyValue, JsonSchema jsonSchema) Checks based on the currentDiscriminatorContext
whether the providedJsonSchema
a match against the current discriminator.- Parameters:
currentDiscriminatorContext
- the currently activeDiscriminatorContext
discriminator
- the discriminator to use for the checkdiscriminatorPropertyValue
- the value of thediscriminator/propertyName
fieldjsonSchema
- theJsonSchema
to check
-
registerAndMergeDiscriminator
protected static void registerAndMergeDiscriminator(DiscriminatorContext currentDiscriminatorContext, com.fasterxml.jackson.databind.node.ObjectNode discriminator, JsonSchema schema, JsonNodePath instanceLocation) Rolls up all nested and compatible discriminators to the root discriminator of the type. Detects attempts to redefine thepropertyName
or mappings.- Parameters:
currentDiscriminatorContext
- the currently activeDiscriminatorContext
discriminator
- the discriminator to use for the checkschema
- the value of thediscriminator/propertyName
fieldinstanceLocation
- the logging prefix
-
getSchemaLocation
Description copied from interface:JsonValidator
The schema location is the canonical URI of the schema object plus a JSON Pointer fragment indicating the subschema that produced a result. In contrast with the evaluation path, the schema location MUST NOT include by-reference applicators such as $ref or $dynamicRef.- Specified by:
getSchemaLocation
in interfaceJsonValidator
- Returns:
- the schema location
-
getEvaluationPath
Description copied from interface:JsonValidator
The evaluation path is the set of keys, starting from the schema root, through which evaluation passes to reach the schema object that produced a specific result.- Specified by:
getEvaluationPath
in interfaceJsonValidator
- Returns:
- the evaluation path
-
getKeyword
Description copied from interface:JsonValidator
The keyword of the validator.- Specified by:
getKeyword
in interfaceJsonValidator
- Returns:
- the keyword
-
getSchemaNode
public com.fasterxml.jackson.databind.JsonNode getSchemaNode() -
getParentSchema
Gets the parent schema.This is the lexical parent schema.
- Returns:
- the parent schema
-
getEvaluationParentSchema
Gets the evaluation parent schema.This is the dynamic parent schema when following references.
- Returns:
- the evaluation parent schema
- See Also:
-
fetchSubSchemaNode
-
validate
public Set<ValidationMessage> validate(ExecutionContext executionContext, com.fasterxml.jackson.databind.JsonNode node) -
getNodeFieldType
-
preloadJsonSchemas
-
atRoot
Get the root path.- Returns:
- The path.
-
toString
-
hasAdjacentKeywordInEvaluationPath
Determines if the keyword exists adjacent in the evaluation path.This does not check if the keyword exists in the current meta schema as this can be a cross-draft case where the properties keyword is in a Draft 7 schema and the unevaluatedProperties keyword is in an outer Draft 2020-12 schema.
The fact that the validator exists in the evaluation path implies that the keyword was valid in whatever meta schema for that schema it was created for.
- Parameters:
keyword
- the keyword to check- Returns:
- true if found
-
message
- Overrides:
message
in classValidationMessageHandler
-
collectAnnotations
Determine if annotations should be reported.- Parameters:
executionContext
- the execution context- Returns:
- true if annotations should be reported
-
collectAnnotations
Determine if annotations should be reported.- Parameters:
executionContext
- the execution contextkeyword
- the keyword- Returns:
- true if annotations should be reported
-
putAnnotation
protected void putAnnotation(ExecutionContext executionContext, Consumer<JsonNodeAnnotation.Builder> customizer) Puts an annotation.- Parameters:
executionContext
- the execution contextcustomizer
- to customize the annotation
-