fix: recursion detection to allow same resolved $ref in different branches#1241
fix: recursion detection to allow same resolved $ref in different branches#1241catosaurusrex2003 wants to merge 5 commits intoasyncapi:masterfrom
Conversation
|
|
@magicmatatjahu @fmvilas @AceTheCreator not a big PR, any chance to review and merge it? |
|
@magicmatatjahu @fmvilas @AceTheCreator any updates? |
|
Would also like to see this merged, @catosaurusrex2003 are you able to rebase as there are some conflicts with the base branch. Are the changes in the playground necessary (tsconfig / package.json) for this change, or were they just for testing purposes? I would probably advise squashing into a single commit and use conventional commit notation in your message |
… into fixes-in-recursion-detection-logic
|
AceTheCreator
left a comment
There was a problem hiding this comment.
Hey @catosaurusrex2003, just a small perf improvement.
I like the idea of creating a new path copy for each branch instead of sharing a global set. What if, during the recursion, we clean up after? currently the clone copies the entire Set at every level. For every tree N levels deep, that's O(N²) work just for tracking.
|
Nice suggestion |



The Problem
The recursion detection algorithm incorrectly throws "too much recursion" errors when the same external
$refappears in multiple branches (e.g. in the schema provided in #1236c1andc2both referencing the same external component).This happens because the algorithm used a global
WeakSetthat flagged any object seen before, even if it was in a different branch.Solution
Replaced global
WeakSettracking with path-based tracking usingSet<object>. Each branch now gets its own copy of the path, allowing the same object to appear in different branches while still detecting true circular references.Key Changes
WeakSet→Set<object>to enable path copyingvisited→visitedInPathfor clarityRelated issue(s)
#1236