Array types are not validated if remaining fields of the enclosing object are not ok
Closed this issue · 1 comments
I have a JsonSchema stating my endpoints array is required with "minItems": 1, however, this rule is only validated if the remaining fields of the enclosing assets object are all ok. (In my example the remaining filed is only the codec as required).
Eg.
The validation of the following JSON returns the expected error:
"assets": [
{
"codec": "ABC",
"endpoints": [
]
}
]
error: /properties/assets/items/properties/endpoints" - "array is too short: must have at least 1 elements but instance has 0 elements"
However, the validation of the following JSON only returns an error related to the absent codec field and not the endpoints array.
"assets": [
{
"endpoints": [ ]
}
]
error: /properties/assets/items - object has missing required properties ([\"codec\"])
I'm using com.github.java-json-tools:json-schema-validator:2.2.11
JsonSchema:
...
{
"definitions": {},
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "http://example.com/root.json",
"type": "object",
"required": [
"assets"
],
"properties": {
"assets": {
"type": "array",
"minItems": 1,
"items": {
"type": "object",
"required": [
"codec",
"endpoints",
],
"properties": {
"codec": {
"type": "string",
"pattern": "^(.*)$"
},
"endpoints": {
"type": "array",
"minItems": 1,
"items": {
"type": "object",
"required": [
"origin",
"path"
],
"properties": {
"origin": {
"type": "string",
"pattern": "^(.*)$"
},
"path": {
"type": "string",
"pattern": "^(.*)$"
}
}
}
}
}
}
}
...
Fixed: just called validate(JsonNode instance, boolean deepCheck) with deepCheck=true
/**
* Validate an instance and return a processing report
* @param deepCheck validate children even if container (array, object) is
* invalid
*/
ProcessingReport validate(JsonNode instance, boolean deepCheck)throws ProcessingException;