Skip to content

fix: handle 2.x message traits without headers - #58

Merged
VisualBean merged 4 commits into
ByteBardOrg:vnextfrom
bielu:fix/v2-message-trait-headers
Oct 24, 2026
Merged

VisualBean merged 4 commits into
ByteBardOrg:vnextfrom
bielu:fix/v2-message-trait-headers

Conversation

@bielu

@bielu bielu commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Fixes a 2.x message trait crash that downstream consumers have to work around (see bielu/Bielu.AspNetCore.ApiDescriptions#137).

  • The 2.x writer threw NullReferenceException for a trait without headers (this.Headers.SchemaFormat).
  • The 2.x reader threw when schemaFormat appeared without headers, or before them.
  • A later headers field discarded an earlier schemaFormat.

All three are fixed. In 3.x output, a trait whose headers have a format but no schema now leaves headers out.

Testing

  • Added 3 regression tests. All 3 fail without the fix.
  • dotnet test: all pass.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Fixed AsyncAPI message traits to serialize correctly when headers are absent, including when converting between versions 2.0 and 3.0.
    • Fixed deserialization so schema format information is handled when it appears before headers or without headers.
    • AsyncAPI 3.0 message traits now include headers only when a header schema is available.

@bielu
bielu requested a review from VisualBean as a code owner October 24, 2026 11:08
@coderabbitai

coderabbitai Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 30 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3fcd4021-c654-4aed-8823-81c2e6b7bf24
Commits

Reviewing files that changed from the base of the PR and between b08f9fb and 7d6c85c.

Files selected for processing: 3
  • src/ByteBard.AsyncAPI.Readers/V2/AsyncApiMessageTraitDeserializer.cs
  • src/ByteBard.AsyncAPI/Models/AsyncApiMessageTrait.cs
  • test/ByteBard.AsyncAPI.Tests/Models/AsyncApiMessage_Should.cs

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c3968238-0f84-44d7-8330-5e7297da6514
Commits

Reviewing files that changed from the base of the PR and between 7ed7e04 and b08f9fb.

Files selected for processing: 3
  • src/ByteBard.AsyncAPI.Readers/V2/AsyncApiMessageTraitDeserializer.cs
  • src/ByteBard.AsyncAPI/Models/AsyncApiMessageTrait.cs
  • test/ByteBard.AsyncAPI.Tests/Models/AsyncApiMessage_Should.cs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Walkthrough

The V2 message-trait deserializer now preserves or initializes headers when processing schema fields. V2 and V3 serialization handle missing header schemas. Tests cover deserialization, serialization, and conversion between versions.

Changes: Message Trait Header Handling

Layer / File(s) Summary
Deserialize headers and schema formats
src/ByteBard.AsyncAPI.Readers/V2/AsyncApiMessageTraitDeserializer.cs, test/ByteBard.AsyncAPI.Tests/Models/AsyncApiMessage_Should.cs
The V2 deserializer preserves an existing headers object or initializes one when applying a schema format. Tests cover schema format ordering and input with no headers.
Serialize optional headers across versions
src/ByteBard.AsyncAPI/Models/AsyncApiMessageTrait.cs, test/ByteBard.AsyncAPI.Tests/Models/AsyncApiMessage_Should.cs
V2 serialization accesses header schema and format safely. V3 serialization omits headers when no schema exists. Tests cover serialization without headers, V3 header format, and cross-version conversion.

Priority: Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: visualbean

Merge Risk: Minimal · up to b08f9

The described header-handling changes have no identified issue requiring resolution before merge; normal checks remain appropriate.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 10 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly identifies the main change: fixing 2.x message traits without headers. It is concise and specific.
Description check Passed The description clearly explains the three fixes, the 3.x behavior, and the test results. It does not use the template headings or include a formal Changelog or Related Issues section, but the require…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description clearly explains the three fixes, the 3.x behavior, and the test results. It does not use the template headings or include a formal Changelog or Related Issues section, but the required change context and validation details are present.

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Comment thread test/ByteBard.AsyncAPI.Tests/Models/AsyncApiMessage_Should.cs
@bielu
bielu force-pushed the fix/v2-message-trait-headers branch from b2a1c0c to 65818e7 Compare October 24, 2026 20:38
bielu and others added 3 commits October 24, 2026 22:17
The 2.x writer threw NullReferenceException for a message trait without
headers because it read Headers.SchemaFormat unconditionally. The 2.x reader
threw too when schemaFormat appeared without headers, or before them, and a
later headers field discarded an earlier schemaFormat.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Adds 3.x counterparts to the 2.x message trait tests, so the change to the
3.x writer is shown not to regress: a trait without headers, a trait with
headers, and a 2.x trait with schemaFormat but no headers upgraded to 3.x.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bielu
bielu force-pushed the fix/v2-message-trait-headers branch from b08f9fb to 4f3a7d7 Compare October 24, 2026 21:17
@VisualBean
VisualBean merged commit 4fcc2ad into ByteBardOrg:vnext Oct 24, 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.

2 participants