JSON-Schema-Test-Suite icon indicating copy to clipboard operation
JSON-Schema-Test-Suite copied to clipboard

Test for jumping over a resource

Open gregsdennis opened this issue 1 year ago • 16 comments
trafficstars

Inspired by an example in @jviotti's blog post on dynamic scope, I wondered how different implementations would handle a reference that targeted a resource embedded in another resource and dynamic references were involved.

Example:

{
  "$id": "https://example.com/foo",
  "type": "object",
  "properties": {
    "bar-item": { "$ref": "item" }
  },
  "$defs": {
    "bar": {
      "$id": "https://example.com/bar",
      "type": "array",
      "items": { "$ref": "item" },
      "$defs": {
        "item": {
          "$id": "item",
          "type": "object",
          "properties": {
            "content": { "$dynamicRef": "#content" }
          },
          "$defs": {
            "defaultContent": {
              "$dynamicAnchor": "content",
              "type": "integer"
            }
          }
        },
        "content": {
          "$dynamicAnchor": "content",
          "type": "string"
        }
      }
    }
  }
}

I see two possibilities here:

  • an implementation includes bar in the dynamic scope and resolves the $dynamicRef to /$defs/bar/$defs/content.
  • an implementation excludes bar from the dynamic scope and resolves the $dynamicRef to /$defs/bar/$defs/item/$defs/defaultContent.

Visually analyzing it, I think the latter is the correct approach, meaning that

{ "bar-item": { "content": 42 } }

is valid, and

{ "bar-item": { "content": "value" } }

is invalid.

This is also how my implementation behaves. I'd like to see how others handle it.

gregsdennis avatar Feb 09 '24 22:02 gregsdennis