Repository navigation
fix(resolver): detect $ref cycles to ancestors of resolved subtrees - #4304
Closed
RobertHebel wants to merge 1 commit into
Closed
RobertHebel wants to merge 1 commit into
RobertHebel wants to merge 1 commit into
Conversation
The OpenAPI 3.1 and 3.2 strategies seeded the dereference lineage with the
pathDiscriminator fragment only, so a $ref from the fragment to one of its
ancestors was not detected as a cycle. A recursive Schema Object such as
Node with children.items { $ref: '#/components/schemas/Node' } overflowed
the stack when resolveSubtree, Swagger UI's resolution path, resolved
['components', 'schemas', 'Node', 'properties'] or
[..., 'properties', 'children'], and returned null for
[..., 'children', 'items']. Seed the lineage with the document root and
every element along the pathDiscriminator, so such a $ref resolves to an
absolute $ref, as cycles do when the whole document is resolved.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
|
Superseded: recreated with commits cherry-picked onto latest main. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The OpenAPI 3.1 and 3.2 ApiDOM strategies seeded the dereference lineage with the
pathDiscriminatorfragment only, so a$reffrom the fragment to one of its ancestors was not detected as a cycle. For a recursive Schema Object, e.g.Nodewithchildren.items: { $ref: '#/components/schemas/Node' },SwaggerClient.resolveSubtree, the path Swagger UI resolves through:RangeError: Maximum call stack size exceededfor['components','schemas','Node','properties']and[…,'properties','children'];nullfor[…,'children','items'].Fix: both strategies seed the lineage with the document root and every element along
pathDiscriminator. Such a$refnow resolves to an absolute$ref(https://…#/components/schemas/Node), as cycles do when the whole document is resolved.Tests:
resolveSubtreeon those paths, on a$refto an ancestor two levels up, andSwaggerClient.resolvewithpathDiscriminator, for 3.1 and 3.2. All of them fail on main. Existing snapshots are unchanged.Found while reviewing the JSON Schema 2020-12 strategy (#4306), which has the same fix for its own strategy.
🤖 Generated with Claude Code