Repository navigation
fix(downgrader): stop recursive $refs into part of an inlined target from making circular output - #93
Merged
Merged
Conversation
…from making circular output A `$ref` into part of a `$defs` entry, webhook, or `components.pathItems` entry that is being inlined, or to the entry around a part being inlined, reused an output still being filled, so the 3.0 output held itself and `JSON.stringify` threw. zod-to-json-schema writes both for `z.lazy` inside `definitions`. Each inlined target now keeps its own `seen` map, so no inlined output reaches one still being filled. The kept-`$ref` looseness check still uses the outside one, so components are converted once. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RnCVj9oJRTNuTKj5n1FBeh
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Per-target
seenfor inlined$refs —Contextgainssharedandapart;inline(ref, ctx, convert, shared = false)now converts each inlined target with its ownseenmap (created on first inline, reused for later inlines of the same target). A still-active target is rejected byctx.inliningbeforeapartis consulted, soapartonly returns completed outputs — an inlined target can no longer reach an output still being filled and embed it. - Kept-
$reflooseness check stays on the sharedseen—convertSchemaRefpassesshared = true, so refs kept as written still reuse the component copy and components are converted once. Theinlineresult is only read forisLoose, never embedded, so this path stays acyclic. - Four regression tests — a
$refinto part of a$defsentry from inside it, from another entry inlined inside it, into the entry around a part being inlined, plus the webhook equivalent; each asserts exact output and thatJSON.stringifydoes not throw. - README Performance — notes objects inside an inlined
$reftarget are converted once per target.
Verification
- Full suite: 262 passing;
uncheck(oxlint / oxfmt / tsc) clean on the three changed source/test files. - Reverting the
inlinebody to the pre-fix global-seenbehavior makes all four new tests fail (4 failed | 86 skipped), so they are live guards, not theatre. - A 3000-case fuzz over random
$defs+ part-$refgraphs reports circular output in 1033/3000 conversions pre-fix and 0 post-fix.
The behavioral change — objects inside an inlined target are now converted once per target, so their identity is no longer shared with the component copy — is documented and consistent with the existing corpus/chained/snapshot tests.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
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.

Requested by dinwwwh · project thread
Problem
In 3.1 to 3.0 (since v0.3.0), a
$refinto part of a target the downgrader inlines (a$defs/definitionsentry, a webhook, or acomponents.pathItemsentry), or a$reffrom such a part to the entry around it, could reuse an output that was still being filled. The output then contained itself, andJSON.stringifythrewConverting circular structure to JSON.zod-to-json-schema 3.25 writes both shapes for
z.lazyinsidedefinitions:Fix
inlinegives each inlined target its ownseenmap (ctx.apart, keyed by target, reused when the same target is inlined again). That way an inlined output never reaches one that is still being filled. The kept-$reflooseness check inconvertSchemaRefpassesshared = trueand keeps using the outsideseen(ctx.shared), so components are still converted once.Tests
Four new tests. Each one fails on main and passes here, and each asserts that
JSON.stringifydoes not throw: a$refinto part of a$defsentry from inside it, the same for a webhook, a$refback from another inlined entry, and a$refto the entry around a part being inlined. README Performance now says objects inside an inlined$reftarget are converted once per target.Checks
pnpm run checkpasses, 262 tests pass, and coverage is unchanged.$refgraphs, main gives circular output in 358 conversions and this branch in none.Generated by Claude Code