Skip to content

fix: Report Draft-06/07 sub-schema errors at the property and item path - #967

Merged
DannyvdSluijs merged 1 commit into
jsonrainbow:mainfrom
Roman3349:fix/draft06-07-error-paths
Oct 16, 2026
Merged

DannyvdSluijs merged 1 commit into
jsonrainbow:mainfrom
Roman3349:fix/draft06-07-error-paths

Conversation

@Roman3349

Copy link
Copy Markdown
Contributor

Description

With a Draft-06 or Draft-07 schema, errors from nested properties and array items were reported at the root (pointer: "", property: ""). The properties, patternProperties, items and additionalItems constraints passed the parent's $path to the sub-schema check unchanged instead of appending the property name or item index.

This also made errors disappear: Validator::validate() de-duplicates with array_unique($errors, SORT_REGULAR), so errors that differed only by location were merged into one.

Example schema:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "required": ["bar"],
  "properties": {
    "foo": {"type": "integer"},
    "n": {"type": "object", "properties": {"x": {"type": "integer"}}}
  }
}

Validated against {"foo": "bar", "n": {"x": "y"}}:

Before After
/bar The property bar is required /bar The property bar is required
"" String value found, but integer is required /foo String value found, but integer is required
(missing) /n/x String value found, but integer is required

Changes:

  • Draft-06 and Draft-07 now build the child path the same way Draft 2019-09 does. Draft 2019-09 has done this since it was added in feat: Add Draft-2019-09 #885. The four changed constraints now match their Draft 2019-09 counterparts line for line.
  • additionalItems errors are now reported at the item's index instead of at the array.
  • additionalProperties already reported the correct path (Report additional property errors at the property path #942) and is unchanged.
  • The de-duplication in Validator is unchanged. With correct paths, distinct errors no longer collapse.

Related Issue

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Code refactoring
  • Other (please describe):

Checklist

  • I have read the CONTRIBUTING guidelines
  • My code follows the code style of this project
  • I have added tests that prove my fix is effective or that my feature works
  • All new and existing tests pass
  • I have updated the documentation accordingly
  • My changes generate no new warnings

Additional Notes

  • New ErrorPathTest for Draft-06, Draft-07 and Draft 2019-09. Each covers nested properties, items/additionalItems and patternProperties. The Draft-06 and Draft-07 tests fail without this change. The Draft 2019-09 test guards the existing behaviour.
  • Draft-06/07 errors now carry a real pointer and property instead of empty strings, and previously merged errors are reported separately. This is a bug fix, but code that relied on the old empty paths or the error count will see different output.
  • No documentation change needed.

@github-actions

Copy link
Copy Markdown
Contributor

🎉 You're making a difference! We appreciate your effort and dedication. A reviewer will check it out soon, but in the meantime, give yourself a pat on the back. Keep up the great work! 💪🚀

⭐ Enjoying contributing? Star the project! ⭐ Your contributions help this project grow, and we'd love your support in another way too! If you find this repo helpful, consider leaving a star 🌟 on GitHub.

The properties, patternProperties, items and additionalItems constraints
of Draft-06 and Draft-07 passed the parent path to sub-schema checks
unchanged, so nested errors were reported at the root. Errors that then
differed only by location were also collapsed by the Validator's
de-duplication, dropping them from the result.

Append the property name or item index to the path, as Draft 2019-09
already does.

Signed-off-by: Roman Ondráček <mail@romanondracek.cz>
@DannyvdSluijs

Copy link
Copy Markdown
Collaborator

Thanks @Roman3349 for all the contributions.

@DannyvdSluijs
DannyvdSluijs merged commit 0f920c3 into jsonrainbow:main Oct 16, 2026
18 checks passed
github-actions Bot added a commit that referenced this pull request Oct 16, 2026
@Roman3349
Roman3349 deleted the fix/draft06-07-error-paths branch October 17, 2026 10:30
Roman3349 added a commit to Roman3349/json-schema that referenced this pull request Oct 17, 2026
Bring Draft 2020-12 in line with the changes merged into main since the
branch was created:

- Support unevaluatedProperties (jsonrainbow#931). $dynamicRef is not followed,
  the same way $recursiveRef is not in Draft 2019-09.
- Use EcmaPatternConverter for pattern, patternProperties,
  additionalProperties and unevaluatedProperties (jsonrainbow#943).
- Add error path and ECMA pattern tests (jsonrainbow#967, jsonrainbow#943).
- Drop skip list entries that now pass, including the bignum float
  comparisons fixed by jsonrainbow#982.

Signed-off-by: Roman Ondráček <mail@romanondracek.cz>
Roman3349 added a commit to Roman3349/json-schema that referenced this pull request Oct 24, 2026
Bring Draft 2020-12 in line with the changes merged into main since the
branch was created:

- Support unevaluatedProperties (jsonrainbow#931). $dynamicRef is not followed,
  the same way $recursiveRef is not in Draft 2019-09.
- Use EcmaPatternConverter for pattern, patternProperties,
  additionalProperties and unevaluatedProperties (jsonrainbow#943).
- Add error path and ECMA pattern tests (jsonrainbow#967, jsonrainbow#943).
- Drop skip list entries that now pass, including the bignum float
  comparisons fixed by jsonrainbow#982.

Signed-off-by: Roman Ondráček <mail@romanondracek.cz>
@Roman3349 Roman3349 mentioned this pull request Oct 24, 2026
7 of 12 tasks
Roman3349 added a commit to Roman3349/json-schema that referenced this pull request Oct 24, 2026
Bring Draft 2020-12 in line with the changes merged into main since the
branch was created:

- Support unevaluatedProperties (jsonrainbow#931). $dynamicRef is not followed,
  the same way $recursiveRef is not in Draft 2019-09.
- Use EcmaPatternConverter for pattern, patternProperties,
  additionalProperties and unevaluatedProperties (jsonrainbow#943).
- Add error path and ECMA pattern tests (jsonrainbow#967, jsonrainbow#943).
- Reject a trailing newline in idn-hostname (jsonrainbow#990).
- Drop skip list entries that now pass, including the bignum float
  comparisons fixed by jsonrainbow#982.

Signed-off-by: Roman Ondráček <mail@romanondracek.cz>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants