-
-
Notifications
You must be signed in to change notification settings - Fork 4
Description
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
?