Closed peter-ponzel closed 9 months ago
any feedback is welcome :upside_down_face:
@peter-ponzel Good observations. The validation messages could definitely be improved and we have other requests including one to implement the format described in the JSON Schema specification.
I'm currently focused on ensuring complete coverage of the specification so I have not addressed these yet. Pull-requests are welcome.
See #828 #680 #401 #299 and #286
wow - I see .. just hit the tip of the iceberg :sweat_smile:
hello,
this issue has already been raised before → https://github.com/networknt/json-schema-validator/issues/615 unfortunately it was not really solved.
using the following json and json-schema
json.json
```json { "meta": { "label": "2", "tags": [ "A" ], "rating": "RPG" } } ```schema.json
```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 usedresponse using PathType.JSON_POINTER
```json { "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
```json { "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 theValidatorTypeCode
is eitherADDITIONAL_PROPERTIES
orREQUIRED
then the corresponding field can be found inarguments[0]
and is not part of thepath
itself. however - when looking at themessage
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 rfc6901best regards, peter
environement
openjdk 17.0.7 2023-04-18
com.networknt:json-schema-validator:1.0.84