Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inconsistent path in ValidationMessage #831

Closed
peter-ponzel opened this issue Jun 21, 2023 · 3 comments · Fixed by #942
Closed

inconsistent path in ValidationMessage #831

peter-ponzel opened this issue Jun 21, 2023 · 3 comments · Fixed by #942

Comments

@peter-ponzel
Copy link

peter-ponzel commented Jun 21, 2023

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

@peter-ponzel
Copy link
Author

any feedback is welcome 🙃

@fdutton
Copy link
Contributor

fdutton commented Jul 3, 2023

@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

@peter-ponzel
Copy link
Author

wow - I see .. just hit the tip of the iceberg 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants