Skip to content

feat(generator-asyncapi): add attachHeadersToSchema option#345

Merged
boyney123 merged 6 commits intomainfrom
feat/asyncapi-attach-headers-to-schema
Feb 26, 2026
Merged

feat(generator-asyncapi): add attachHeadersToSchema option#345
boyney123 merged 6 commits intomainfrom
feat/asyncapi-attach-headers-to-schema

Conversation

@boyney123
Copy link
Contributor

What This PR Does

Adds a new attachHeadersToSchema boolean option to the AsyncAPI generator that combines message headers and payload into a single unified schema. When enabled, the generated schema wraps the original payload and headers under properties.payload and properties.headers respectively. This is useful for consumers who need header metadata alongside the message body.

Changes Overview

Key Changes

  • Add attachHeadersToSchema option to the options schema and destructuring
  • Extract schema retrieval into getSchemaForMessage helper that conditionally merges headers
  • Add getSchemaFromMessagePart helper to normalize nested schema formats
  • Add isJSONSchemaMessage guard to skip header attachment for non-JSON schemas (e.g., Avro)
  • Add three test cases covering: headers + payload merge, no-headers fallback, and non-JSON schema skip
  • Add Avro + headers test fixture file

How It Works

When attachHeadersToSchema is true, the generator checks if the message has headers and uses a JSON schema format. If both conditions are met, it wraps the payload and headers into a combined { type: "object", properties: { headers, payload } } schema. For non-JSON schema formats (like Avro) or messages without headers, the original payload schema is returned unchanged.

Breaking Changes

None. The option defaults to false, so existing behavior is preserved.

🤖 Generated with Claude Code

boyney123 and others added 3 commits February 26, 2026 14:42
… headers and payload

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

changeset-bot bot commented Feb 26, 2026

🦋 Changeset detected

Latest commit: a0ba207

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

@boyney123 boyney123 merged commit 1753235 into main Feb 26, 2026
5 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