Skip to content

Fix inherited discriminator resolution in C# model factories - #12157

Draft
JoshLove-msft with Copilot wants to merge 3 commits into
mainfrom
copilot/http-client-csharp-fix-discriminator-resolution
Draft

JoshLove-msft with Copilot wants to merge 3 commits into
mainfrom
copilot/http-client-csharp-fix-discriminator-resolution

Conversation

Copilot AI commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

When three inheritance levels share a discriminator property, leaf factories select the intermediate model’s value, causing serialization to emit the wrong discriminator and base-type readers to lose the concrete type.

  • Property-specific resolution: Select the most-derived value applicable to each discriminator property. Keep root and nested discriminators separate and use the declaring property’s enum mapping.
  • Constructor initialization: Share resolution with factory generation and initialize inherited discriminators when intermediate constructors cannot accept them. Preserve customized get-only and private-set properties.
  • Regression coverage: Cover required/optional properties, fixed/extensible enums, customized enum members, separate discriminators, and read-only customizations.

The leaf factory now selects its own enum member rather than PrometheusEnrichmentItem:

return new PrometheusInstantQuery(
    AlertsManagementType.PrometheusInstantQuery,
    additionalBinaryDataProperties: null);

The public property-specific resolver is available for downstream management constructor repair; that helper is outside this repository.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
1 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@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 Oct 12, 2026
Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix discriminator resolution for leaf models in model factories Fix inherited discriminator resolution in C# model factories Oct 12, 2026
Copilot AI requested a review from JoshLove-msft October 12, 2026 22:00

This branch has not been deployed

No deployments
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.

[http-client-csharp] Model factories use intermediate discriminator for leaf models sharing an inherited discriminator

2 participants