Class SchemaValidatorsConfig
- Direct Known Subclasses:
SchemaValidatorsConfig.ImmutableSchemaValidatorsConfig
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Builder forSchemaValidatorsConfig
.static class
SchemaValidatorsConfig
that throws on mutators or deprecated methods. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
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) builder()
builder
(SchemaValidatorsConfig config) Deprecated.Deprecated.Deprecated.boolean
Deprecated.Deprecated.Deprecated.Deprecated.Gets the format assertion enabled flag.Get the locale to consider when generating localised messages (default is the JVM default).Get the message source to use for generating localised messages.Get the approach used to generate paths in messages, logs and errors.int
Gets the max depth of the evaluation path to preload when preloading refs.Gets the regular expression factory.Gets the schema id validator to validate $id.boolean
Gets if schemas loaded from refs will be cached and reused for subsequent runs.boolean
Deprecated.boolean
Gets if the discriminator keyword is enabled.boolean
Gets whether to use a ECMA-262 compliant regular expression validator.boolean
boolean
Deprecated.boolean
boolean
boolean
Gets if the nullable keyword is enabled.boolean
Deprecated.boolean
Gets if the schema should be preloaded.boolean
boolean
Answers whether a keyword's validators may relax their analysis.boolean
Determines if the validator should perform strict checking.boolean
boolean
Deprecated.boolean
Deprecated.boolean
Deprecated.boolean
Deprecated.boolean
Deprecated.boolean
void
setApplyDefaultsStrategy
(ApplyDefaultsStrategy applyDefaultsStrategy) void
setCacheRefs
(boolean cacheRefs) Sets if schemas loaded from refs will be cached and reused for subsequent runs.void
setCustomMessageSupported
(boolean customMessageSupported) Deprecated.void
setEcma262Validator
(boolean ecma262Validator) Sets whether to use a ECMA-262 compliant regular expression validator.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) Deprecated.void
setHandleNullableField
(boolean handleNullableField) void
setJavaSemantics
(boolean javaSemantics) void
setLoadCollectors
(boolean loadCollectors) Deprecated.void
Deprecated.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
setPreloadJsonSchemaRefMaxNestingDepth
(int preloadJsonSchemaRefMaxNestingDepth) Sets the max depth of the evaluation path to preload when preloading refs.void
setReadOnly
(boolean readOnly) void
setRegularExpressionFactory
(RegularExpressionFactory regularExpressionFactory) Sets the regular expression factory.void
setSchemaIdValidator
(JsonSchemaIdValidator schemaIdValidator) Sets the schema id validator to validate $id.void
Alters the strictness of validations for a specific keyword.void
setTypeLoose
(boolean typeLoose) void
setWriteOnly
(boolean writeOnly)
-
Field Details
-
ALL_KEYWORD_WALK_LISTENER_KEY
- See Also:
-
DEFAULT_PRELOAD_JSON_SCHEMA_REF_MAX_NESTING_DEPTH
public static final int DEFAULT_PRELOAD_JSON_SCHEMA_REF_MAX_NESTING_DEPTH- See Also:
-
-
Constructor Details
-
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 Details
-
addItemWalkListener
-
addItemWalkListeners
-
addKeywordWalkListener
-
addKeywordWalkListener
-
addKeywordWalkListeners
-
addKeywordWalkListeners
public void addKeywordWalkListeners(String keyword, List<JsonSchemaWalkListener> keywordWalkListeners) -
addPropertyWalkListener
-
addPropertyWalkListeners
-
getApplyDefaultsStrategy
-
getArrayItemWalkListeners
-
getExecutionContextCustomizer
-
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
-
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
Get the message source to use for generating localised messages.- Returns:
- the message source
-
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
-
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
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. -
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.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.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
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
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
-
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.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
-
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
-
setFormatAssertionsEnabled
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.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
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 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 discriminators should be used. Defaults tofalse
- Since:
- 1.0.51
- for
-
setPathType
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
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:
-
setSchemaIdValidator
Sets the schema id validator to validate $id.- Parameters:
schemaIdValidator
- the validator
-
setStrict
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
-
builder
-
isWriteMode
Deprecated.UseisReadOnly
orisWriteOnly
- Returns:
- true if schema is used to write data
-
setLoadCollectors
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.Gets if collectors are to be loaded.- Returns:
- if collectors are to be loader
-
disableUnevaluatedAnalysis
Deprecated. -
disableUnevaluatedItems
Deprecated. -
disableUnevaluatedProperties
Deprecated. -
enableUnevaluatedAnalysis
Deprecated. -
enableUnevaluatedItems
Deprecated. -
enableUnevaluatedProperties
Deprecated. -
isUnevaluatedItemsAnalysisDisabled
Deprecated. -
isUnevaluatedItemsAnalysisEnabled
Deprecated. -
isUnevaluatedPropertiesAnalysisDisabled
Deprecated. -
isUnevaluatedPropertiesAnalysisEnabled
Deprecated.
-