supabase / pg_jsonschema

PostgreSQL extension providing JSON Schema validation
Apache License 2.0
1.03k stars 30 forks source link

Error message too unspecific #55

Closed egze closed 6 months ago

egze commented 6 months ago

Bug report

The validation error messages are too unspecific. It would help to know the path to the field that has errors.

Describe the bug

Example query

SELECT jsonschema_validation_errors(
            '{
                "type": "object",
                "properties": {
                    "tags": {
                        "type": "array",
                        "items": {
                            "type": "string",
                            "maxLength": 16
                        }
                    }
                }
            }'::json,
            '{"tags": [1,2,3]}'
        )

produces the error message

{"1 is not of type \"string\"","2 is not of type \"string\"","3 is not of type \"string\""}

It would be great to see a json-path to the field. Something like so:

{
  "$.tags[0]": "1 is not of type \"string\",
  "$.tags[1]": "2 is not of type \"string\",
  "$.tags[2]": "3 is not of type \"string\",
}

Otherwise the error message if not actionable.

olirice commented 6 months ago

pg_jsonschema is a very light weight wrapper around jsonschema-rs. This project bubbles up error messages from that underlying library so I'd recommend opening this on the jsonschema-rs issue tracker if you have thoughts on how he error messages could be improved