-
Notifications
You must be signed in to change notification settings - Fork 65
[TCGC] Add optional property to SdkMethodResponse to distinguish from nullable body types #3493
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…le types Co-authored-by: tadelesh <[email protected]>
Co-authored-by: tadelesh <[email protected]>
tadelesh
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot run pnpm format to format code and pnpm change add to add changeset. In the changeset, you need to mention how to do migration for the breaking change.
Co-authored-by: tadelesh <[email protected]>
.chronus/changes/add-optional-property-sdkmethodresponse-2025-11-10.md
Outdated
Show resolved
Hide resolved
Co-authored-by: tadelesh <[email protected]>
commit: |
packages/typespec-client-generator-core/test/methods/responses.test.ts
Outdated
Show resolved
Hide resolved
markcowl
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not be merged until after the November release (this week).
…ponse without body exists, false when all responses have body, undefined when no response type Co-authored-by: tadelesh <[email protected]>
Summary
This PR fixes the issue where TCGC treats response types with no body as
nullable, making it impossible to distinguish between:{@body body: Type | null})Type | NoContentResponse)Changes
optionalproperty toSdkMethodResponseinterface ininterfaces.tsgetSdkMethodResponsefunction inmethods.tsto setoptionalcorrectly:truewhen there is a response without bodyfalsewhen all responses have bodyundefinedwhen there is no response typeoptionalproperty instead of nullable typeType | nulland responses without bodypnpm formatBreaking Change
optionalproperty when handling responses that may not have a body.Migration Guide
Before:
After:
Property Values
The
optionalproperty onSdkMethodResponsehas three possible values:true: At least one HTTP response has no body (e.g.,Widget | NoContentResponse)false: All HTTP responses have a body (e.g.,{@body body: Widget | null})undefined: No response type exists (e.g.,voidorNoContentResponseonly)Examples
Case 1: Nullable body type
Result:
type.kind === "nullable",optional === falseCase 2: Optional response (no body in some cases)
Result:
type.kind === "model",optional === trueCase 3: No response type
Result:
type === undefined,optional === undefinedTest Results
✅ All 1016 tests pass (2 skipped)
✅ No regressions detected
✅ New test validates the distinction between nullable body and optional response
Fixes #3302
Original prompt
nullablegenerated by tcgc is not as expected #3302✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.