Skip to content

Escape angle brackets in OpenAPI and AsyncAPI descriptions - #447

Merged
boyney123 merged 1 commit into
mainfrom
fix/escape-special-characters-in-descriptions
Aug 31, 2026
Merged

Escape angle brackets in OpenAPI and AsyncAPI descriptions#447
boyney123 merged 1 commit into
mainfrom
fix/escape-special-characters-in-descriptions

Conversation

@boyney123

Copy link
Copy Markdown
Contributor

What This PR Does

Fixes a customer-reported bug where an OpenAPI parameter description containing angle brackets (e.g. <veldnaam>,<asc/desc>) is written raw into the generated .mdx file. MDX parses the angle brackets as a JSX tag and the EventCatalog build fails with:

Unexpected character `d` (U+0064) after self-closing slash, expected `>` to end the tag

The AsyncAPI generator has the same class of bug in service and channel descriptions (with no escaping at all, including curly braces), so this PR fixes both packages.

Changes Overview

Key Changes

  • generator-openapi: escapeSpecialCharactersThatBreakMarkdown now also escapes < (as \<) alongside the existing {/} escaping, and protects inline code spans in addition to fenced code blocks. The escaping is now applied to parameter descriptions and response schema descriptions, which were previously interpolated raw.
  • generator-asyncapi: adds the same escape utility (src/utils/markdown.ts) and applies it to service (info.description) and channel descriptions, which previously had no escaping at all.
  • Regression tests in both packages using fixtures containing <fieldname>,<asc/desc>, curly braces, and inline code — all failing before the fix, passing after.
  • Changesets: patch bumps for @eventcatalog/generator-openapi and @eventcatalog/generator-asyncapi.

How It Works

The escape utility replaces fenced code blocks and inline code spans with placeholders, escapes {, }, and < in the remaining text (MDX parses {} as JSX expressions and < as the start of a JSX tag), then restores the code blocks untouched. \< renders as a literal < in MDX, so descriptions display exactly as authored.

Verified end-to-end: regenerated a catalog from the customer's spec and from the AsyncAPI fixture, and compiled every generated .mdx file with @mdx-js/mdx — all compile cleanly, where the customer's file previously failed.

Breaking Changes

None.

Additional Notes

  • Response-level descriptions in OpenAPI (e.g. "200": description: ...) are never rendered into markdown — what renders under ### Responses is the response schema's own description, which is what this PR escapes and tests.
  • generator-aws-glue (src/utils/messages.ts) interpolates schema.description raw too — same class of bug, lower likelihood of angle brackets in practice. Left for a follow-up.

https://claude.ai/code/session_01EdKN8y3UTR6LeBWME4SsEz

Descriptions containing angle brackets (e.g. <fieldname>,<asc/desc>) were
written raw into generated markdown and parsed by MDX as JSX tags,
breaking the EventCatalog build.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Aug 31, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 64eaeb7

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

This PR includes changesets to release 2 packages
Name Type
@eventcatalog/generator-openapi Patch
@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

@boyney123
boyney123 merged commit 6f8ab8f into main Aug 31, 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.

1 participant