Description
hello,
this issue has already been raised before → #615 unfortunately it was not really solved.
using the following json and json-schema
json.json
{
"meta": {
"label": "2",
"tags": [ "A" ],
"rating": "RPG"
}
}
schema.json
{
"$id": "http://localhost:8080/schemas/schema.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"required": [
"meta"
],
"properties": {
"meta": {
"type": "object",
"required": [
"label",
"tags",
"rating",
"officialRating"
],
"properties": {
"label": {
"type": "string",
"minLength": 2
},
"tags": {
"type": "array",
"uniqueItems": true,
"items": {
"type": "string",
"enum": [
"action",
"comedy",
"drama",
"fantasy"
]
}
},
"rating": {
"$ref": "#/definitions/rating"
},
"officialRating": {
"$ref": "#/definitions/rating"
}
}
}
},
"definitions": {
"rating": {
"type": "string",
"enum": [
"R",
"PG-13",
"PG",
"G"
]
}
}
}
will give the following results - depending on which PathType
is used
response using PathType.JSON_POINTER
{
"validationMessages": [
{
"schemaPath": "#/properties/meta/required",
"message": "/meta.officialRating: is missing but it is required",
"path": "/meta",
"arguments[0]": "officialRating"
},
{
"schemaPath": "#/definitions/rating/enum",
"message": "/meta/rating: does not have a value in the enumeration [R, PG-13, PG, G]",
"path": "/meta/rating",
"arguments[0]": null
},
{
"schemaPath": "#/properties/meta/properties/label/minLength",
"message": "/meta/label: must be at least 2 characters long",
"path": "/meta/label",
"arguments[0]": null
},
{
"schemaPath": "#/properties/meta/properties/tags/items/enum",
"message": "/meta/tags/0: does not have a value in the enumeration [action, comedy, drama, fantasy]",
"path": "/meta/tags/0",
"arguments[0]": null
}
]
}
response using PathType.JSON_PATH or PathType.JSON_LEGACY
{
"validationMessages": [
{
"schemaPath": "#/properties/meta/required",
"message": "$.meta.officialRating: is missing but it is required",
"path": "$.meta",
"arguments[0]": "officialRating"
},
{
"schemaPath": "#/definitions/rating/enum",
"message": "$.meta.rating: does not have a value in the enumeration [R, PG-13, PG, G]",
"path": "$.meta.rating",
"arguments[0]": null
},
{
"schemaPath": "#/properties/meta/properties/label/minLength",
"message": "$.meta.label: must be at least 2 characters long",
"path": "$.meta.label",
"arguments[0]": null
},
{
"schemaPath": "#/properties/meta/properties/tags/items/enum",
"message": "$.meta.tags[0]: does not have a value in the enumeration [action, comedy, drama, fantasy]",
"path": "$.meta.tags[0]",
"arguments[0]": null
}
]
}
in some cases path
points to the expected error field - but for instance when the ValidatorTypeCode
is either ADDITIONAL_PROPERTIES
or REQUIRED
then the corresponding field can be found in arguments[0]
and is not part of the path
itself.
however - when looking at the message
it does look like it's always "pointing" to the expected error field .
is there any way to get the "full path" - other than parsing the message
?
on that note - could it be that this /meta.officialRating
is not intended ?
couldn't find anything regarding dots in json pointer, see rfc6901
best regards,
peter
environement
openjdk 17.0.7 2023-04-18
com.networknt:json-schema-validator:1.0.84