Skip to content

[http-client-csharp] @@clientName on discriminated union subtypes is ignored — generates original TypeSpec name #10657

@yungshinlintw

Description

@yungshinlintw

Bug Report

Emitter Version

@azure-typespec/http-client-csharp v1.0.0-alpha.20260512.2

Description

@@clientName directives for discriminated union subtypes are ignored during code generation. The emitter generates classes using the original TypeSpec model name instead of the @@clientName-specified name.

This is a regression — the GA version of our SDK (generated with an earlier emitter) correctly produced ContentArrayField, ContentStringField, etc. The new emitter produces ArrayField, StringField, etc., ignoring the @@clientName directives.

Repro

TypeSpec models (models.tsp):

@discriminator("type")
model ContentField { ... }

model ArrayField extends ContentField {
  type: ContentFieldType.array;
  valueArray?: ContentField[];
}

model StringField extends ContentField {
  type: ContentFieldType.string;
  valueString?: string;
}
// ... other subtypes of ContentField discriminated union

Client customization (client.tsp) — source: client.tsp L166-L174:

@@clientName(StringField, "ContentStringField", "csharp");
@@clientName(DateField, "ContentDateTimeOffsetField", "csharp");
@@clientName(TimeField, "ContentTimeField", "csharp");
@@clientName(NumberField, "ContentNumberField", "csharp");
@@clientName(IntegerField, "ContentIntegerField", "csharp");
@@clientName(BooleanField, "ContentBooleanField", "csharp");
@@clientName(ArrayField, "ContentArrayField", "csharp");
@@clientName(ObjectField, "ContentObjectField", "csharp");
@@clientName(JsonField, "ContentJsonField", "csharp");

Expected Behavior

The emitter should generate C# classes with the @@clientName-specified names:

  • ContentArrayField.cs
  • ContentStringField.cs
  • ContentDateTimeOffsetField.cs
  • etc.

Actual Behavior

The emitter generates classes using the original TypeSpec model names, ignoring @@clientName:

  • ArrayField.cs
  • StringField.cs
  • DateField.cs
  • etc.

Impact

This is a breaking change for our published GA SDK (Azure.AI.ContentUnderstanding). Our GA SDK exposes ContentArrayField, ContentStringField, etc. as public types. Regenerating with the new emitter renames these types, breaking:

  • All consumer code using these types
  • Our customization files (ContentUnderstandingClient.Customizations.cs) which reference these types by their @@clientName names — resulting in 144 compilation errors after regeneration

Merged GA SDK (proof that older emitter correctly applied @@clientName)

Context

  • TypeSpec @@clientName directives: client.tsp L166-L174 (C#) and client.tsp L207-L215 (Java)
  • TypeSpec repo: azure-rest-api-specs-pr (private), PR #27815
  • SDK: Azure.AI.ContentUnderstanding
  • API version: 2026-07-01-preview (base GA: 2025-11-01)
  • The same issue also affects the Java emitter (@azure-tools/typespec-java) — Azure/autorest.java#3337

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingemitter:client:csharpIssue for the C# client emitter: @typespec/http-client-csharp

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions