Skip to content

Multi-level discriminator handling improvements#9119

Merged
radhgupta merged 16 commits intomicrosoft:mainfrom
radhgupta:hierarchyBuilding
Dec 5, 2025
Merged

Multi-level discriminator handling improvements#9119
radhgupta merged 16 commits intomicrosoft:mainfrom
radhgupta:hierarchyBuilding

Conversation

@radhgupta
Copy link
Member

@radhgupta radhgupta commented Dec 1, 2025

This pull request refines the logic for handling multi-level discriminators in model constructor initialization within ModelProvider.cs. The changes ensure more accurate passing of discriminator parameters in complex inheritance scenarios, improving both correctness and maintainability.

Multi-level discriminator handling improvements

  • Updated the logic to check whether the current model or base model uses a multi-level discriminator, ensuring the correct constructor is called and the appropriate discriminator value is passed in multi-level inheritance scenarios.
  • Enhanced the handling of discriminator parameters: now, when initializing constructors, the code attempts to pass through the discriminator parameter from the base model if available, otherwise falls back to using the current model's discriminator value.
  • Improved the logic in GetExpressionForCtor to correctly decide when to pass through the discriminator parameter or use the model's own discriminator value, based on whether the model is part of a multi-level discriminator hierarchy.

Constructor initialization logic

  • Ensured that base constructor calls are properly made even when there are no base parameters, maintaining correct inheritance behavior.

@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 Dec 1, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Dec 1, 2025

No changes needing a change description found.

@radhgupta radhgupta changed the title Hierarchy building Multi-level discriminator handling improvements Dec 1, 2025
@radhgupta radhgupta marked this pull request as ready for review December 1, 2025 21:31
@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 3, 2025

Open in StackBlitz

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

commit: 4ad4a9c

@azure-sdk
Copy link
Collaborator

azure-sdk commented Dec 3, 2025

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

@radhgupta radhgupta added this pull request to the merge queue Dec 5, 2025
Merged via the queue into microsoft:main with commit e235fbd Dec 5, 2025
37 checks passed
@radhgupta radhgupta deleted the hierarchyBuilding branch December 5, 2025 21:39
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