Skip to content

[http-client-csharp] Add discriminated union extends support - #12481

Merged
JoshLove01 merged 20 commits into
microsoft:mainfrom
jorgerangel-msft:jorgerangel-msft-union-extends-support
Nov 13, 2026
Merged

JoshLove01 merged 20 commits into
microsoft:mainfrom
jorgerangel-msft:jorgerangel-msft-union-extends-support

Conversation

@jorgerangel-msft

Copy link
Copy Markdown
Contributor

Summary

  • Support tagged JSON @discriminated unions with an explicit model base and nominally inherited model variants, exposing the declared base in generated C# APIs.
  • Adopt TCGC's inline-discriminator projection and add context-specific object-envelope serialization, including custom discriminator/payload names, nullable values, arrays, and dictionaries. Direct uses of payload models remain unwrapped.
  • Forward discriminator values through untagged intermediate models while preserving existing rebased-discriminator constructor behavior.
  • Add one Sample-TypeSpec hierarchy, positive/negative unit tests, serialization baselines, and Spector coverage for explicit, injected, custom, enum, and recursive inline discriminators.

Scope and dependencies

This covers the tagged JSON section of the .NET design. @events/SSE support is not included. Unions that do not meet the supported explicit-base and nominal-inheritance requirements retain their existing representation.

Uses the compatible prereleases containing the required metadata/projection: TCGC 0.74.0-dev.9 and Azure Core 0.74.0-dev.4. HTTP spec dependencies are updated to include the integration scenarios.

Validation

  • npm run build and generated Sample-TypeSpec compilation passed.
  • Emitter tests: 422 passed, 2 skipped.
  • Input serialization tests: 318 passed.
  • Focused generator/model-factory tests: 658 passed.
  • Focused client-model serialization/method tests: 876 passed.
  • Generated sample runtime tests: 18 passed.
  • Spector: all 5 tests passed, covering 18 wire contracts.
  • Repository-root formatting, scoped Oxlint, and Cop checks passed.

Validation after the constructor compatibility fix used the scoped suites above; a second full .NET test run was not performed.

Relates to #12478.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@microsoft-github-policy-service microsoft-github-policy-service Bot added the emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp label Nov 3, 2026
Make envelope union bases abstract and emit context-specific union methods in their model serialization files. Cover shared-base wire formats and restore the Spector skip comment.

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

JoshLove01 commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Resolved the conflicts with main and pushed merge commit 6ab759d. The union changes are retained alongside the upstream lifecycle revert and the migration to TCGC's @dynamicModel decorator.

The dependency blocker is resolved for this branch by pinning compiler 1.18.0-dev.14, TCGC 0.74.0-dev.16, and Azure Core 0.74.0-dev.5. A compiler-only npm override keeps dependencies on that same compiler despite their stale stable-only peer ranges; no --force or --legacy-peer-deps installation flags are needed. Regenerated the client fixtures with the merged implementation.

All six original inline review comments have replies.

--generated by Copilot

Preserve union serialization while adopting the upstream lifecycle revert and dynamic-model decorator migration. Align prerelease compiler and TCGC dependencies, override stale compiler peer constraints, and regenerate client fixtures.

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

pkg-pr-new Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/http-client-csharp@12481

commit: a3d7ded

@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

No changes needing a change description found.

…eneration

Keep the union-extends Spector client non-stubbed under the default generation command so CI regeneration matches the committed runtime-test fixture. Preserve stub generation for other Spector scenarios.

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

Copy link
Copy Markdown
Contributor

Fixed the regeneration failures in e303b24. The default generation command was replacing the executable union-extends Spector client with API-only stubs, which caused the generated-file drift on both platforms. That scenario now retains its executable client during default regeneration; other scenarios still generate stubs.

Verified default regeneration leaves both the union-extends fixture and an unrelated stub fixture unchanged, and the five union Spector scenarios still pass.

--generated by Copilot

Generate and commit the missing union-extends debugger profile using ScmCodeModelGenerator, matching the executable Spector fixture and eliminating remaining CI regeneration drift.

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

Copy link
Copy Markdown
Contributor

Fixed the remaining regeneration drift in 2ad40bb. The latest run confirms the generated clients now match; the only outstanding difference was the missing union-extends debugger launch profile. Added that generated profile and made it select ScmCodeModelGenerator, matching the executable fixture. Repeated launch-profile generation produces identical output.

--generated by Copilot

@JoshLove01
JoshLove01 marked this pull request as ready for review November 5, 2026 20:08
Copilot AI balanced review requested due to automatic review settings November 5, 2026 20:08

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.

🟡 Changes recommended

Union handling generates uncompilable SDK code for BinaryData customizations and leaves supported envelope variants internal, preventing consumers from constructing them or accessing variant-specific properties.

2 open issues
1 file not reviewed
  • packages/http-client-csharp/package-lock.json: Generated file
What changed in this PR

Adds C# support for tagged JSON unions with an explicit model base and nominally inherited variants, addressing #12478. The implementation preserves union-specific envelopes while keeping direct payload-model serialization unwrapped.

Changes:

  • Updates dependencies and carries supported union metadata from the emitter into the generator.
  • Adds contextual envelope serialization and inherited-discriminator constructor handling.
  • Adds sample hierarchies, serialization baselines, Spector coverage, and generation-script integration.
File Description
packages/​http-client-csharp/​package.json Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​Type.Union.Discriminated.Extends.slnx Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​Type.Union.Discriminated.Extends.NuGet.targets Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​tests/​Type.Union.Discriminated.Extends.Tests.csproj Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Type.Union.Discriminated.Extends.csproj Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​schema/​ConfigurationSchema.json Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​Recursive.RestClient.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​Models/​UnknownRecursivePet.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​Models/​UnknownInjectedPet.Serialization.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​Models/​UnknownInjectedPet.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​Models/​UnknownExplicitPet.Serialization.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​Models/​UnknownExplicitPet.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​Models/​UnknownEnumPet.Serialization.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​Models/​UnknownEnumPet.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​Models/​UnknownCustomPet.Serialization.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​Models/​UnknownCustomPet.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​Models/​RecursivePet.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​Models/​RecursiveDog.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​Models/​RecursiveCat.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​Models/​PetKind.Serialization.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​Models/​PetKind.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​Models/​Mammal.Serialization.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​Models/​Mammal.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​Models/​InjectedPet.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​Models/​InjectedDog.Serialization.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​Models/​InjectedDog.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​Models/​InjectedCat.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​Models/​ExplicitPet.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​Models/​ExplicitDog.Serialization.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​Models/​ExplicitDog.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​Models/​ExplicitCat.Serialization.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​Models/​ExplicitCat.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​Models/​EnumPet.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​Models/​EnumDog.Serialization.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​Models/​EnumDog.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​Models/​EnumCat.Serialization.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​Models/​EnumCat.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​Models/​CustomPet.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​Models/​CustomDog.Serialization.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​Models/​CustomDog.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​Models/​CustomCat.Serialization.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​Models/​CustomCat.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​Models/​_TypeUnionDiscriminatedExtendsContext.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​Internal/​Utf8JsonBinaryContent.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​Internal/​SerializationFormat.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​Internal/​PipelineRequestHeadersExtensions.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​Internal/​Optional.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​Internal/​ErrorResult.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​Internal/​CodeGenTypeAttribute.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​Internal/​CodeGenSuppressAttribute.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​Internal/​CodeGenSerializationAttribute.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​Internal/​CodeGenMemberAttribute.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​Internal/​ClientPipelineExtensions.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​Internal/​ChangeTrackingList.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​Internal/​ChangeTrackingDictionary.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​Internal/​CancellationTokenExtensions.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​Internal/​BinaryContentHelper.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​Internal/​Argument.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​InjectedDiscriminatorOperations.RestClient.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​InjectedDiscriminator.RestClient.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​InjectedDiscriminator.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​ExtendsClientSettings.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​ExtendsClientOptions.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​ExtendsClient.RestClient.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​ExtendsClient.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​ExplicitDiscriminatorOperations.RestClient.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​ExplicitDiscriminator.RestClient.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​ExplicitDiscriminator.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​EnumDiscriminatorOperations.RestClient.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​EnumDiscriminator.RestClient.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​EnumDiscriminator.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​CustomDiscriminatorOperations.RestClient.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​CustomDiscriminator.RestClient.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​src/​Generated/​CustomDiscriminator.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​Configuration.json Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​type/​union/​discriminated/​extends/​client.tsp Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector/​http/​azure/​client-generator-core/​response-replacement/​tspCodeModel.json Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector.Tests/​TestProjects.Spector.Tests.csproj Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Spector.Tests/​Http/​_Type/​Union/​Discriminated/​Extends/​UnionExtendsTests.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Local/​Sample-TypeSpec/​tspconfig.yaml Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Local/​Sample-TypeSpec/​src/​Generated/​UnionExtends.RestClient.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Local/​Sample-TypeSpec/​src/​Generated/​SampleTypeSpecModelFactory.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Local/​Sample-TypeSpec/​src/​Generated/​SampleTypeSpecClient.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Local/​Sample-TypeSpec/​src/​Generated/​Models/​UnionPetContainer.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Local/​Sample-TypeSpec/​src/​Generated/​Models/​UnionPet.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Local/​Sample-TypeSpec/​src/​Generated/​Models/​UnionDog.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Local/​Sample-TypeSpec/​src/​Generated/​Models/​UnionCat.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Local/​Sample-TypeSpec/​src/​Generated/​Models/​SampleTypeSpecContext.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​TestProjects/​Local/​Sample-TypeSpec/​Sample-TypeSpec.tsp Updated as part of this pull request.
packages/​http-client-csharp/​generator/​Microsoft.TypeSpec.Generator/​src/​TypeFactory.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​Microsoft.TypeSpec.Generator/​src/​Providers/​ModelProvider.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​Microsoft.TypeSpec.Generator/​src/​Properties/​launchSettings.json Updated as part of this pull request.
packages/​http-client-csharp/​generator/​Microsoft.TypeSpec.Generator/​src/​Primitives/​PropertyWireInformation.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​Microsoft.TypeSpec.Generator.Input/​src/​InputTypes/​Serialization/​InputUnionTypeConverter.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​Microsoft.TypeSpec.Generator.Input/​src/​InputTypes/​Serialization/​InputNamespaceConverter.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​Microsoft.TypeSpec.Generator.Input/​src/​InputTypes/​InputUnionType.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​Microsoft.TypeSpec.Generator.Input/​src/​InputTypes/​InputNamespace.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​Microsoft.TypeSpec.Generator.ClientModel/​test/​Providers/​TestData/​DiscriminatedUnionSerializationTests/​WritesContextualEnvelopeSerialization(type,data).cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​Microsoft.TypeSpec.Generator.ClientModel/​test/​Providers/​TestData/​DiscriminatedUnionSerializationTests/​WritesContextualEnvelopeSerialization(kind,value).cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​Microsoft.TypeSpec.Generator.ClientModel/​test/​Providers/​MrwSerializationTypeDefinitions/​DiscriminatorTests.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​Microsoft.TypeSpec.Generator.ClientModel/​src/​Providers/​ScmModelProvider.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​Microsoft.TypeSpec.Generator.ClientModel/​src/​Providers/​ScmMethodProviderCollection.cs Updated as part of this pull request.
packages/​http-client-csharp/​generator/​Microsoft.TypeSpec.Generator.ClientModel/​src/​Providers/​MrwSerializationTypeDefinition.cs Updated as part of this pull request.
packages/​http-client-csharp/​eng/​scripts/​Generation.psm1 Updated as part of this pull request.
packages/​http-client-csharp/​eng/​scripts/​Generate.ps1 Updated as part of this pull request.
packages/​http-client-csharp/​emitter/​test/​Unit/​utils/​test-util.ts Updated as part of this pull request.
packages/​http-client-csharp/​emitter/​src/​type/​input-type.ts Updated as part of this pull request.
packages/​http-client-csharp/​emitter/​src/​type/​code-model.ts Updated as part of this pull request.
packages/​http-client-csharp/​emitter/​src/​lib/​type-converter.ts Updated as part of this pull request.
packages/​http-client-csharp/​emitter/​src/​lib/​client-model-builder.ts Updated as part of this pull request.

Review effort: Balanced

…iants

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 5, 2026 20:57

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.

🟡 Changes recommended

Critical generator defects can produce uncompilable SDKs and broken union handling through duplicate signatures, unsuppressed experimental references, abstract payload deserialization, and incorrect JSONL serialization and parsing.

5 open issues
1 resolved since last review
1 file not reviewed
  • packages/http-client-csharp/package-lock.json: Generated file

Review effort: Balanced

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 5, 2026 22:27

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.

🟡 Changes recommended

Critical issues in alternate-type mappings, inherited union helpers, and XML deserialization can prevent generated SDK compilation, while JSONL byte serialization can emit invalid JSON.

9 open issues
1 resolved since last review
1 file not reviewed
  • packages/http-client-csharp/package-lock.json: Generated file

Review effort: Balanced

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 9, 2026 22:23
@JoshLove01

Copy link
Copy Markdown
Contributor

Reserve helper names from non-generated CLR ancestors

Fixed in a08bc7e: helper-name allocation now reserves properties, fields, and methods throughout the resolved hand-written CLR ancestry, not only input/generated models. Added a multi-level ancestor regression and a generated sample that compiles with protected conflicting members.

Keep non-JSON union responses off the JSON envelope path

Fixed in the same commit: non-JSON union responses now return raw BinaryData and bypass JSON parsing in both sync and async convenience methods, including collection responses. JSON and +json media types retain envelope deserialization; mixed JSON/non-JSON response types use the raw-data path. Added content-type coverage and a generated XML response runtime regression.

--generated by Copilot

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.

🔵 Needs a closer look

Shared constructor generation and external-base serialization changes affect existing hierarchies beyond union-extends, warranting human compatibility review and a full .NET regression run beyond the reported scoped validation.

No open issues 🎉

1 file not reviewed
  • packages/http-client-csharp/package-lock.json: Generated file

Review effort: Balanced

@jorgerangel-msft

Copy link
Copy Markdown
Contributor Author

[P2] Preserve raw-data handling for non-JSON union requests

ScmMethodProviderCollection.cs:406-411

An operation accepting @body pet: Pets with @header contentType: "application/xml" skips envelope serialization but still exposes Pet, so the generated convenience method forwards it directly to the protocol method expecting BinaryContent. I reproduced CS1503 in both sync and async methods; please retain the raw-data fallback for non-JSON requests, as the response path now does.

🤖 Generated by Jorge's Copilot

@jorgerangel-msft

Copy link
Copy Markdown
Contributor Author

[P2] Allow unrelated models to be omitted during helper-name allocation

DiscriminatedUnionSerialization.cs:142-160

The new throwing GetModelType lookup runs against every input model here and in the descendant scan below, so a generator plugin returning null from CreateModelCore for an unrelated model now aborts union generation. I reproduced InvalidOperationException: Unable to resolve C# type for union model 'omitted'. even though that model is neither the union base nor a variant; please tolerate nullable lookups in candidate scans and reserve hard failures for required union participants.

🤖 Generated by Jorge's Copilot

Map non-JSON union request bodies to BinaryData and keep envelope serialization JSON-only. Tolerate omitted models during helper-name candidate scans while retaining checked resolution for required participants.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 9, 2026 23:27
@JoshLove01

Copy link
Copy Markdown
Contributor

Preserve raw-data handling for non-JSON union requests

Fixed in 020c998: non-JSON union request bodies now expose BinaryData and use the existing raw BinaryContent.Create conversion instead of passing a model or writing a JSON envelope. JSON and +json requests retain typed envelope serialization; mixed media types use raw data. Added sync/async content-type and collection coverage plus a generated XML request/response round-trip regression.

Allow unrelated models to be omitted during helper-name allocation

Fixed in the same commit: ancestor/descendant candidate scans tolerate null factory results, and omitted providers are skipped when collecting member names. Required union base and variant resolution still has explicit checks. Added a plugin-style regression that omits an unrelated input model.

--generated by Copilot

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

No active review issues are reported for the C# discriminated-union support changes.

No open issues 🎉

1 file not reviewed
  • packages/http-client-csharp/package-lock.json: Generated file

Review effort: Balanced

Preserve union event handling alongside upstream deprecation metadata support.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 12, 2026 09:11

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

There are no active review issues requiring changes.

No open issues 🎉

1 file not reviewed
  • packages/http-client-csharp/package-lock.json: Generated file

Review effort: Balanced

Take main's stable TCGC 0.74.0 / TypeSpec 1.18.0 pins and lockfile. Re-enable the discriminated/extends Spector scenario that main marked as pending, since this PR implements it.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 13, 2026 19:52

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

No active review issues are recorded for the C# discriminated-union inheritance changes.

No open issues 🎉

Review effort: Balanced

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

LGTM

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 13, 2026 20:02

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

No active review issues are recorded for the C# tagged-union support change.

No open issues 🎉

Review effort: Balanced

@JoshLove01
JoshLove01 enabled auto-merge November 13, 2026 20:38
@JoshLove01
JoshLove01 added this pull request to the merge queue Nov 13, 2026
Merged via the queue into microsoft:main with commit e6d27e5 Nov 13, 2026
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants