Repository navigation
fix: handle circular references from recursive schemas - #231
Merged
Merged
Conversation
Resolved $refs turn a recursive schema into a circular object, and fast-json-patch's compare throws "Converting circular structure to JSON" when it clones it. Replace each back-reference with a marker naming the ancestor's JSON pointer before comparing, so a redirected recursive reference still shows up as a change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Welcome to AsyncAPI. Thanks a lot for creating your first pull request. Please check out our contributors guide useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.
|
willbamford
marked this pull request as ready for review
November 12, 2026 13:19
willbamford
requested review from
aayushmau5,
asyncapi-bot-eve,
derberg and
magicmatatjahu
as code owners
November 12, 2026 13:19
Member
|
Hi @willbamford Thanks for the PR. |
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.



Description
Diffing parsed documents (
document.json()) that contain a recursive schema throwsTypeError: Converting circular structure to JSON. Resolved$refs turn the schema into a circular object, andfast-json-patch'scompareclones its inputs withJSON.stringify.generateDiffnow copies both documents first, replacing each reference back to an ancestor with a marker that names the ancestor's JSON pointer ([Circular /components/schemas/filters]). Using a single[Circular]placeholder would hide a recursive reference that gets redirected to a different ancestor, so the pointer is part of the marker. Shared, non-recursive references are copied as before.Tests cover a v3 spec with a recursive
anyOfschema through the parser, which fails onmaster, plus a redirected recursive reference and pointer escaping.Related issue(s)
Same crash as asyncapi/cli#2093. asyncapi/cli#2113 works around it in the CLI only; fixing it here covers every consumer of the library.
via Claude Opus 5.5