Closed
Description
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
Labels
No labels