Skip to content

fix(http-server-csharp): resolve declared service namespace - #11908

Merged
Timothee Guerin (timotheeguerin) merged 2 commits into
mainfrom
sramsey/csharp-service-namespace
Sep 10, 2026
Merged

fix(http-server-csharp): resolve declared service namespace#11908
Timothee Guerin (timotheeguerin) merged 2 commits into
mainfrom
sramsey/csharp-service-namespace

Conversation

@sophia-ramsey

Copy link
Copy Markdown
Member

This pull request updates the logic for determining the generated C# service namespace in the @typespec/http-server-csharp package. Now, the namespace explicitly declared with @service is 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:

  • Added a new function getServiceNamespace in service-discovery.ts to reliably select the namespace declared with @service, falling back to the first non-standard namespace with content if no service is declared.
  • Updated getServiceNamespaceName to use the new getServiceNamespace logic, ensuring the correct namespace is used for C# code generation.
  • Refactored resolveServiceTypes in service-resolution.ts to use getServiceNamespace instead of the previous custom logic, and updated documentation/comments for clarity. [1] [2]

Testing and documentation:

  • Added and updated tests in service-resolution.test.ts to verify that the namespace declared with @service is used, and to cover fallback behavior when no service is declared. [1] [2]
  • Added a changelog entry describing the fix and its effect on generated C# service namespaces. (.chronus/changes/http-server-csharp-service-namespace-2026-09-08.md)

Co-authored-by: GitHub Copilot <copilot@github.com>
@pkg-pr-new

pkg-pr-new Bot commented Sep 9, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/http-server-csharp@11908

commit: 2094f03

@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • @typespec/http-server-csharp
Show changes

@typespec/http-server-csharp - fix ✏️

Use the namespace declared with @service as the generated C# service namespace, even when an imported or unrelated namespace is encountered first.

@azure-sdk-automation

azure-sdk-automation Bot commented Sep 9, 2026

Copy link
Copy Markdown

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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 resolveServiceTypes and getServiceNamespaceName to use the unified service namespace resolution.
  • Added/updated tests to lock in correct @service precedence 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.

Merged via the queue into main with commit 71b8d96 Sep 10, 2026
35 checks passed
@timotheeguerin
Timothee Guerin (timotheeguerin) deleted the sramsey/csharp-service-namespace branch September 10, 2026 18:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants