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
,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
public abstract class BaseJsonValidator extends ValidationMessageHandler implements JsonValidator
-
-
Field Summary
Fields Modifier and Type Field Description protected ApplyDefaultsStrategy
applyDefaultsStrategy
protected com.fasterxml.jackson.databind.JsonNode
schemaNode
protected boolean
suppressSubSchemaRetrieval
protected ValidationContext
validationContext
-
Fields inherited from class com.networknt.schema.ValidationMessageHandler
customErrorMessagesEnabled, errorMessage, errorMessageType, evaluationParentSchema, evaluationPath, failFast, keyword, messageSource, parentSchema, schemaLocation
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
BaseJsonValidator(BaseJsonValidator copy)
Copy constructor.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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected 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 against the current discriminator.protected static void
debug(org.slf4j.Logger logger, 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)
JsonSchema
getEvaluationParentSchema()
Gets the evaluation parent schema.JsonNodePath
getEvaluationPath()
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.String
getKeyword()
The keyword of the validator.protected String
getNodeFieldType()
JsonSchema
getParentSchema()
Gets the parent schema.SchemaLocation
getSchemaLocation()
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
getSchemaNode()
protected void
preloadJsonSchemas(Collection<JsonSchema> schemas)
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.String
toString()
Set<ValidationMessage>
validate(ExecutionContext executionContext, com.fasterxml.jackson.databind.JsonNode node)
<T> T
validate(ExecutionContext executionContext, com.fasterxml.jackson.databind.JsonNode node, OutputFormat<T> format)
Validates to a format.<T> T
validate(ExecutionContext executionContext, com.fasterxml.jackson.databind.JsonNode node, OutputFormat<T> format, ExecutionContextCustomizer executionCustomizer)
Validates to a format.-
Methods inherited from class com.networknt.schema.ValidationMessageHandler
getErrorCodeKey, getErrorMessage, getErrorMessageType, getMessageNode, isPartOfOneOfMultipleType, message, parseErrorCode, schemaLocationContains, updateErrorMessageType, updateKeyword, updateValidatorType
-
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 Detail
-
suppressSubSchemaRetrieval
protected final boolean suppressSubSchemaRetrieval
-
applyDefaultsStrategy
protected final ApplyDefaultsStrategy applyDefaultsStrategy
-
schemaNode
protected final com.fasterxml.jackson.databind.JsonNode schemaNode
-
validationContext
protected ValidationContext validationContext
-
-
Constructor Detail
-
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(BaseJsonValidator copy)
Copy constructor.- Parameters:
copy
- to copy from
-
-
Method Detail
-
equals
protected static boolean equals(double n1, double n2)
-
debug
protected static void debug(org.slf4j.Logger logger, 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 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
public SchemaLocation 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
public JsonNodePath 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
public String 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
public JsonSchema getParentSchema()
Gets the parent schema.This is the lexical parent schema.
- Returns:
- the parent schema
-
getEvaluationParentSchema
public JsonSchema getEvaluationParentSchema()
Gets the evaluation parent schema.This is the dynamic parent schema when following references.
- Returns:
- the evaluation parent schema
- See Also:
JsonSchema.fromRef(JsonSchema, JsonNodePath)
-
fetchSubSchemaNode
protected JsonSchema fetchSubSchemaNode(ValidationContext validationContext)
-
validate
public Set<ValidationMessage> validate(ExecutionContext executionContext, com.fasterxml.jackson.databind.JsonNode node)
-
validate
public <T> T validate(ExecutionContext executionContext, com.fasterxml.jackson.databind.JsonNode node, OutputFormat<T> format)
Validates to a format.- Type Parameters:
T
- the result type- Parameters:
executionContext
- the execution contextnode
- the nodeformat
- the format- Returns:
- the result
-
validate
public <T> T validate(ExecutionContext executionContext, com.fasterxml.jackson.databind.JsonNode node, OutputFormat<T> format, ExecutionContextCustomizer executionCustomizer)
Validates to a format.- Type Parameters:
T
- the result type- Parameters:
executionContext
- the execution contextnode
- the nodeformat
- the formatexecutionCustomizer
- the customizer- Returns:
- the result
-
getNodeFieldType
protected String getNodeFieldType()
-
preloadJsonSchemas
protected void preloadJsonSchemas(Collection<JsonSchema> schemas)
-
atRoot
protected JsonNodePath atRoot()
Get the root path.- Returns:
- The path.
-
-