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
public abstract class BaseJsonValidator extends Object implements JsonValidator
-
-
Field Summary
Fields Modifier and Type Field Description protected ApplyDefaultsStrategyapplyDefaultsStrategyprotected booleanfailFastprotected JsonSchemaparentSchemaprotected com.fasterxml.jackson.databind.JsonNodeschemaNodeprotected StringschemaPathprotected booleansuppressSubSchemaRetrievalprotected ValidationContextvalidationContext
-
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 StringatPath(String currentPath, int index)Create the path for a given child indexed item.protected StringatPath(String currentPath, String token)Create the path for a given child token.protected StringatRoot()Get the root path.protected ValidationMessagebuildValidationMessage(String at, String... arguments)protected static voidcheckDiscriminatorMatch(ValidationContext.DiscriminatorContext currentDiscriminatorContext, com.fasterxml.jackson.databind.node.ObjectNode discriminator, String discriminatorPropertyValue, JsonSchema jsonSchema)Checks based on the currentValidationContext.DiscriminatorContextwhether the providedJsonSchemaa match against against the current discriminator.protected ValidationMessageconstructValidationMessage(String messageKey, String at, String... arguments)protected voiddebug(org.slf4j.Logger logger, com.fasterxml.jackson.databind.JsonNode node, com.fasterxml.jackson.databind.JsonNode rootNode, String at)protected booleanequals(double n1, double n2)protected JsonSchemafetchSubSchemaNode(ValidationContext validationContext)protected ErrorMessageTypegetErrorMessageType()protected StringgetNodeFieldType()JsonSchemagetParentSchema()protected PathTypegetPathType()com.fasterxml.jackson.databind.JsonNodegetSchemaNode()StringgetSchemaPath()protected ValidatorTypeCodegetValidatorType()protected booleangreaterThan(double n1, double n2)protected booleanisPartOfOneOfMultipleType()protected booleanlessThan(double n1, double n2)protected voidparseErrorCode(String errorCodeKey)protected voidpreloadJsonSchemas(Collection<JsonSchema> schemas)protected static voidregisterAndMergeDiscriminator(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 voidupdateValidatorType(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:JsonValidatorValidate the given root JsonNode, starting at the root of the data path.- Specified by:
validatein 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 boolean equals(double n1, double n2)
-
greaterThan
protected boolean greaterThan(double n1, double n2)
-
lessThan
protected 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 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:
walkin interfaceJsonSchemaWalker- Specified by:
walkin 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.DiscriminatorContextwhether the providedJsonSchemaa match against against the current discriminator.- Parameters:
currentDiscriminatorContext- the currently activeValidationContext.DiscriminatorContextdiscriminator- the discriminator to use for the checkdiscriminatorPropertyValue- the value of thediscriminator/propertyNamefieldjsonSchema- theJsonSchemato 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 thepropertyNameor mappings.- Parameters:
currentDiscriminatorContext- the currently activeValidationContext.DiscriminatorContextdiscriminator- the discriminator to use for the checkschema- the value of thediscriminator/propertyNamefieldat- the logging prefix
-
-