Skip to content

fix: answer 400 for a null or missing stay in the booking sample (#465) - #467

Merged
CaffeinatedCoder merged 2 commits into
mainfrom
fix/465-sample-null-stay
Oct 25, 2026
Merged

CaffeinatedCoder merged 2 commits into
mainfrom
fix/465-sample-null-stay

Conversation

@CaffeinatedCoder

Copy link
Copy Markdown
Owner

Closes #465

Problem

POST /bookings with {"roomId":1,"guest":"Ada","stay":null}, or with no stay, answered 500 with an UnreachableException. System.Text.Json doesn't check nullable annotations by default, so it bound BookingRequest.Stay as null, and CheckStay reached its throwing discard arm. An outside pre-tag review of release/10.x found it. The walkthrough said the discard arm was only there for the compiler.

Change

  • samples/Bookings/BookingApi.cs: CheckStay takes a DateRange? and answers "Give the stay." for null, so the sample returns a 400 validation problem.
  • docs/walkthrough.md: quotes the new CheckStay, and a "Good to know" bullet says why a JSON null reaches the handler (RespectNullableAnnotations is off by default).

The sample isn't in a package, so there is no changelog row.

Tests

  • WalkthroughSampleTests (live): posts a null stay and a body with no stay, and expects the 400 with {"stay":["Give the stay."]}.
  • Reverted (the old BookingApi.cs back): the test fails with System.Diagnostics.UnreachableException.
  • Conventions pass, including WalkthroughSampleConventionTests, which checks that the page quotes the sample verbatim. The sample builds.

🤖 Generated with Claude Code

System.Text.Json doesn't check nullable annotations by default, so "stay":null, or a body
with no stay, bound BookingRequest.Stay as null. CheckStay then reached its throwing
discard arm and the sample answered 500 with an UnreachableException. CheckStay now takes
a DateRange? and answers "Give the stay." for null, and the walkthrough quotes the new
code and says why null arrives.

Found-By: RV
Defect-Class: JSON

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@CaffeinatedCoder CaffeinatedCoder added this to the 10.3.0 milestone Oct 25, 2026
@CaffeinatedCoder CaffeinatedCoder added bug Something isn't working severity/low Cosmetic, message or documentation-level difference labels Oct 25, 2026
@CaffeinatedCoder
CaffeinatedCoder merged commit 1e7097e into main Oct 25, 2026
14 checks passed
@CaffeinatedCoder
CaffeinatedCoder deleted the fix/465-sample-null-stay branch October 25, 2026 21:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working severity/low Cosmetic, message or documentation-level difference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Booking sample answers 500 for a null or missing stay

1 participant