Class SchemaValidatorsConfig
- java.lang.Object
-
- com.networknt.schema.SchemaValidatorsConfig
-
- Direct Known Subclasses:
SchemaValidatorsConfig.ImmutableSchemaValidatorsConfig
public class SchemaValidatorsConfig extends Object
Configuration for validators.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSchemaValidatorsConfig.BuilderBuilder forSchemaValidatorsConfig.static classSchemaValidatorsConfig.ImmutableSchemaValidatorsConfigSchemaValidatorsConfigthat throws on mutators or deprecated methods.
-
Field Summary
Fields Modifier and Type Field Description static StringALL_KEYWORD_WALK_LISTENER_KEYstatic intDEFAULT_PRELOAD_JSON_SCHEMA_REF_MAX_NESTING_DEPTH
-
Constructor Summary
Constructors Constructor Description SchemaValidatorsConfig()Deprecated.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddItemWalkListener(JsonSchemaWalkListener itemWalkListener)voidaddItemWalkListeners(List<JsonSchemaWalkListener> itemWalkListeners)voidaddKeywordWalkListener(JsonSchemaWalkListener keywordWalkListener)voidaddKeywordWalkListener(String keyword, JsonSchemaWalkListener keywordWalkListener)voidaddKeywordWalkListeners(String keyword, List<JsonSchemaWalkListener> keywordWalkListeners)voidaddKeywordWalkListeners(List<JsonSchemaWalkListener> keywordWalkListeners)voidaddPropertyWalkListener(JsonSchemaWalkListener propertyWalkListener)voidaddPropertyWalkListeners(List<JsonSchemaWalkListener> propertyWalkListeners)static SchemaValidatorsConfig.Builderbuilder()static SchemaValidatorsConfig.Builderbuilder(SchemaValidatorsConfig config)SchemaValidatorsConfigdisableUnevaluatedAnalysis()Deprecated.SchemaValidatorsConfigdisableUnevaluatedItems()Deprecated.SchemaValidatorsConfigdisableUnevaluatedProperties()Deprecated.booleandoLoadCollectors()Deprecated.SchemaValidatorsConfigenableUnevaluatedAnalysis()Deprecated.SchemaValidatorsConfigenableUnevaluatedItems()Deprecated.SchemaValidatorsConfigenableUnevaluatedProperties()Deprecated.ApplyDefaultsStrategygetApplyDefaultsStrategy()List<JsonSchemaWalkListener>getArrayItemWalkListeners()StringgetErrorMessageKeyword()ExecutionContextCustomizergetExecutionContextCustomizer()BooleangetFormatAssertionsEnabled()Gets the format assertion enabled flag.Map<String,List<JsonSchemaWalkListener>>getKeywordWalkListenersMap()LocalegetLocale()Get the locale to consider when generating localised messages (default is the JVM default).MessageSourcegetMessageSource()Get the message source to use for generating localised messages.PathTypegetPathType()Get the approach used to generate paths in messages, logs and errors.intgetPreloadJsonSchemaRefMaxNestingDepth()Gets the max depth of the evaluation path to preload when preloading refs.List<JsonSchemaWalkListener>getPropertyWalkListeners()RegularExpressionFactorygetRegularExpressionFactory()Gets the regular expression factory.JsonSchemaIdValidatorgetSchemaIdValidator()Gets the schema id validator to validate $id.booleanisCacheRefs()Gets if schemas loaded from refs will be cached and reused for subsequent runs.booleanisCustomMessageSupported()Deprecated.booleanisDiscriminatorKeywordEnabled()Gets if the discriminator keyword is enabled.booleanisEcma262Validator()Gets whether to use a ECMA-262 compliant regular expression validator.booleanisFailFast()booleanisHandleNullableField()Deprecated.booleanisJavaSemantics()booleanisLosslessNarrowing()booleanisNullableKeywordEnabled()Gets if the nullable keyword is enabled.booleanisOpenAPI3StyleDiscriminators()Deprecated.booleanisPreloadJsonSchema()Gets if the schema should be preloaded.booleanisReadOnly()booleanisStrict(String keyword)Answers whether a keyword's validators may relax their analysis.booleanisStrict(String keyword, Boolean defaultValue)Determines if the validator should perform strict checking.booleanisTypeLoose()booleanisUnevaluatedItemsAnalysisDisabled()Deprecated.booleanisUnevaluatedItemsAnalysisEnabled()Deprecated.booleanisUnevaluatedPropertiesAnalysisDisabled()Deprecated.booleanisUnevaluatedPropertiesAnalysisEnabled()Deprecated.booleanisWriteMode()Deprecated.booleanisWriteOnly()voidsetApplyDefaultsStrategy(ApplyDefaultsStrategy applyDefaultsStrategy)voidsetCacheRefs(boolean cacheRefs)Sets if schemas loaded from refs will be cached and reused for subsequent runs.voidsetCustomMessageSupported(boolean customMessageSupported)Deprecated.voidsetEcma262Validator(boolean ecma262Validator)Sets whether to use a ECMA-262 compliant regular expression validator.voidsetExecutionContextCustomizer(ExecutionContextCustomizer executionContextCustomizer)voidsetFailFast(boolean failFast)When enabled,JsonValidator.validate(ExecutionContext, JsonNode, JsonNode, JsonNodePath)doesn't return anySet<ValidationMessage>, instead aJsonSchemaExceptionis thrown as soon as a validation errors is discovered.voidsetFormatAssertionsEnabled(Boolean formatAssertionsEnabled)Deprecated.voidsetHandleNullableField(boolean handleNullableField)voidsetJavaSemantics(boolean javaSemantics)voidsetLoadCollectors(boolean loadCollectors)Deprecated.voidsetLocale(Locale locale)Deprecated.voidsetLosslessNarrowing(boolean losslessNarrowing)voidsetMessageSource(MessageSource messageSource)Set the message source to use for generating localised messages.voidsetOpenAPI3StyleDiscriminators(boolean openAPI3StyleDiscriminators)When enabled, the validation ofanyOfandallOfin polymorphism will respect OpenAPI 3 style discriminators as described in the OpenAPI 3.0.3 spec.voidsetPathType(PathType pathType)Set the approach used to generate paths in messages, logs and errors (default is PathType.LEGACY).voidsetPreloadJsonSchema(boolean preloadJsonSchema)Sets if the schema should be preloaded.voidsetPreloadJsonSchemaRefMaxNestingDepth(int preloadJsonSchemaRefMaxNestingDepth)Sets the max depth of the evaluation path to preload when preloading refs.voidsetReadOnly(boolean readOnly)voidsetRegularExpressionFactory(RegularExpressionFactory regularExpressionFactory)Sets the regular expression factory.voidsetSchemaIdValidator(JsonSchemaIdValidator schemaIdValidator)Sets the schema id validator to validate $id.voidsetStrict(String keyword, boolean strict)Alters the strictness of validations for a specific keyword.voidsetTypeLoose(boolean typeLoose)voidsetWriteOnly(boolean writeOnly)
-
-
-
Field Detail
-
ALL_KEYWORD_WALK_LISTENER_KEY
public static final String ALL_KEYWORD_WALK_LISTENER_KEY
- See Also:
- Constant Field Values
-
DEFAULT_PRELOAD_JSON_SCHEMA_REF_MAX_NESTING_DEPTH
public static final int DEFAULT_PRELOAD_JSON_SCHEMA_REF_MAX_NESTING_DEPTH
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
SchemaValidatorsConfig
@Deprecated public SchemaValidatorsConfig()
Deprecated.Constructor to create an instance.This is deprecated in favor of using the builder
builder()to create an instance. Migration note: The builder has different defaults from the constructor.SchemaValidatorsConfig config = SchemaValidatorsConfig.builder() .pathType(PathType.LEGACY) .errorMessageKeyword("message") .nullableKeywordEnabled(true) .build();- customMessageSupported (errorMessageKeyword): change from message to null
- pathType: changed from PathType.LEGACY to PathType.JSON_POINTER.
- handleNullableField (nullableKeywordEnabled): changed from true to false
-
-
Method Detail
-
addItemWalkListener
public void addItemWalkListener(JsonSchemaWalkListener itemWalkListener)
-
addItemWalkListeners
public void addItemWalkListeners(List<JsonSchemaWalkListener> itemWalkListeners)
-
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)
-
addPropertyWalkListener
public void addPropertyWalkListener(JsonSchemaWalkListener propertyWalkListener)
-
addPropertyWalkListeners
public void addPropertyWalkListeners(List<JsonSchemaWalkListener> propertyWalkListeners)
-
getApplyDefaultsStrategy
public ApplyDefaultsStrategy getApplyDefaultsStrategy()
-
getArrayItemWalkListeners
public List<JsonSchemaWalkListener> getArrayItemWalkListeners()
-
getExecutionContextCustomizer
public ExecutionContextCustomizer getExecutionContextCustomizer()
-
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
-
getKeywordWalkListenersMap
public Map<String,List<JsonSchemaWalkListener>> getKeywordWalkListenersMap()
-
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.
-
getMessageSource
public MessageSource getMessageSource()
Get the message source to use for generating localised messages.- Returns:
- the message source
-
getPathType
public PathType getPathType()
Get the approach used to generate paths in messages, logs and errors.- Returns:
- The path generation approach.
-
getPreloadJsonSchemaRefMaxNestingDepth
public int getPreloadJsonSchemaRefMaxNestingDepth()
Gets the max depth of the evaluation path to preload when preloading refs.- Returns:
- the max depth to preload
-
getPropertyWalkListeners
public List<JsonSchemaWalkListener> getPropertyWalkListeners()
-
getRegularExpressionFactory
public RegularExpressionFactory getRegularExpressionFactory()
Gets the regular expression factory.This defaults to the JDKRegularExpressionFactory and the implementations require inclusion of optional org.jruby.joni:joni or org.graalvm.js:js dependencies.
- Returns:
- the factory
-
getSchemaIdValidator
public JsonSchemaIdValidator getSchemaIdValidator()
Gets the schema id validator to validate $id.- Returns:
- the validator
-
isCacheRefs
public boolean isCacheRefs()
Gets if schemas loaded from refs will be cached and reused for subsequent runs.- Returns:
- true if schemas loaded from refs should be cached
-
isCustomMessageSupported
@Deprecated public boolean isCustomMessageSupported()
Deprecated.
-
getErrorMessageKeyword
public String getErrorMessageKeyword()
-
isEcma262Validator
public boolean isEcma262Validator()
Gets whether to use a ECMA-262 compliant regular expression validator.This defaults to the false and setting true require inclusion of optional org.jruby.joni:joni or org.graalvm.js:js dependencies.
- Returns:
- true if ECMA-262 compliant
-
isFailFast
public boolean isFailFast()
-
isHandleNullableField
@Deprecated public boolean isHandleNullableField()
Deprecated.Deprecated use {isNullableKeywordEnabled()instead.- Returns:
- true if the nullable keyword is enabled
-
isNullableKeywordEnabled
public boolean isNullableKeywordEnabled()
Gets if the nullable keyword is enabled.- Returns:
- true if the nullable keyword is enabled
-
isJavaSemantics
public boolean isJavaSemantics()
-
isLosslessNarrowing
public boolean isLosslessNarrowing()
-
isOpenAPI3StyleDiscriminators
@Deprecated public boolean isOpenAPI3StyleDiscriminators()
Deprecated.Indicates whether OpenAPI 3 style discriminators should be supportedDeprecated use {
isDiscriminatorKeywordEnabled()instead.- Returns:
- true in case discriminators are enabled
- Since:
- 1.0.51
-
isDiscriminatorKeywordEnabled
public boolean isDiscriminatorKeywordEnabled()
Gets if the discriminator keyword is enabled.- Returns:
- true if the discriminator keyword is enabled
-
isPreloadJsonSchema
public boolean isPreloadJsonSchema()
Gets if the schema should be preloaded.- Returns:
- true if it should be preloaded
-
isReadOnly
public boolean isReadOnly()
-
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
-
isTypeLoose
public boolean isTypeLoose()
- Returns:
- true if type loose is used.
-
isWriteOnly
public boolean isWriteOnly()
-
setApplyDefaultsStrategy
public void setApplyDefaultsStrategy(ApplyDefaultsStrategy applyDefaultsStrategy)
-
setCacheRefs
public void setCacheRefs(boolean cacheRefs)
Sets if schemas loaded from refs will be cached and reused for subsequent runs.Note that setting this to false will affect performance as refs will need to be repeatedly resolved for each evaluation run. It may be needed to be set to false if there are multiple nested applicators like anyOf, oneOf and allOf as that will consume a lot of memory to cache all the permutations.
- Parameters:
cacheRefs- true to cache
-
setCustomMessageSupported
@Deprecated public void setCustomMessageSupported(boolean customMessageSupported)
Deprecated.Sets whether custom error messages in the schema are used.This is deprecated in favor of setting the error message keyword to use.
- Parameters:
customMessageSupported- true to use message as the error message keyword
-
setEcma262Validator
public void setEcma262Validator(boolean ecma262Validator)
Sets whether to use a ECMA-262 compliant regular expression validator.This defaults to the false and setting true require inclusion of optional org.jruby.joni:joni or org.graalvm.js:js dependencies.
- Parameters:
ecma262Validator- true if ECMA-262 compliant
-
setExecutionContextCustomizer
public void setExecutionContextCustomizer(ExecutionContextCustomizer executionContextCustomizer)
-
setFailFast
public void setFailFast(boolean failFast)
When enabled,JsonValidator.validate(ExecutionContext, JsonNode, JsonNode, JsonNodePath)doesn't return anySet<ValidationMessage>, instead aJsonSchemaExceptionis thrown as soon as a validation errors is discovered.- Parameters:
failFast- boolean
-
setFormatAssertionsEnabled
@Deprecated public void setFormatAssertionsEnabled(Boolean formatAssertionsEnabled)
Deprecated.Sets the format assertion enabled flag.This is deprecated. Either set this using the builder SchemaValidatorsConfig.builder().formatAssertionsEnabled(true).build() or this should be set via executionContext.getExecutionConfig().setFormatAssertionsEnabled(true).
- Parameters:
formatAssertionsEnabled- the format assertions enabled flag
-
setHandleNullableField
public void setHandleNullableField(boolean handleNullableField)
-
setJavaSemantics
public void setJavaSemantics(boolean javaSemantics)
-
setLocale
@Deprecated public void setLocale(Locale locale)
Deprecated.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).This is deprecated. Either set this using the builder SchemaValidatorsConfig.builder().locale(locale).build() or this should be set via executionContext.getExecutionConfig().setLocale(locale).
- Parameters:
locale- The locale.
-
setLosslessNarrowing
public void setLosslessNarrowing(boolean losslessNarrowing)
-
setMessageSource
public void setMessageSource(MessageSource messageSource)
Set the message source to use for generating localised messages.- Parameters:
messageSource- the message source
-
setOpenAPI3StyleDiscriminators
public void setOpenAPI3StyleDiscriminators(boolean openAPI3StyleDiscriminators)
When enabled, the validation ofanyOfandallOfin 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
oneOfthe spec is unfortunately very vague. WhetheroneOfsemantics should be affected by discriminators or not is not even 100% clear within the members of the OAS steering committee. ThereforeoneOfat the moment ignores discriminators - for
anyOfthe 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 theanyOflist 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
allOfuse 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
-
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.
-
setPreloadJsonSchema
public void setPreloadJsonSchema(boolean preloadJsonSchema)
Sets if the schema should be preloaded.- Parameters:
preloadJsonSchema- true to preload
-
setPreloadJsonSchemaRefMaxNestingDepth
public void setPreloadJsonSchemaRefMaxNestingDepth(int preloadJsonSchemaRefMaxNestingDepth)
Sets the max depth of the evaluation path to preload when preloading refs.- Parameters:
preloadJsonSchemaRefMaxNestingDepth- the max depth to preload
-
setReadOnly
public void setReadOnly(boolean readOnly)
-
setRegularExpressionFactory
public void setRegularExpressionFactory(RegularExpressionFactory regularExpressionFactory)
Sets the regular expression factory.This defaults to the JDKRegularExpressionFactory and the implementations require inclusion of optional org.jruby.joni:joni or org.graalvm.js:js dependencies.
- Parameters:
regularExpressionFactory- the factory- See Also:
JDKRegularExpressionFactory,ECMAScriptRegularExpressionFactory
-
setSchemaIdValidator
public void setSchemaIdValidator(JsonSchemaIdValidator schemaIdValidator)
Sets the schema id validator to validate $id.- Parameters:
schemaIdValidator- the validator
-
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
-
setTypeLoose
public void setTypeLoose(boolean typeLoose)
-
setWriteOnly
public void setWriteOnly(boolean writeOnly)
-
builder
public static SchemaValidatorsConfig.Builder builder()
-
builder
public static SchemaValidatorsConfig.Builder builder(SchemaValidatorsConfig config)
-
isWriteMode
@Deprecated public boolean isWriteMode()
Deprecated.UseisReadOnlyorisWriteOnly- Returns:
- true if schema is used to write data
-
setLoadCollectors
@Deprecated public void setLoadCollectors(boolean loadCollectors)
Deprecated.Sets if collectors are to be loaded.This is deprecated in favor of the caller calling
CollectorContext.loadCollectors()manually.- Parameters:
loadCollectors- to load collectors
-
doLoadCollectors
@Deprecated public boolean doLoadCollectors()
Deprecated.Gets if collectors are to be loaded.- Returns:
- if collectors are to be loader
-
disableUnevaluatedAnalysis
@Deprecated public SchemaValidatorsConfig disableUnevaluatedAnalysis()
Deprecated.
-
disableUnevaluatedItems
@Deprecated public SchemaValidatorsConfig disableUnevaluatedItems()
Deprecated.
-
disableUnevaluatedProperties
@Deprecated public SchemaValidatorsConfig disableUnevaluatedProperties()
Deprecated.
-
enableUnevaluatedAnalysis
@Deprecated public SchemaValidatorsConfig enableUnevaluatedAnalysis()
Deprecated.
-
enableUnevaluatedItems
@Deprecated public SchemaValidatorsConfig enableUnevaluatedItems()
Deprecated.
-
enableUnevaluatedProperties
@Deprecated public SchemaValidatorsConfig enableUnevaluatedProperties()
Deprecated.
-
isUnevaluatedItemsAnalysisDisabled
@Deprecated public boolean isUnevaluatedItemsAnalysisDisabled()
Deprecated.
-
isUnevaluatedItemsAnalysisEnabled
@Deprecated public boolean isUnevaluatedItemsAnalysisEnabled()
Deprecated.
-
isUnevaluatedPropertiesAnalysisDisabled
@Deprecated public boolean isUnevaluatedPropertiesAnalysisDisabled()
Deprecated.
-
isUnevaluatedPropertiesAnalysisEnabled
@Deprecated public boolean isUnevaluatedPropertiesAnalysisEnabled()
Deprecated.
-
-