fix(http-server-csharp): emitter type errors - #11628
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
commit: |
|
All changed packages have been documented.
Show changes
|
…msey/csharp-server-nullable
There was a problem hiding this comment.
Pull request overview
This PR improves the C# HTTP server emitter’s correctness around nullable/optional parameter rendering, response handling for union return types (especially void | @error patterns), and controller argument ordering by tracking the original (business) operation behind each canonicalized HTTP operation.
Changes:
- Fixes “double nullable” (
int??) emission for optional nullable value-type parameters across interfaces and mocks. - Tracks canonical operation → source operation to preserve business-parameter ordering when generating controller call sites.
- Improves response analysis to emit
204 NoContent(andNoContent()) forvoidsuccess unions while still handling value success unions correctly; adds multipart and error-model-related robustness tests.
Reviewed changes
Copilot reviewed 20 out of 21 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/http-server-csharp/test/snapshots/sample-service/generated/controllers/PetsController.cs | Updates generated DELETE action to return 204/NoContent for void success. |
| packages/http-server-csharp/test/nullable-parameters.test.ts | Adds integration-style test to prevent int??/Choice?? in emitted mocks/interfaces. |
| packages/http-server-csharp/src/service-resolution.ts | Returns both canonical ops map and a canonical→source operation map. |
| packages/http-server-csharp/src/service-resolution.test.ts | Verifies canonical→source operation tracking behavior. |
| packages/http-server-csharp/src/emitter.tsx | Plumbs canonical→source operation map via a new Alloy context provider. |
| packages/http-server-csharp/src/context/operation-source-context.ts | Introduces OperationSources context for canonical→source operation lookup. |
| packages/http-server-csharp/src/components/type-expression/type-expression.tsx | Adds helper to detect nullable value-type unions for correct T? emission. |
| packages/http-server-csharp/src/components/scaffolding/mock-implementations.tsx | Aligns mock signatures with nullable/optional rules and multipart fallback detection. |
| packages/http-server-csharp/src/components/render-root.tsx | Adds multipart fallback detection for interface usings when canonical metadata is absent. |
| packages/http-server-csharp/src/components/multipart-fallback.test.tsx | New test ensuring multipart interface + mocks stay aligned without canonicalization. |
| packages/http-server-csharp/src/components/models/models.tsx | Adjusts JsonNodes-using decision for root error models (includes inherited checks). |
| packages/http-server-csharp/src/components/models/model-helpers.ts | Improves modelNeedsJsonNodes recursion/inheritance handling. |
| packages/http-server-csharp/src/components/models/error-models.tsx | Uses TypeExpression for union/tuple/record/array ctor parameter typing. |
| packages/http-server-csharp/src/components/models/error-models.test.tsx | Adds tests for structured error constructor typing + inherited JsonNodes using. |
| packages/http-server-csharp/src/components/interfaces/interfaces.tsx | Fixes nullable suffix emission; adds multipart decorator fallback helpers. |
| packages/http-server-csharp/src/components/interfaces/interfaces.test.tsx | Adds tests for nullable suffix and multipart fallback behavior. |
| packages/http-server-csharp/src/components/controllers/controllers.tsx | Passes source (business) operation into ControllerAction via context lookup. |
| packages/http-server-csharp/src/components/controllers/controllers.test.tsx | Adds test ensuring source operation preserves positional argument order. |
| packages/http-server-csharp/src/components/controller-action/response-analysis.ts | Updates success-status analysis for unions (skip errors, handle void success → 204). |
| packages/http-server-csharp/src/components/controller-action/controller-action.tsx | Orders call arguments based on source operation; uses updated success-status analysis. |
| packages/http-server-csharp/src/components/controller-action/controller-action.test.tsx | Adds regression tests for void/value union handling and call-arg ordering. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…icrosoft/typespec into sramsey/csharp-server-nullable
…icrosoft/typespec into sramsey/csharp-server-nullable
|
You can try these changes here
|
Addresses errors I encountered while using the C# server emitter to emit code from the ai foundry spec for the agent contracts api service package. Includes tests
Issues addressed:
int??toint?)<Unresolved Symbol ...>by falling back to the original@multipartBodymetadata when canonicalization data is unavailableRecord,Array, orobjectinstead of the same concrete structured types used by their propertiesvoid | @errorresponses generating invalid result assignments by excluding error branches from success-response analysis and emitting direct awaits withNoContent()