Package com.networknt.schema
Class BaseJsonValidator
- java.lang.Object
-
- com.networknt.schema.BaseJsonValidator
-
- All Implemented Interfaces:
JsonValidator
,JsonSchemaWalker
- Direct Known Subclasses:
AdditionalPropertiesValidator
,AllOfValidator
,AnyOfValidator
,ConstValidator
,ContainsValidator
,DateTimeValidator
,DependenciesValidator
,DependentRequired
,DependentSchemas
,EnumValidator
,ExclusiveMaximumValidator
,ExclusiveMinimumValidator
,FalseValidator
,FormatValidator
,IfValidator
,ItemsValidator
,ItemsValidator202012
,JsonSchema
,MaximumValidator
,MaxItemsValidator
,MaxLengthValidator
,MaxPropertiesValidator
,MinimumValidator
,MinItemsValidator
,MinLengthValidator
,MinMaxContainsValidator
,MinPropertiesValidator
,MultipleOfValidator
,NotAllowedValidator
,NotValidator
,OneOfValidator
,PatternPropertiesValidator
,PatternValidator
,PrefixItemsValidator
,PropertiesValidator
,PropertyNamesValidator
,ReadOnlyValidator
,RefValidator
,RequiredValidator
,TrueValidator
,TypeValidator
,UnevaluatedItemsValidator
,UnevaluatedPropertiesValidator
,UnionTypeValidator
,UniqueItemsValidator
,WriteOnlyValidator
public abstract class BaseJsonValidator extends Object implements JsonValidator
-
-
Field Summary
Fields Modifier and Type Field Description protected ApplyDefaultsStrategy
applyDefaultsStrategy
protected boolean
failFast
protected JsonSchema
parentSchema
protected com.fasterxml.jackson.databind.JsonNode
schemaNode
protected String
schemaPath
protected boolean
suppressSubSchemaRetrieval
protected ValidationContext
validationContext
-
Constructor Summary
Constructors Constructor Description BaseJsonValidator(String schemaPath, com.fasterxml.jackson.databind.JsonNode schemaNode, JsonSchema parentSchema, ValidatorTypeCode validatorType, ValidationContext validationContext)
BaseJsonValidator(String schemaPath, com.fasterxml.jackson.databind.JsonNode schemaNode, JsonSchema parentSchema, ValidatorTypeCode validatorType, ValidationContext validationContext, boolean suppressSubSchemaRetrieval)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected String
atPath(String currentPath, int index)
Create the path for a given child indexed item.protected String
atPath(String currentPath, String token)
Create the path for a given child token.protected String
atRoot()
Get the root path.protected ValidationMessage
buildValidationMessage(String at, String... arguments)
protected static void
checkDiscriminatorMatch(ValidationContext.DiscriminatorContext currentDiscriminatorContext, com.fasterxml.jackson.databind.node.ObjectNode discriminator, String discriminatorPropertyValue, JsonSchema jsonSchema)
Checks based on the currentValidationContext.DiscriminatorContext
whether the providedJsonSchema
a match against against the current discriminator.protected ValidationMessage
constructValidationMessage(String messageKey, String at, String... arguments)
protected static void
debug(org.slf4j.Logger logger, com.fasterxml.jackson.databind.JsonNode node, com.fasterxml.jackson.databind.JsonNode rootNode, String at)
protected static boolean
equals(double n1, double n2)
protected JsonSchema
fetchSubSchemaNode(ValidationContext validationContext)
protected ErrorMessageType
getErrorMessageType()
protected String
getNodeFieldType()
JsonSchema
getParentSchema()
protected PathType
getPathType()
com.fasterxml.jackson.databind.JsonNode
getSchemaNode()
String
getSchemaPath()
protected ValidatorTypeCode
getValidatorType()
protected static boolean
greaterThan(double n1, double n2)
protected boolean
isPartOfOneOfMultipleType()
protected static boolean
lessThan(double n1, double n2)
protected void
parseErrorCode(String errorCodeKey)
protected void
preloadJsonSchemas(Collection<JsonSchema> schemas)
protected static void
registerAndMergeDiscriminator(ValidationContext.DiscriminatorContext currentDiscriminatorContext, com.fasterxml.jackson.databind.node.ObjectNode discriminator, JsonSchema schema, String at)
Rolls up all nested and compatible discriminators to the root discriminator of the type.protected void
updateValidatorType(ValidatorTypeCode validatorTypeCode)
Set<ValidationMessage>
validate(com.fasterxml.jackson.databind.JsonNode node)
Validate the given root JsonNode, starting at the root of the data path.Set<ValidationMessage>
walk(com.fasterxml.jackson.databind.JsonNode node, com.fasterxml.jackson.databind.JsonNode rootNode, String at, boolean shouldValidateSchema)
This is default implementation of walk method.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.networknt.schema.JsonValidator
preloadJsonSchema, validate
-
-
-
-
Field Detail
-
schemaPath
protected String schemaPath
-
schemaNode
protected com.fasterxml.jackson.databind.JsonNode schemaNode
-
parentSchema
protected JsonSchema parentSchema
-
suppressSubSchemaRetrieval
protected final boolean suppressSubSchemaRetrieval
-
validationContext
protected ValidationContext validationContext
-
failFast
protected final boolean failFast
-
applyDefaultsStrategy
protected final ApplyDefaultsStrategy applyDefaultsStrategy
-
-
Constructor Detail
-
BaseJsonValidator
public BaseJsonValidator(String schemaPath, com.fasterxml.jackson.databind.JsonNode schemaNode, JsonSchema parentSchema, ValidatorTypeCode validatorType, ValidationContext validationContext)
-
BaseJsonValidator
public BaseJsonValidator(String schemaPath, com.fasterxml.jackson.databind.JsonNode schemaNode, JsonSchema parentSchema, ValidatorTypeCode validatorType, ValidationContext validationContext, boolean suppressSubSchemaRetrieval)
-
-
Method Detail
-
getSchemaPath
public String getSchemaPath()
-
getSchemaNode
public com.fasterxml.jackson.databind.JsonNode getSchemaNode()
-
getParentSchema
public JsonSchema getParentSchema()
-
fetchSubSchemaNode
protected JsonSchema fetchSubSchemaNode(ValidationContext validationContext)
-
validate
public Set<ValidationMessage> validate(com.fasterxml.jackson.databind.JsonNode node)
Description copied from interface:JsonValidator
Validate the given root JsonNode, starting at the root of the data path.- Specified by:
validate
in interfaceJsonValidator
- Parameters:
node
- JsonNode- Returns:
- A list of ValidationMessage if there is any validation error, or an empty list if there is no error.
-
equals
protected static boolean equals(double n1, double n2)
-
greaterThan
protected static boolean greaterThan(double n1, double n2)
-
lessThan
protected static boolean lessThan(double n1, double n2)
-
parseErrorCode
protected void parseErrorCode(String errorCodeKey)
-
buildValidationMessage
protected ValidationMessage buildValidationMessage(String at, String... arguments)
-
constructValidationMessage
protected ValidationMessage constructValidationMessage(String messageKey, String at, String... arguments)
-
debug
protected static void debug(org.slf4j.Logger logger, com.fasterxml.jackson.databind.JsonNode node, com.fasterxml.jackson.databind.JsonNode rootNode, String at)
-
getValidatorType
protected ValidatorTypeCode getValidatorType()
-
getErrorMessageType
protected ErrorMessageType getErrorMessageType()
-
updateValidatorType
protected void updateValidatorType(ValidatorTypeCode validatorTypeCode)
-
getNodeFieldType
protected String getNodeFieldType()
-
walk
public Set<ValidationMessage> walk(com.fasterxml.jackson.databind.JsonNode node, com.fasterxml.jackson.databind.JsonNode rootNode, String at, boolean shouldValidateSchema)
This is default implementation of walk method. Its job is to call the validate method if shouldValidateSchema is enabled.- Specified by:
walk
in interfaceJsonSchemaWalker
- Specified by:
walk
in interfaceJsonValidator
- Parameters:
node
- JsonNoderootNode
- JsonNodeat
- StringshouldValidateSchema
- boolean- Returns:
- a set of validation messages if shouldValidateSchema is true.
-
preloadJsonSchemas
protected void preloadJsonSchemas(Collection<JsonSchema> schemas)
-
isPartOfOneOfMultipleType
protected boolean isPartOfOneOfMultipleType()
-
getPathType
protected PathType getPathType()
-
atRoot
protected String atRoot()
Get the root path.- Returns:
- The path.
-
atPath
protected String atPath(String currentPath, String token)
Create the path for a given child token.- Parameters:
currentPath
- The current path.token
- The child token.- Returns:
- The complete path.
-
atPath
protected String atPath(String currentPath, int index)
Create the path for a given child indexed item.- Parameters:
currentPath
- The current path.index
- The child index.- Returns:
- The complete path.
-
checkDiscriminatorMatch
protected static void checkDiscriminatorMatch(ValidationContext.DiscriminatorContext currentDiscriminatorContext, com.fasterxml.jackson.databind.node.ObjectNode discriminator, String discriminatorPropertyValue, JsonSchema jsonSchema)
Checks based on the currentValidationContext.DiscriminatorContext
whether the providedJsonSchema
a match against against the current discriminator.- Parameters:
currentDiscriminatorContext
- the currently activeValidationContext.DiscriminatorContext
discriminator
- the discriminator to use for the checkdiscriminatorPropertyValue
- the value of thediscriminator/propertyName
fieldjsonSchema
- theJsonSchema
to check
-
registerAndMergeDiscriminator
protected static void registerAndMergeDiscriminator(ValidationContext.DiscriminatorContext currentDiscriminatorContext, com.fasterxml.jackson.databind.node.ObjectNode discriminator, JsonSchema schema, String at)
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 activeValidationContext.DiscriminatorContext
discriminator
- the discriminator to use for the checkschema
- the value of thediscriminator/propertyName
fieldat
- the logging prefix
-
-