fix(http-server-csharp): avoid duplicate nullable suffixes - #11900
Open
sophia-ramsey wants to merge 2 commits into
Open
fix(http-server-csharp): avoid duplicate nullable suffixes#11900sophia-ramsey wants to merge 2 commits into
sophia-ramsey wants to merge 2 commits into
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
commit: |
Contributor
|
All changed packages have been documented.
Show changes
|
|
You can try these changes here
|
sophia-ramsey
marked this pull request as ready for review
September 10, 2026 17:41
sophia-ramsey
requested review from
catalinaperalta,
iscai-msft,
Laurent Mazuel (lmazuel),
Mark Cowlishaw (markcowl) and
Timothee Guerin (timotheeguerin)
as code owners
September 10, 2026 17:41
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The change is narrowly scoped, includes coverage in both component and end-to-end tests, and only leaves a minor test robustness nit.
Pull request overview
This PR fixes a C# server emitter bug where optional parameters whose TypeSpec type is already a nullable value-type union (e.g. int32 | null) could be emitted with a duplicated nullable suffix (int??) in generated business-logic interfaces and mock implementations.
Changes:
- Added a helper (
getNullableValueTypeUnionInnerType) to detect nullable value-type unions and extract the non-null inner type for special handling. - Updated interface and mock parameter type rendering to avoid double-appending
?for optional nullable value-type unions. - Added targeted tests (component-level and end-to-end) to ensure
int??does not appear in generated signatures.
File summaries
| File | Description |
|---|---|
| packages/http-server-csharp/test/nullable-parameters.test.ts | New end-to-end test validating optional nullable value parameters render with a single ? in both interfaces and mocks. |
| packages/http-server-csharp/src/components/type-expression/type-expression.tsx | Introduces helper for nullable value-type unions and refactors nullable-union rendering to use it. |
| packages/http-server-csharp/src/components/scaffolding/mock-implementations.tsx | Avoids T?? in mock method signatures by stripping nullable unions to their inner value type when also optional. |
| packages/http-server-csharp/src/components/interfaces/interfaces.tsx | Applies the same inner-type logic for optional parameters when building interface method parameters. |
| packages/http-server-csharp/src/components/interfaces/interfaces.test.tsx | Adds a component test asserting the interface signature uses only a single nullable suffix. |
| .chronus/changes/sramsey-csharp-duplicate-nullable-suffixes-2026-09-08.md | Adds a fix changelog entry for @typespec/http-server-csharp. |
Review details
- Files reviewed: 6/6 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request fixes an issue where optional nullable value parameters in generated C# interfaces and mocks would emit duplicate nullable suffixes (e.g.,
int??). The changes ensure that only a single nullable suffix is emitted for such parameters. The update includes logic changes, new helper functions, and additional tests to verify correct behavior.Bug Fix: Prevent Duplicate Nullable Suffixes
int32 | null) are rendered with only one nullable suffix (int?), preventing cases likeint??. [1] [2] [3] [4] [5]Helper Function
getNullableValueTypeUnionInnerTypeto detect and extract the correct inner type for nullable value types in unions, used to avoid double nullable suffixes. [1] [2] [3]Testing
These changes ensure that the generated C# code is correct and idiomatic when handling optional nullable value parameters.