Skip to content

fix(http-server-csharp): don't emit auth scheme models and fix enum member rendering - #11466

Merged
iscai-msft merged 3 commits into
microsoft:mainfrom
timotheeguerin:cs-server-auth-models
Jul 30, 2026
Merged

fix(http-server-csharp): don't emit auth scheme models and fix enum member rendering#11466
iscai-msft merged 3 commits into
microsoft:mainfrom
timotheeguerin:cs-server-auth-models

Conversation

@timotheeguerin

Copy link
Copy Markdown
Member

Fixes #11449

Problem

When a spec applies @useAuth(...) with a named auth scheme model (e.g. model AzureApiKeyAuthentication is ApiKeyAuth<ApiKeyLocation.header, "Ocp-Apim-Subscription-Key">), @typespec/http-server-csharp generated a C# model class for the auth scheme. That class:

  1. Should not be generated at all — auth scheme models are protocol/security metadata, not payloads. The OpenAPI3 emitter emits them under components.securitySchemes, never as schemas.
  2. Failed to compile — its enum-member-typed properties (type: AuthType.apiKey, in: Location) rendered as <Unresolved Symbol: refkey[...]>, producing C# errors like The name 'refkey' does not exist in the current context.

These are two independent bugs.

Root causes

  • Auth models emitted: getServiceModels (service-resolution.ts) collected every named model in the service namespace, including @useAuth scheme models.
  • Unresolved symbol: the server TypeExpression had no EnumMember case, so it fell through to the emitter-framework component which emits efRefkey(enumMember). Regular Enum members never register a member refkey (only union-enums do), so the reference was unresolved.

Fix

  • service-resolution.ts — collect auth scheme models via getAllHttpServices + resolveAuthentication (the same source the OpenAPI3 emitter uses) and exclude them from model discovery.
  • type-expression.tsx — add an EnumMember case that renders the parent enum type (kind: Color.redColor), with a primitive-type fallback for std-lib enums (e.g. TypeSpec.Http.AuthType) that are never emitted.

Tests

Added toRenderTo component tests (no additions to generation.test.ts):

  • models.test.tsx — an @useAuth scheme model is excluded from resolveServiceTypes(...).models and not rendered.
  • type-expression.test.tsx — an enum-member property renders as its parent enum; a std-lib enum member falls back to string.

Full package suite passes (206 tests). Changeset included.

…ember rendering

Auth scheme models referenced by @useAuth (e.g. `model X is ApiKeyAuth<...>`) were emitted as C# payload classes. They are now excluded from model discovery, aligning with the OpenAPI3 emitter which treats them as security metadata.

Also fixes a property typed as an enum member (e.g. `kind: Color.red`) rendering as an unresolved refkey symbol; it now uses the parent enum type, with a primitive-type fallback for non-emitted std-lib enums.

Fixes microsoft#11449
@pkg-pr-new

pkg-pr-new Bot commented Jul 30, 2026

Copy link
Copy Markdown

Open in StackBlitz

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

commit: 33b5bfd

@github-actions

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • @typespec/http-server-csharp
Show changes

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

Do not generate C# model classes for authentication scheme models (e.g. models referenced by @useAuth), aligning with the OpenAPI3 emitter which treats them as security metadata. Also fix a property typed as an enum member (e.g. kind: Color.red) rendering as an unresolved symbol; it now uses the parent enum type.

@azure-sdk-automation

azure-sdk-automation Bot commented Jul 30, 2026

Copy link
Copy Markdown

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

@timotheeguerin

Copy link
Copy Markdown
Member Author

@copilot fix spellcheck

Comment thread packages/http-server-csharp/src/components/models/models.test.tsx Outdated
@timotheeguerin
timotheeguerin marked this pull request as ready for review July 30, 2026 13:06
@iscai-msft
iscai-msft added this pull request to the merge queue Jul 30, 2026
Merged via the queue into microsoft:main with commit dc8dcd8 Jul 30, 2026
33 checks passed
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.

[Bug]: http-server-csharp: Generated model file fails to compile due to Unresolved Symbol: refkey

2 participants