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

Validator does not comply with JSON Schema validation standards #1133

Closed
DanNemes opened this issue Nov 24, 2024 · 0 comments · Fixed by #1134
Closed

Validator does not comply with JSON Schema validation standards #1133

DanNemes opened this issue Nov 24, 2024 · 0 comments · Fixed by #1134

Comments

@DanNemes
Copy link

DanNemes commented Nov 24, 2024

Given this schema:

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

This input:

{
  "test":{
      "nested":null
  }
}

And this java snippet

final JsonNode jsonNodeSchema = ObjectMapperUtil.readTree(SCHEMA);
final JsonSchemaFactory factory = JsonSchemaFactory.getInstance(SpecVersionDetector.detect(jsonNodeSchema));
final JsonSchema validator = factory.getSchema(jsonNodeSchema, SchemaValidatorsConfig.builder()
    .nullableKeywordEnabled(false)
    .build());

final JsonNode jsonNodeFromString = ObjectMapperUtil.readTree(DATA);
final Set<ValidationMessage> errors = validator.validate(jsonNodeFromString);
if (!errors.isEmpty()) {
    throw new RuntimeException(errors.toString());
}

Expectation:
An error message to always be shown, irrespective of 'nullable': "/test/nested: null found, string expected"
This is because in the json schema specification the 'nullable' keyword does not exist and setting it to either true/false should have no effect on the validation.

Actual result:
setting the 'nullable' flag in the schema to true: no error message
setting the 'nullable' flag in the schema to false: error message shown "/test/nested: null found, string expected"

Using the same json schema and input on the following site would yield the correct error:
https://www.jsonschemavalidator.net/

@DanNemes DanNemes changed the title Validator not respecting json schema validation Specification standard Validator does not comply with JSON Schema validation standards Nov 25, 2024
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

Successfully merging a pull request may close this issue.

1 participant