Fix system model base provider resolution - #11585
Open
Wei Hu (live1206) wants to merge 1 commit into
Open
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
commit: |
Contributor
|
No changes needing a change description found. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes base model provider resolution for SystemObjectModelProvider when the wrapped framework type has an existing CLR base type, ensuring the corresponding declared TypeSpec base model provider is created/resolved and registered for subsequent lookups.
Changes:
- Updates
ModelProvider.BuildBaseModelProvider()to fall back to creating the declared input base model provider when no mapped provider exists for the resolved CLR base type, and to register aCSharpTypeMapalias when the types match by name. - Adds a regression test covering automatic system base-provider creation across an input model hierarchy (
ArgumentException/SystemException).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Providers/ModelProvider.cs | Adds a fallback that creates the declared input base model provider and aliases the resolved CLR base CSharpType to it when they match by name. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/SystemObjectModelProviderTests.cs | Adds a regression test verifying base system providers are created/resolved from the input model inheritance chain. |
Contributor
Author
Arthur Ma (ArthurMa1978)
approved these changes
Aug 10, 2026
Jorge Rangel (jorgerangel-msft)
approved these changes
Aug 10, 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.
Summary
Ensure MTG creates and resolves the corresponding input base model provider when a
SystemObjectModelProviderwraps a framework type with an existing CLR base type.SystemObjectModelProvider.BuildBaseType()prefersSystemType.BaseType, so the normalModelProvider.BuildBaseType()path does not create the declared TypeSpec base model.BuildBaseModelProvider()previously only checkedCSharpTypeMap, which could leave the base providernulldepending on model creation order.The fallback now:
CSharpTypealias for subsequent lookups.Added a regression test using
ArgumentExceptionandSystemExceptionto cover both automatic system base-provider creation and framework/non-frameworkCSharpTypeequivalence.Contributes to #10787.
Validation
SystemObjectModelProviderTests: 27 passednpm run test:generatorMgmt-TypeSpec-MultiService