Class SchemaValidatorsConfig

    • Field Detail

      • ALL_KEYWORD_WALK_LISTENER_KEY

        public static final java.lang.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
      • applyDefaultsStrategy

        private ApplyDefaultsStrategy applyDefaultsStrategy
        The strategy the walker uses to sets nodes that are missing or NullNode to the default value, if any, and mutate the input json.
      • cacheRefs

        private boolean cacheRefs
        Controls if schemas loaded from refs will be cached and reused for subsequent runs.
      • errorMessageKeyword

        private java.lang.String errorMessageKeyword
        When set to true, "messages" provided in schema are used for forming validation errors else default messages are used
      • failFast

        private boolean failFast
        When set to true, validator process is stop immediately when a very first validation error is discovered.
      • formatAssertionsEnabled

        private java.lang.Boolean formatAssertionsEnabled
        Since Draft 2019-09 format assertions are not enabled by default.
      • nullableKeywordEnabled

        private boolean nullableKeywordEnabled
        When a field is set as nullable in the OpenAPI specification, the schema validator validates that it is nullable however continues with validation against the nullable field

        If handleNullableField is set to true && incoming field is nullable && value is field: null --> succeed If handleNullableField is set to false && incoming field is nullable && value is field: null --> it is up to the type validator using the SchemaValidator to handle it.

      • javaSemantics

        private boolean javaSemantics
        When set to true, use Java-specific semantics rather than native JavaScript semantics
      • keywordWalkListenersMap

        private final java.util.Map<java.lang.String,​java.util.List<JsonSchemaWalkListener>> keywordWalkListenersMap
      • locale

        private java.util.Locale locale
        The Locale to consider when loading validation messages from the default resource bundle.
      • losslessNarrowing

        private boolean losslessNarrowing
        When set to true, can interpret round doubles as integers
      • messageSource

        private MessageSource messageSource
        The message source to use for generating localised messages.
      • discriminatorKeywordEnabled

        private boolean discriminatorKeywordEnabled
        When set to true, support for discriminators is enabled for validations of oneOf, anyOf and allOf as described on GitHub.
      • pathType

        private PathType pathType
        The approach used to generate paths in reported messages, logs and errors. Default is the legacy "JSONPath-like" approach.
      • preloadJsonSchema

        private boolean preloadJsonSchema
        Controls if the schema will automatically be preloaded.
      • preloadJsonSchemaRefMaxNestingDepth

        private int preloadJsonSchemaRefMaxNestingDepth
        Controls the max depth of the evaluation path to preload when preloading refs.
      • readOnly

        private java.lang.Boolean readOnly
        When set to true assumes that schema is used to validate incoming data from an API.
      • schemaIdValidator

        private JsonSchemaIdValidator schemaIdValidator
        Used to validate the acceptable $id values.
      • strictness

        private final java.util.Map<java.lang.String,​java.lang.Boolean> strictness
        Contains a mapping of how strict a keyword's validators should be. Defaults to true.

        Each validator has its own understanding of what constitutes strict and permissive.

      • typeLoose

        private boolean typeLoose
        when validate type, if TYPE_LOOSE = true, will try to convert string to different types to match the type defined in schema.
      • writeOnly

        private java.lang.Boolean writeOnly
        When set to true assumes that schema is used to to validate outgoing data from an API.
      • loadCollectors

        @Deprecated
        private boolean loadCollectors
        Deprecated.
    • 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
      • SchemaValidatorsConfig

        SchemaValidatorsConfig​(ApplyDefaultsStrategy applyDefaultsStrategy,
                               boolean cacheRefs,
                               java.lang.String errorMessageKeyword,
                               ExecutionContextCustomizer executionContextCustomizer,
                               boolean failFast,
                               java.lang.Boolean formatAssertionsEnabled,
                               boolean nullableKeywordEnabled,
                               java.util.List<JsonSchemaWalkListener> itemWalkListeners,
                               boolean javaSemantics,
                               java.util.Map<java.lang.String,​java.util.List<JsonSchemaWalkListener>> keywordWalkListenersMap,
                               java.util.Locale locale,
                               boolean losslessNarrowing,
                               MessageSource messageSource,
                               boolean discriminatorKeywordEnabled,
                               PathType pathType,
                               boolean preloadJsonSchema,
                               int preloadJsonSchemaRefMaxNestingDepth,
                               java.util.List<JsonSchemaWalkListener> propertyWalkListeners,
                               java.lang.Boolean readOnly,
                               RegularExpressionFactory regularExpressionFactory,
                               JsonSchemaIdValidator schemaIdValidator,
                               java.util.Map<java.lang.String,​java.lang.Boolean> strictness,
                               boolean typeLoose,
                               java.lang.Boolean writeOnly)
    • Method Detail

      • addItemWalkListeners

        public void addItemWalkListeners​(java.util.List<JsonSchemaWalkListener> itemWalkListeners)
      • addKeywordWalkListener

        public void addKeywordWalkListener​(java.lang.String keyword,
                                           JsonSchemaWalkListener keywordWalkListener)
      • addKeywordWalkListeners

        public void addKeywordWalkListeners​(java.util.List<JsonSchemaWalkListener> keywordWalkListeners)
      • addKeywordWalkListeners

        public void addKeywordWalkListeners​(java.lang.String keyword,
                                            java.util.List<JsonSchemaWalkListener> keywordWalkListeners)
      • addPropertyWalkListener

        public void addPropertyWalkListener​(JsonSchemaWalkListener propertyWalkListener)
      • addPropertyWalkListeners

        public void addPropertyWalkListeners​(java.util.List<JsonSchemaWalkListener> propertyWalkListeners)
      • getFormatAssertionsEnabled

        public java.lang.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 java.util.Map<java.lang.String,​java.util.List<JsonSchemaWalkListener>> getKeywordWalkListenersMap()
      • getLocale

        public java.util.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
      • 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 java.lang.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 supported

        Deprecated 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​(java.lang.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​(java.lang.String keyword,
                                java.lang.Boolean defaultValue)
        Determines if the validator should perform strict checking.
        Parameters:
        keyword - the keyword
        defaultValue - 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)
      • setFormatAssertionsEnabled

        @Deprecated
        public void setFormatAssertionsEnabled​(java.lang.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​(java.util.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 of anyOf and allOf 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. Whether oneOf semantics should be affected by discriminators or not is not even 100% clear within the members of the OAS steering committee. Therefore oneOf 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 the anyOf 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 to false
        Since:
        1.0.51
      • 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​(java.lang.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)
      • isWriteMode

        @Deprecated
        public boolean isWriteMode()
        Deprecated.
        Use isReadOnly or isWriteOnly
        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.
      • disableUnevaluatedProperties

        @Deprecated
        public SchemaValidatorsConfig disableUnevaluatedProperties()
        Deprecated.
      • enableUnevaluatedAnalysis

        @Deprecated
        public SchemaValidatorsConfig enableUnevaluatedAnalysis()
        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.