json-schema-org / JSON-Schema-Test-Suite

A language agnostic test suite for the JSON Schema specifications
MIT License
615 stars 205 forks source link

Clarification Needed on Handling Duplicate `anchor` Definitions Across JSON Schema Tests #744

Closed kaptinlin closed 5 months ago

kaptinlin commented 5 months ago

Description: There seems to be a discrepancy in how duplicate $anchor definitions are handled across different tests in the JSON Schema Test Suite. Specifically, the tests present conflicting interpretations of whether a subsequent $anchor with the same name should override an earlier definition or whether the first occurrence should be retained.

Relevant Test Files and Observations:

  1. Ref Test (ref.json#L632) - In this test, when $anchor is defined multiple times, the reference points to the first occurrence of the $anchor.

  2. Anchor Test (anchor.json#L84) - This test appears to indicate that the latest $anchor definition overrides earlier ones.

Concern: The handling of duplicate $anchor names varies between tests, which may lead to inconsistent behavior in schema processing across different implementations. This inconsistency could impact the predictability and reliability of JSON Schema validation.

Questions and Suggested Actions:

Thank you for considering this issue. Addressing this ambiguity will help in enhancing the robustness and interoperability of JSON Schema implementations and tools.

gregsdennis commented 5 months ago

In both of the tests you reference, one of the $anchor keywords has a different base URI, provided by an adjacent $id keyword.

These aren't duplicate anchors, just same-named anchors in different resources.

gregsdennis commented 5 months ago

Truly duplicate $anchors should ("MAY") be an error.

At the end of Core 8.2.2:

The effect of specifying the same fragment name multiple times within the same resource, using any combination of "$anchor" and/or "$dynamicAnchor", is undefined. Implementations MAY raise an error if such usage is detected.

kaptinlin commented 5 months ago

thanks