Skip to content

fix: stop adding topic and retain when writing an MQTT lastWill - #47

Merged
VisualBean merged 1 commit into
ByteBardOrg:vnextfrom
bielu:fix/mqtt-lastwill-roundtrip
Oct 17, 2026
Merged

VisualBean merged 1 commit into
ByteBardOrg:vnextfrom
bielu:fix/mqtt-lastwill-roundtrip

Conversation

@bielu

@bielu bielu commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

Problem

Reading an MQTT server binding with a partial lastWill and writing it back changes the document:

# input
bindings:
  mqtt:
    lastWill:
      qos: 1
# output
bindings:
  mqtt:
    lastWill:
      topic:
      qos: 1
      retain: false

LastWill.Serialize wrote topic with WriteRequiredProperty (so a missing topic became topic: null) and retain from a non-nullable bool (so a missing value became retain: false). Both fields are optional in the MQTT binding spec.

Change

  • retain now has a private bool? backing field; the public Retain property is still bool (defaults to false), the same pattern MQTTOperationBinding already uses for qos/retain. No public API change.
  • topic and retain are written with WriteOptionalProperty, so they appear only when set. An explicitly assigned Retain = false is still written.

Tests

Added to MQTTBindingVariants_Should:

  • LastWill_WithoutTopicAndRetain_RoundTripsWithoutAddingThem (V2 and V3): fails on vnext, passes with this change.
  • LastWill_WithExplicitRetainFalse_WritesRetain: guards that an explicit false is still written.

The existing V2_MQTTServerBinding_FilledObject_SerializesAndDeserializes round-trip is unchanged, and the full suite passes on net8.0/net9.0/net10.0.

🤖 Generated with Claude Code

LastWill wrote `topic` with WriteRequiredProperty and `retain` from a
non-nullable bool, so reading `lastWill: { qos: 1 }` and writing it back
produced `topic:` (null) and `retain: false`. Both fields are optional in
the MQTT binding spec.

`retain` now has a nullable backing field (same pattern as
MQTTOperationBinding), and both fields are written only when set. The
public `Retain` property keeps its bool type, so this is not a breaking
API change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

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 59 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
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 15ea4d83-c15d-4f46-ac01-fecee5701749
📥 Commits

Reviewing files that changed from the base of the PR and between eb68984 and fa8bb27.

📒 Files selected for processing: 2
  • src/ByteBard.AsyncAPI.Bindings/MQTT/LastWill.cs
  • test/ByteBard.AsyncAPI.Tests/Bindings/MQTT/MQTTBindingVariants_Should.cs
  • 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.

@bielu
bielu marked this pull request as ready for review October 17, 2026 17:32
@VisualBean
VisualBean merged commit 150d6d7 into ByteBardOrg:vnext Oct 17, 2026
9 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