json-refs icon indicating copy to clipboard operation
json-refs copied to clipboard

Resolution does not work when first level properties contain circular references.

Open tjainesri opened this issue 4 years ago • 1 comments

I have read the 3 cases where the library treats references as circular. As far as I can tell only rule 1 pertains to local references and it makes sense. A/b -> B/c -> C/a is obviously circular but what I am confused about is references at the root level properties? A -> B -> A. Shouldn't these be treated as circular as well?

Here is a simple example to reproduce what I think is an error:

{ "param1": { "$ref": "#/param2" }, "param2": { "$ref": "#/param1" } }

Calling resolveRefs on the object above results in the following resolution result: { "refs": { "#/param1": { "def": { "$ref": "#/param2" }, "uri": "#/param2", "uriDetails": { "path": "", "fragment": "/param2", "reference": "same-document" }, "type": "local", "fqURI": "#/param2", "value": { "$ref": "#/param1" } }, "#/param2": { "def": { "$ref": "#/param1" }, "uri": "#/param1", "uriDetails": { "path": "", "fragment": "/param1", "reference": "same-document" }, "type": "local", "fqURI": "#/param1", "value": { "$ref": "#/param1" } } }, "resolved": { "param1": { "$ref": "#/param1" }, "param2": { "$ref": "#/param1" } } }

Expected behavior: The circular flag for the two references should have been set to true.

tjainesri avatar Jun 14 '20 12:06 tjainesri

This is indeed a bug, I apologize. I agree that the reference details for both should have circular: true.

whitlockjc avatar Jun 16 '20 23:06 whitlockjc