Skip to content

fix(asyncapi): preserve shared references when saving parsed spec files - #445

Merged
boyney123 merged 2 commits into
mainfrom
fix/asyncapi-shared-refs-parsed-spec
Aug 19, 2026
Merged

fix(asyncapi): preserve shared references when saving parsed spec files#445
boyney123 merged 2 commits into
mainfrom
fix/asyncapi-shared-refs-parsed-spec

Conversation

@boyney123

Copy link
Copy Markdown
Contributor

Summary

Fixes event-catalog/eventcatalog#2745 — AsyncAPI pages rendering as a blank white page in EventCatalog.

Root cause

Parsed AsyncAPI v3 documents contain shared (non-circular) object references: each operation's dereferenced channel is the same JS object as the entry under the root channels object. The circular-reference-safe serializer introduced in #364 (safeStringify, released in 6.1.1) tracked every object it had ever seen, so it treated these shared references as cycles and collapsed them into $ref: '#' — a reference to the document root.

With saveParsedSpecFile: true, the resulting spec file fails AsyncAPI validation (asyncapi3-required-operation-channel-unambiguity plus cascading errors) when EventCatalog re-parses it at build time, so parsed.document is undefined and the AsyncAPI page renders completely blank.

Fix

Track ancestors instead of every object seen: shared references are serialized inline, and only true cycles (e.g. the oneOf/allOf discriminator patterns from #364) are replaced with a $ref. The YAML path (yaml.dump) gets the same cycle-breaking pre-pass so circular schemas can no longer crash it.

Testing

  • New regression test with an AsyncAPI v3 fixture (root operations referencing channels, external payload schema $refs) that asserts the saved spec file contains no $ref: "#" and re-parses as a valid AsyncAPI document — fails on the old code, passes with the fix
  • Full generator-asyncapi suite: 145/145 passing, including the original AsyncAPI: oneOf / allOf references can not be parsed #364 circular-ref test
  • Verified the reporter's real spec files now round-trip through save → re-parse with zero errors, and render correctly in the EventCatalog AsyncAPI page

Parsed AsyncAPI v3 documents contain shared (non-circular) references:
each operation's dereferenced channel is the same object as the entry
under the root channels object. The circular-reference-safe serializer
treated any already-seen object as a cycle and replaced it with
$ref: '#', producing a spec file that fails AsyncAPI validation and
renders as a blank page in EventCatalog. Track ancestors instead of
every object seen so shared references are preserved and only true
cycles are replaced with a $ref.

Closes event-catalog/eventcatalog#2745
@changeset-bot

changeset-bot Bot commented Aug 19, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 9ff1764

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@eventcatalog/generator-asyncapi Patch

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

The Version Packages commit bumped generator-apicurio's dependency on
@eventcatalog/generator-openapi to >=9.0.0 without regenerating the
lockfile, so every CI job fails at install with
ERR_PNPM_OUTDATED_LOCKFILE (also failing on main).
@boyney123
boyney123 merged commit 67cf0b2 into main Aug 19, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AsyncAPI not are not shown in the visualiser

1 participant