Skip to content

fix(http-server-csharp): only emit types that belong to the service - #11520

Draft
timotheeguerin wants to merge 2 commits into
microsoft:mainfrom
timotheeguerin:timotheeguerin/hscsharp-emit-only-service-types
Draft

fix(http-server-csharp): only emit types that belong to the service#11520
timotheeguerin wants to merge 2 commits into
microsoft:mainfrom
timotheeguerin:timotheeguerin/hscsharp-emit-only-service-types

Conversation

@timotheeguerin

@timotheeguerin timotheeguerin commented Aug 1, 2026

Copy link
Copy Markdown
Member

The emitter generated a class for every model, enum and union it could reach from the global namespace, including all the declarations of any imported library, whether or not the service used them. On a spec built on a few library templates that meant dozens of dead C# classes, plus anonymous-model warnings pointing at library files the spec author cannot change.

Emission is now anchored on the service: declarations of the service namespace(s) are always emitted, and anything declared elsewhere is emitted only when the service references it, directly or transitively (operations, properties, base models, template arguments, union variants, array/record element types). Diagnostics follow the same rule, so warnings only point at the spec's own types.

On a sample spec using library templates this drops the generated models from 63 to 34 and the warnings from 5 to 0, with no unresolved type references in the generated project.

Two related gaps are fixed along the way: enums and unions are now discovered through references (previously only through a namespace walk), and Record<T> value types are traversed.

Specs that declare no @service keep the previous behavior, since there is nothing to anchor the emit on.

Types declared outside the service namespace are now emitted only when the service references them, directly or transitively, instead of emitting every model, enum and union declared by imported libraries.
@pkg-pr-new

pkg-pr-new Bot commented Aug 1, 2026

Copy link
Copy Markdown

Open in StackBlitz

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

commit: a534e6a

@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • @typespec/http-server-csharp
Show changes

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

Only emit types that belong to the service. Types declared outside the service namespace, for example in an imported library, are now emitted only when the service references them, directly or transitively.

@azure-sdk-automation

azure-sdk-automation Bot commented Aug 1, 2026

Copy link
Copy Markdown

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

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.

1 participant