fix: do not run nested visitors with a stale parent on shared $refs - #3038
fix: do not run nested visitors with a stale parent on shared $refs#3038vadyvas wants to merge 3 commits into
Conversation
🦋 Changeset detectedLatest commit: 394cd16 The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
@cursor review |
Coverage Report
File Coverage
|
||||||||||||||||||||||||||||||||||||||
Performance Benchmark (Lower is Faster)
|
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 5467388. Configure here.
| } | ||
| } | ||
|
|
||
| walkingNodeByType[type.name] = prevWalkingNode; |
There was a problem hiding this comment.
this keeps track of the node we are currently inside
without the restore, after we leave a child and move to a sibling, the map would still say we are inside that child and the check below would wrongly skip visitors
b4d4615 to
394cd16
Compare
|
📦 A new experimental 🧪 version v0.0.0-snapshot.1787819613 of Redocly CLI has been published for testing. Install with NPM: npm install @redocly/cli@0.0.0-snapshot.1787819613 |
What/Why/How?
operation-parameters-uniquereported a duplicate parameter that is not there. It happens when the same path item is reused through$ref, for example from two callbacks, and the reported location points at an operation that has noparametersat all.The reason is in the walker. Two
$refs to the same path item resolve to one object, so the walker enters it twice. On the second entry it does not call the rule'senterhooks again, because it already called them for that node — but it still calls the rule's nestedParametervisitor. So the visitor runs with the state and the parent location left over from the first entry, and reports a parameter it had already counted.Added a guard: a nested visitor now runs only if the node its parent hook sits on is the node the walker is really inside. On the second entry the
Parametervisitor stays quiet, and the rule reports only what it actually saw.operation-parameters-uniqueis not the only rule with this shape —spec-querystring-parametershad the same problem.Reference
Closes #2829
Testing
Screenshots (optional)
x-signatureis declared once, in one list:Before:
After:
Check yourself
Security
Note
Medium Risk
Touches core lint traversal used by all nested rules; behavior change is narrow and well-tested but could affect edge cases in custom rules relying on the old (buggy) re-entry semantics.
Overview
Fixes false duplicate-parameter lint errors when the same path item is referenced from multiple
$refs (e.g. two callbacks pointing at#/components/pathItems/notify). Multiple references resolve to one object, so the walker could re-enter that node without re-running parententerhooks while still firing nested visitors—leaving stale parent context and bogus reports on unrelated operations.The OpenAPI walker in
walk.tsnow tracks the node actually being walked per type (walkingNodeByType) and only activates nested visitors when the parent’s activated node matches that stack. Sibling keys beside a$refstill get walked as before.Adds unit coverage for shared callback path items and
$refsiblings, plus an e2e fixture whereoperation-parameters-uniqueandpath-parameters-definedmust pass when a shared path item is reused.Reviewed by Cursor Bugbot for commit 394cd16. Bugbot is set up for automated code reviews on this repo. Configure here.