fix(http-server-csharp): align error constructor types - #11902
fix(http-server-csharp): align error constructor types#11902sophia-ramsey wants to merge 1 commit into
Conversation
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
commit: |
|
All changed packages have been documented.
Show changes
|
|
You can try these changes here
|
There was a problem hiding this comment.
🟢 Approval recommended
The changes are scoped, consistent with existing emitter/type-rendering behavior, and include targeted tests plus a valid .chronus fix entry.
Pull request overview
This PR fixes C# http-server emitter error model constructor generation so constructor parameters use the same rendered C# types as the emitted model properties (covering records, arrays, tuples, and nullable unions), and updates JsonNodes import detection to include inherited properties for root error models.
Changes:
- Switched error constructor parameter type rendering from legacy string mapping to the shared
TypeExpressionrenderer. - Enhanced
modelNeedsJsonNodesto recursively detectJsonObjectusage through nested types and (optionally) inherited properties, and wired it for root error models. - Added tests validating constructor parameter types and
System.Text.Json.Nodesimport emission for inherited record properties.
File summaries
| File | Description |
|---|---|
| packages/http-server-csharp/src/components/models/models.tsx | Passes a “root error model” flag to include inherited properties when deciding whether System.Text.Json.Nodes is needed. |
| packages/http-server-csharp/src/components/models/model-helpers.ts | Refactors modelNeedsJsonNodes into a recursive type-walk with optional base-model traversal; removes legacy getCSharpTypeString. |
| packages/http-server-csharp/src/components/models/error-models.tsx | Uses TypeExpression for error constructor parameter types to align with generated property types. |
| packages/http-server-csharp/src/components/models/error-models.test.tsx | Adds coverage for structured constructor parameter typing and inherited JsonObject import detection. |
| .chronus/changes/fix-csharp-error-constructor-types-2026-9-8.md | Adds a fix changeset for @typespec/http-server-csharp describing the user-visible behavior change. |
Review details
- Files reviewed: 5/5 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This pull request addresses the way error model constructors are generated in the C# server emitter, ensuring that the constructor parameters use the correct generated property types for all supported shapes (records, arrays, tuples, and nullable unions). It also improves detection of when error models require
JsonObject/JsonNodesimports and removes legacy type string generation logic. Comprehensive tests are added to verify the new behavior.Error model constructor improvements
Improved detection for
JsonObjectusagemodelNeedsJsonNodesfunction to recursively detect when a model or any of its inherited properties requireJsonObject(for nested or inherited record types), and updated its usage to include inherited properties for root error models. [1] [2]Code cleanup and refactoring
getCSharpTypeStringfunction in favor of using theTypeExpressioncomponent for type rendering, simplifying type handling logic. [1] [2]Testing
usingstatements forJsonObjectare included when required by inherited properties.