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 not validated against when a $schema is set #160

Closed
tzhoumsm opened this issue Apr 4, 2018 · 1 comment
Closed

$schema not validated against when a $schema is set #160

tzhoumsm opened this issue Apr 4, 2018 · 1 comment

Comments

@tzhoumsm
Copy link

tzhoumsm commented Apr 4, 2018

dateschema.json File:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "date": {
      "type": "string",
      "format": "date"
    }
  }
}

date.json file containing invalid date:

{
  "date": "2017-04-0"
}

Code run against:

        String schemaJson = Resources.toString(Resources.getResource("dateschema.json"), Charsets.UTF_8);
        String resultImpression = Resources.toString(Resources.getResource("date.json"), Charsets.UTF_8);

        JSONObject rawSchema = new JSONObject(new JSONTokener(schemaJson));
        JSONObject eventJson = new JSONObject(resultImpression);

        Schema schema = SchemaLoader.load(rawSchema);

        try {
            schema.validate(eventJson);
        } catch (ValidationException exception) {
            printError(exception, resultImpression);
        }

When debugging I can see that the specVersion is set to DRAFT_7 and the SchemaLoader.class config.specVersion is set to DRAFT_7

The issue is when the Schema line is run, it still validates against DRAFT_4. - the schema in debug mode can be seen to drop the "format":"date".
{"type":"object","properties":{"date":{"type":"string"}}}

When I create a custom SchemaLoader as below with the draftV7Support specified:

SchemaLoader schemaLoader = SchemaLoader.builder().useDefaults(false).schemaJson().draftV7Support().build();
        Schema schema = schemaLoader.load().build();

Then the "format":"date" appears at the Schema line.
{"type":"object","properties":{"date":{"type":"string","format":"date"}}}

What I don't want to do is create a custom schemaLoader like above as that appears to then validate all schemas against draft07?

Am I doing something wrong when specifying: "$schema": "http://json-schema.org/draft-07/schema#" ?

@tzhoumsm tzhoumsm changed the title format 'date' not validated against when $schema is set to draft-07 $schema not validated against when a $schema is set Apr 4, 2018
erosb added a commit that referenced this issue Apr 17, 2018
@erosb
Copy link
Contributor

erosb commented Jun 7, 2018

The fix is available in the latest release: 1.9.0

@erosb erosb closed this as completed Jun 7, 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

2 participants