Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infinite recursion when referencing self #608

Open
romancow opened this issue Jul 12, 2023 · 0 comments · May be fixed by #717
Open

Infinite recursion when referencing self #608

romancow opened this issue Jul 12, 2023 · 0 comments · May be fixed by #717

Comments

@romancow
Copy link

Describe the bug
Infinite recursion when a reference references itself.

To Reproduce
Steps to reproduce the behavior:
Attempt to dereference the following schema:

{
  "definitions": {
    "node": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        },
        "children": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/node"
          }
        }
      }
    }
  },
  "type": "object",
  "properties": {
    "tree": {
      "title": "Recursive references",
      "$ref": "#/definitions/node"
    }
  }
}

Expected behavior
For the library to detect/handle the self reference and deference appropriately.

Desktop (please complete the following information):

  • OS: macos
  • Browser: Chrome
  • Version: 114

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
From looking at the code, I think the issue lies around https://github.com/json-schema-tools/dereferencer/blob/master/src/dereferencer.ts#L168

It's creating the sub-dereferencer, passing in the current refCache before the current ref is added. This sub-dereferencer then attempts to dereference the same ref (not finding it in the cache), and so on ad infinitum. Perhaps fetched could be added to refCache before creating subDereffer?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant