Skip to content

Validator does not comply with JSON Schema validation standards #1133

Closed
@DanNemes

Description

@DanNemes

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/

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions