fix(http-server-csharp): resolve declared service namespace - #11908
Conversation
Co-authored-by: GitHub Copilot <copilot@github.com>
commit: |
|
All changed packages have been documented.
Show changes
|
|
You can try these changes here
|
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟢 Approval recommended
The new namespace-resolution behavior is implemented via a single shared helper, has targeted test coverage for both the @service and no-service fallback paths, and includes an appropriate .chronus fix entry.
Pull request overview
This PR fixes service namespace selection in @typespec/http-server-csharp so the generated C# root namespace always comes from the namespace explicitly decorated with @service, rather than whichever non-std namespace happens to appear first. This aligns emitted C# namespaces with author intent and stabilizes output when imported/unrelated namespaces exist.
Changes:
- Added
getServiceNamespace(program)to centralize “service namespace (preferred) / standalone fallback” resolution logic. - Updated
resolveServiceTypesandgetServiceNamespaceNameto use the unified service namespace resolution. - Added/updated tests to lock in correct
@serviceprecedence and fallback behavior; updated a legacy generation test expectation accordingly.
File summaries
| File | Description |
|---|---|
| packages/http-server-csharp/test/generation.test.ts | Updates legacy generation assertions to reflect corrected namespace qualification in emitted C# when service namespace is resolved reliably. |
| packages/http-server-csharp/src/service-resolution.ts | Switches service namespace discovery to the new getServiceNamespace(program) helper. |
| packages/http-server-csharp/src/service-resolution.test.ts | Adds coverage for preferring the @service namespace and validates standalone fallback behavior. |
| packages/http-server-csharp/src/service-discovery.ts | Introduces getServiceNamespace and refactors getServiceNamespaceName to use compiler getNamespaceFullName. |
| .chronus/changes/http-server-csharp-service-namespace-2026-09-08.md | Adds a fix changelog entry describing the user-visible namespace resolution correction. |
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 updates the logic for determining the generated C# service namespace in the
@typespec/http-server-csharppackage. Now, the namespace explicitly declared with@serviceis always used for the generated C# service namespace, even if an imported or unrelated namespace appears first. The changes also refactor and clarify related code, and add new tests to ensure correct behavior.Service namespace resolution improvements:
getServiceNamespaceinservice-discovery.tsto reliably select the namespace declared with@service, falling back to the first non-standard namespace with content if no service is declared.getServiceNamespaceNameto use the newgetServiceNamespacelogic, ensuring the correct namespace is used for C# code generation.resolveServiceTypesinservice-resolution.tsto usegetServiceNamespaceinstead of the previous custom logic, and updated documentation/comments for clarity. [1] [2]Testing and documentation:
service-resolution.test.tsto verify that the namespace declared with@serviceis used, and to cover fallback behavior when no service is declared. [1] [2]