Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schema validation fails when LoadingConfiguration's caching is disabled when the schema is retrieved from JsonSchemaFactory #281

Open
MysticHLE opened this issue Dec 19, 2018 · 0 comments

Comments

@MysticHLE
Copy link

MysticHLE commented Dec 19, 2018

I'm running into an issue which I believe is a bug in how the ValidationProcessor is constructed from within the JsonSchemaFactory. Full context below:

I'm currently using a custom URIDownloader with the JsonSchemaFactory by attaching it to a scheme via a LoadingConfiguration. I also want to disable the caching aspect of the loader in the factory so that it retrieves from the URIDownloader as updates to the (same) schemas happen over time.

final LoadingConfigurationBuilder loadingConfigBuilder = LoadingConfiguration.newBuilder();
loadingConfigBuilder.addScheme("http", myUriDownloader); 
loadingConfigBuilder.setCacheSize(0); // Disables caching of schema loader in factory

this.schemaFactory = JsonSchemaFactory.newBuilder()
        .setLoadingConfiguration(loadingConfigBuilder.freeze())
        .freeze();

As updates happen to schemas, I can confirm that JsonSchemaFactory.getJsonSchema(...) indeed returns schema objects that reflect said updates (verified under debugger). However, when using said schema objects to do the validation on expectedly proper payloads, it fails as if the updates did not happen.

try {
    JsonSchema jsonSchema = this.schemaFactory.getJsonSchema(schemaId); // <-- Shows the updated schema information when viewed under debugger
    ProcessingReport validationReport = jsonSchema.validate(paylaod); 
    if (!validationReport.isSuccess()) { // <-- This if statement evaluates to true (schema validation FAILED)
        ...
    }
} catch (ProcessingException e) {
   ...
}

Specifically, the updates I'm testing with is by changing the type of the schema (from "string" to "integer," for instance):

From:

{
    "type":"string",
    "$schema":"http://json-schema.org/draft-04/schema#",
    "$id":"http://schema.amazonalexa.com/v1/ups/value/test",
    "description":"test"
}

To:

{
    "type":"integer",
    "$schema":"http://json-schema.org/draft-04/schema#",
    "$id":"http://schema.amazonalexa.com/v1/ups/value/test",
    "description":"test"
}

When stepping through the code of JsonSchema.validate(...) under the debugger, it seems that the ValidationProcessor that is being used has its own cache, which ends up using the wrong validator type (which maps to the old schema type) to do the validation on the new schema type and payload. From looking at the JsonSchemaFactory code, it seems that the ValidationProcessor (which has its own cache) is constructed without accounting for the cache settings from LoadingConfiguration.

@MysticHLE MysticHLE changed the title Schema validation fails when LoadingConfiguration's caching is disabled when the schema is retrieved JsonSchemaFactory Schema validation fails when LoadingConfiguration's caching is disabled when the schema is retrieved from JsonSchemaFactory Dec 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant