fix(http-server-csharp): don't emit auth scheme models and fix enum member rendering - #11466
Merged
Merged
Conversation
…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
commit: |
Contributor
|
All changed packages have been documented.
Show changes
|
|
You can try these changes here
|
Member
Author
|
@copilot fix spellcheck |
timotheeguerin
commented
Jul 30, 2026
timotheeguerin
marked this pull request as ready for review
July 30, 2026 13:06
timotheeguerin
requested review from
catalinaperalta,
iscai-msft,
markcowl and
xirzec
as code owners
July 30, 2026 13:06
iscai-msft
approved these changes
Jul 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-csharpgenerated a C# model class for the auth scheme. That class:components.securitySchemes, never asschemas.type: AuthType.apiKey,in: Location) rendered as<Unresolved Symbol: refkey[...]>, producing C# errors likeThe name 'refkey' does not exist in the current context.These are two independent bugs.
Root causes
getServiceModels(service-resolution.ts) collected every named model in the service namespace, including@useAuthscheme models.TypeExpressionhad noEnumMembercase, so it fell through to the emitter-framework component which emitsefRefkey(enumMember). RegularEnummembers never register a member refkey (only union-enums do), so the reference was unresolved.Fix
service-resolution.ts— collect auth scheme models viagetAllHttpServices+resolveAuthentication(the same source the OpenAPI3 emitter uses) and exclude them from model discovery.type-expression.tsx— add anEnumMembercase that renders the parent enum type (kind: Color.red→Color), with a primitive-type fallback for std-lib enums (e.g.TypeSpec.Http.AuthType) that are never emitted.Tests
Added
toRenderTocomponent tests (no additions togeneration.test.ts):models.test.tsx— an@useAuthscheme model is excluded fromresolveServiceTypes(...).modelsand not rendered.type-expression.test.tsx— an enum-member property renders as its parent enum; a std-lib enum member falls back tostring.Full package suite passes (206 tests). Changeset included.