Package com.networknt.schema
Class SchemaValidatorsConfig
- java.lang.Object
-
- com.networknt.schema.SchemaValidatorsConfig
-
public class SchemaValidatorsConfig extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static String
ALL_KEYWORD_WALK_LISTENER_KEY
-
Constructor Summary
Constructors Constructor Description SchemaValidatorsConfig()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addItemWalkListener(JsonSchemaWalkListener itemWalkListener)
void
addItemWalkListeners(List<JsonSchemaWalkListener> itemWalkListeners)
void
addKeywordWalkListener(JsonSchemaWalkListener keywordWalkListener)
void
addKeywordWalkListener(String keyword, JsonSchemaWalkListener keywordWalkListener)
void
addKeywordWalkListeners(String keyword, List<JsonSchemaWalkListener> keywordWalkListeners)
void
addKeywordWalkListeners(List<JsonSchemaWalkListener> keywordWalkListeners)
void
addPropertyWalkListener(JsonSchemaWalkListener propertyWalkListener)
void
addPropertyWalkListeners(List<JsonSchemaWalkListener> propertyWalkListeners)
SchemaValidatorsConfig
disableUnevaluatedAnalysis()
SchemaValidatorsConfig
disableUnevaluatedItems()
SchemaValidatorsConfig
disableUnevaluatedProperties()
boolean
doLoadCollectors()
SchemaValidatorsConfig
enableUnevaluatedAnalysis()
SchemaValidatorsConfig
enableUnevaluatedItems()
SchemaValidatorsConfig
enableUnevaluatedProperties()
ApplyDefaultsStrategy
getApplyDefaultsStrategy()
List<JsonSchemaWalkListener>
getArrayItemWalkListeners()
ExecutionContextCustomizer
getExecutionContextCustomizer()
Boolean
getFormatAssertionsEnabled()
Gets the format assertion enabled flag.Map<String,List<JsonSchemaWalkListener>>
getKeywordWalkListenersMap()
Locale
getLocale()
Get the locale to consider when generating localised messages (default is the JVM default).MessageSource
getMessageSource()
Get the message source to use for generating localised messages.PathType
getPathType()
Get the approach used to generate paths in messages, logs and errors.List<JsonSchemaWalkListener>
getPropertyWalkListeners()
JsonSchemaIdValidator
getSchemaIdValidator()
Gets the schema id validator to validate $id.boolean
isCustomMessageSupported()
boolean
isEcma262Validator()
boolean
isFailFast()
boolean
isHandleNullableField()
boolean
isJavaSemantics()
boolean
isLosslessNarrowing()
boolean
isOpenAPI3StyleDiscriminators()
Indicates whether OpenAPI 3 style discriminators should be supportedboolean
isPreloadJsonSchema()
Gets if the schema should be preloaded.boolean
isReadOnly()
boolean
isStrict(String keyword)
Answers whether a keyword's validators may relax their analysis.boolean
isStrict(String keyword, Boolean defaultValue)
Determines if the validator should perform strict checking.boolean
isTypeLoose()
boolean
isUnevaluatedItemsAnalysisDisabled()
boolean
isUnevaluatedItemsAnalysisEnabled()
boolean
isUnevaluatedPropertiesAnalysisDisabled()
boolean
isUnevaluatedPropertiesAnalysisEnabled()
boolean
isWriteMode()
Deprecated.boolean
isWriteOnly()
void
setApplyDefaultsStrategy(ApplyDefaultsStrategy applyDefaultsStrategy)
void
setCustomMessageSupported(boolean customMessageSupported)
void
setEcma262Validator(boolean ecma262Validator)
void
setExecutionContextCustomizer(ExecutionContextCustomizer executionContextCustomizer)
void
setFailFast(boolean failFast)
When enabled,JsonValidator.validate(ExecutionContext, JsonNode, JsonNode, JsonNodePath)
doesn't return anySet
<ValidationMessage
>, instead aJsonSchemaException
is thrown as soon as a validation errors is discovered.void
setFormatAssertionsEnabled(Boolean formatAssertionsEnabled)
Sets the format assertion enabled flag.void
setHandleNullableField(boolean handleNullableField)
void
setJavaSemantics(boolean javaSemantics)
void
setLoadCollectors(boolean loadCollectors)
void
setLocale(Locale locale)
Set the locale to consider when generating localised messages.void
setLosslessNarrowing(boolean losslessNarrowing)
void
setMessageSource(MessageSource messageSource)
Set the message source to use for generating localised messages.void
setOpenAPI3StyleDiscriminators(boolean openAPI3StyleDiscriminators)
When enabled, the validation ofanyOf
andallOf
in polymorphism will respect OpenAPI 3 style discriminators as described in the OpenAPI 3.0.3 spec.void
setPathType(PathType pathType)
Set the approach used to generate paths in messages, logs and errors (default is PathType.LEGACY).void
setPreloadJsonSchema(boolean preloadJsonSchema)
Sets if the schema should be preloaded.void
setReadOnly(boolean readOnly)
void
setSchemaIdValidator(JsonSchemaIdValidator schemaIdValidator)
Sets the schema id validator to validate $id.void
setStrict(String keyword, boolean strict)
Alters the strictness of validations for a specific keyword.void
setTypeLoose(boolean typeLoose)
void
setWriteOnly(boolean writeOnly)
-
-
-
Field Detail
-
ALL_KEYWORD_WALK_LISTENER_KEY
public static final String ALL_KEYWORD_WALK_LISTENER_KEY
- See Also:
- Constant Field Values
-
-
Method Detail
-
disableUnevaluatedAnalysis
public SchemaValidatorsConfig disableUnevaluatedAnalysis()
-
disableUnevaluatedItems
public SchemaValidatorsConfig disableUnevaluatedItems()
-
disableUnevaluatedProperties
public SchemaValidatorsConfig disableUnevaluatedProperties()
-
enableUnevaluatedAnalysis
public SchemaValidatorsConfig enableUnevaluatedAnalysis()
-
enableUnevaluatedItems
public SchemaValidatorsConfig enableUnevaluatedItems()
-
enableUnevaluatedProperties
public SchemaValidatorsConfig enableUnevaluatedProperties()
-
isUnevaluatedItemsAnalysisDisabled
public boolean isUnevaluatedItemsAnalysisDisabled()
-
isUnevaluatedItemsAnalysisEnabled
public boolean isUnevaluatedItemsAnalysisEnabled()
-
isUnevaluatedPropertiesAnalysisDisabled
public boolean isUnevaluatedPropertiesAnalysisDisabled()
-
isUnevaluatedPropertiesAnalysisEnabled
public boolean isUnevaluatedPropertiesAnalysisEnabled()
-
isTypeLoose
public boolean isTypeLoose()
- Returns:
- true if type loose is used.
-
setTypeLoose
public void setTypeLoose(boolean typeLoose)
-
setFailFast
public void setFailFast(boolean failFast)
When enabled,JsonValidator.validate(ExecutionContext, JsonNode, JsonNode, JsonNodePath)
doesn't return anySet
<ValidationMessage
>, instead aJsonSchemaException
is thrown as soon as a validation errors is discovered.- Parameters:
failFast
- boolean
-
isFailFast
public boolean isFailFast()
-
setApplyDefaultsStrategy
public void setApplyDefaultsStrategy(ApplyDefaultsStrategy applyDefaultsStrategy)
-
getApplyDefaultsStrategy
public ApplyDefaultsStrategy getApplyDefaultsStrategy()
-
isHandleNullableField
public boolean isHandleNullableField()
-
setHandleNullableField
public void setHandleNullableField(boolean handleNullableField)
-
isEcma262Validator
public boolean isEcma262Validator()
-
setEcma262Validator
public void setEcma262Validator(boolean ecma262Validator)
-
isJavaSemantics
public boolean isJavaSemantics()
-
setJavaSemantics
public void setJavaSemantics(boolean javaSemantics)
-
isCustomMessageSupported
public boolean isCustomMessageSupported()
-
setCustomMessageSupported
public void setCustomMessageSupported(boolean customMessageSupported)
-
addKeywordWalkListener
public void addKeywordWalkListener(JsonSchemaWalkListener keywordWalkListener)
-
addKeywordWalkListener
public void addKeywordWalkListener(String keyword, JsonSchemaWalkListener keywordWalkListener)
-
addKeywordWalkListeners
public void addKeywordWalkListeners(List<JsonSchemaWalkListener> keywordWalkListeners)
-
addKeywordWalkListeners
public void addKeywordWalkListeners(String keyword, List<JsonSchemaWalkListener> keywordWalkListeners)
-
addPropertyWalkListeners
public void addPropertyWalkListeners(List<JsonSchemaWalkListener> propertyWalkListeners)
-
addPropertyWalkListener
public void addPropertyWalkListener(JsonSchemaWalkListener propertyWalkListener)
-
addItemWalkListener
public void addItemWalkListener(JsonSchemaWalkListener itemWalkListener)
-
addItemWalkListeners
public void addItemWalkListeners(List<JsonSchemaWalkListener> itemWalkListeners)
-
getPropertyWalkListeners
public List<JsonSchemaWalkListener> getPropertyWalkListeners()
-
getKeywordWalkListenersMap
public Map<String,List<JsonSchemaWalkListener>> getKeywordWalkListenersMap()
-
getArrayItemWalkListeners
public List<JsonSchemaWalkListener> getArrayItemWalkListeners()
-
getExecutionContextCustomizer
public ExecutionContextCustomizer getExecutionContextCustomizer()
-
setExecutionContextCustomizer
public void setExecutionContextCustomizer(ExecutionContextCustomizer executionContextCustomizer)
-
isLosslessNarrowing
public boolean isLosslessNarrowing()
-
setLosslessNarrowing
public void setLosslessNarrowing(boolean losslessNarrowing)
-
isOpenAPI3StyleDiscriminators
public boolean isOpenAPI3StyleDiscriminators()
Indicates whether OpenAPI 3 style discriminators should be supported- Returns:
- true in case discriminators are enabled
- Since:
- 1.0.51
-
setOpenAPI3StyleDiscriminators
public void setOpenAPI3StyleDiscriminators(boolean openAPI3StyleDiscriminators)
When enabled, the validation ofanyOf
andallOf
in polymorphism will respect OpenAPI 3 style discriminators as described in the OpenAPI 3.0.3 spec. The presence of a discriminator configuration on the schema will lead to the following changes in the behavior:- for
oneOf
the spec is unfortunately very vague. WhetheroneOf
semantics should be affected by discriminators or not is not even 100% clear within the members of the OAS steering committee. ThereforeoneOf
at the moment ignores discriminators - for
anyOf
the validation will choose one of the candidate schemas for validation based on the discriminator property value and will pass validation when this specific schema passes. This is in particular useful when the payload could match multiple candidates in theanyOf
list and could lead to ambiguity. Example: type B has all mandatory properties of A and adds more mandatory ones. Whether the payload is an A or B is determined via the discriminator property name. A payload indicating it is an instance of B then requires passing the validation of B and passing the validation of A would not be sufficient anymore. - for
allOf
use cases with discriminators defined on the copied-in parent type, it is possible to automatically validate against a subtype. Example: some schema specifies that there is a field of type A. A carries a discriminator field and B inherits from A. Then B is automatically a candidate for validation as well and will be chosen in case the discriminator property matches
- Parameters:
openAPI3StyleDiscriminators
- whether or not discriminators should be used. Defaults tofalse
- Since:
- 1.0.51
- for
-
setLoadCollectors
public void setLoadCollectors(boolean loadCollectors)
-
doLoadCollectors
public boolean doLoadCollectors()
-
isReadOnly
public boolean isReadOnly()
-
setReadOnly
public void setReadOnly(boolean readOnly)
-
isWriteOnly
public boolean isWriteOnly()
-
setWriteOnly
public void setWriteOnly(boolean writeOnly)
-
isWriteMode
@Deprecated public boolean isWriteMode()
Deprecated.UseisReadOnly
orisWriteOnly
- Returns:
- true if schema is used to write data
-
setPathType
public void setPathType(PathType pathType)
Set the approach used to generate paths in messages, logs and errors (default is PathType.LEGACY).- Parameters:
pathType
- The path generation approach.
-
getPathType
public PathType getPathType()
Get the approach used to generate paths in messages, logs and errors.- Returns:
- The path generation approach.
-
isStrict
public boolean isStrict(String keyword)
Answers whether a keyword's validators may relax their analysis. The default is to perform strict checking. One must explicitly allow a validator to be more permissive.Each validator has its own understanding of what is permissive and strict. Consult the keyword's documentation for details.
- Parameters:
keyword
- the keyword to adjust (not null)- Returns:
- Whether to perform a strict validation.
-
isStrict
public boolean isStrict(String keyword, Boolean defaultValue)
Determines if the validator should perform strict checking.- Parameters:
keyword
- the keyworddefaultValue
- the default value- Returns:
- whether to perform a strict validation
-
setStrict
public void setStrict(String keyword, boolean strict)
Alters the strictness of validations for a specific keyword. When set to true, instructs the keyword's validators to perform strict validation. Otherwise, a validator may perform a more permissive check.- Parameters:
keyword
- The keyword to adjust (not null)strict
- Whether to perform strict validations
-
getLocale
public Locale getLocale()
Get the locale to consider when generating localised messages (default is the JVM default).This locale is on a schema basis and will be used as the default locale for
ExecutionConfig
.- Returns:
- The locale.
-
setLocale
public void setLocale(Locale locale)
Set the locale to consider when generating localised messages.Note that this locale is set on a schema basis. To configure the schema on a per execution basis use
ExecutionConfig.setLocale(Locale)
.- Parameters:
locale
- The locale.
-
getMessageSource
public MessageSource getMessageSource()
Get the message source to use for generating localised messages.- Returns:
- the message source
-
setMessageSource
public void setMessageSource(MessageSource messageSource)
Set the message source to use for generating localised messages.- Parameters:
messageSource
- the message source
-
getFormatAssertionsEnabled
public Boolean getFormatAssertionsEnabled()
Gets the format assertion enabled flag.This defaults to null meaning that it will follow the defaults of the specification.
Since draft 2019-09 this will default to false unless enabled by using the $vocabulary keyword.
- Returns:
- the format assertions enabled flag
-
setFormatAssertionsEnabled
public void setFormatAssertionsEnabled(Boolean formatAssertionsEnabled)
Sets the format assertion enabled flag.- Parameters:
formatAssertionsEnabled
- the format assertions enabled flag
-
getSchemaIdValidator
public JsonSchemaIdValidator getSchemaIdValidator()
Gets the schema id validator to validate $id.- Returns:
- the validator
-
setSchemaIdValidator
public void setSchemaIdValidator(JsonSchemaIdValidator schemaIdValidator)
Sets the schema id validator to validate $id.- Parameters:
schemaIdValidator
- the validator
-
isPreloadJsonSchema
public boolean isPreloadJsonSchema()
Gets if the schema should be preloaded.- Returns:
- true if it should be preloaded
-
setPreloadJsonSchema
public void setPreloadJsonSchema(boolean preloadJsonSchema)
Sets if the schema should be preloaded.- Parameters:
preloadJsonSchema
- true to preload
-
-