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

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

test: A $dynamicRef without anchor in fragment behaves identical to $ref #651

Closed santhosh-tekuri closed 1 year ago

santhosh-tekuri commented 1 year ago

from https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-01#section-8.2.3.2:

If the initially resolved starting point URI includes a fragment that was 
created by the "$dynamicAnchor" keyword, the initial URI MUST be r
eplaced by the URI (including the fragment) for the outermost schema 
resource in the dynamic scope that defines an identically named fragment 
with "$dynamicAnchor"

Otherwise, its behavior is identical to "$ref", and no runtime resolution is needed.

please ensure that my understanding is correct and the test case is valid

karenetheridge commented 1 year ago

My implementation errors on this:

evaluation generated an exception: {
  "error": "EXCEPTION: uri \"https://test.json-schema.org/typical-dynamic-resolution/list\" conflicts with an existing schema resource",
  "instanceLocation": "",
  "keywordLocation": ""
}

Please use a unique identifier for each new resource.

santhosh-tekuri commented 1 year ago

@karenetheridge corrected $id for uniqueness

gregsdennis commented 1 year ago

Do we not already have a test for this? (Not at my computer right now) I seem to recall having something.

gregsdennis commented 1 year ago

Just checking the current suite, we have

These all declare $dynamicAnchor, but they're out of the dynamic scope. I'd say that covers this case, though indirectly.

santhosh-tekuri commented 1 year ago

my impl https://github.com/santhosh-tekuri/boon passes all existing test cases, but it does not pass this test case.

below is the logic in my implementation validator.rs#L567-L574:

  1. find the initial target.
  2. if the initial target has $dynamicAnchor search for override in dynamic scope
  3. otherwise use initial target.

in step 1, it resolves to #/$defs/list/$defs/items from root resource. this initial target has $dynamicAnchor property. so it searches for override in dynamic scope

since my impl does not pass this test, I wanted to confirm whether my understanding of spec is correct or not

jdesrosiers commented 1 year ago

Do we not already have a test for this?

That was my first reaction as well, but I checked and this does appear to be unique. This is the only test that uses a JSON Pointer in a dynamic reference.

gregsdennis commented 1 year ago

This is the only test that uses a JSON Pointer in a dynamic reference. - @jdesrosiers

Should we refocus the test, then? If we're checking its functionality using a pointer, it should be focused on that, not that $dynamicRef behaves like $ref.

jdesrosiers commented 1 year ago

If we're checking its functionality using a pointer, it should be focused on that, not that $dynamicRef behaves like $ref.

The functionality when using a pointer is that $dynamicRef will behave like $ref. I think the test is fine.