Add SystemObjectModelProvider for non-generated base type customization#9862
Draft
live1206 wants to merge 6 commits intomicrosoft:mainfrom
Draft
Add SystemObjectModelProvider for non-generated base type customization#9862live1206 wants to merge 6 commits intomicrosoft:mainfrom
live1206 wants to merge 6 commits intomicrosoft:mainfrom
Conversation
…ed fallback Add SystemObjectModelProvider extending ModelProvider for downstream generators that map input models to existing framework types (e.g., ARM Resource to ResourceData). Unlike SystemObjectTypeProvider which extends TypeProvider, this class can serve as BaseModelProvider for derived models. Fix BuildBaseModelProvider() to use name+namespace based CSharpTypeMap fallback when strict CSharpType equality fails. This resolves the case where custom code overrides a base type to an external type (e.g., TrackedResourceData) but the CSharpTypeMap lookup fails due to framework vs non-framework CSharpType mismatch. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ObjectModelProvider - Added CrossLanguageDefinitionId property (from input model) to support downstream generators that need to check the cross-language definition ID - Fixed BuildName() null safety: _systemType may be null when called from base constructor before field assignment (same pattern as BuildNamespace) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
commit: |
Contributor
|
No changes needing a change description found. |
live1206
added a commit
to live1206/azure-sdk-for-net
that referenced
this pull request
Mar 2, 2026
…ovider from upstream Use SystemObjectModelProvider from Microsoft.TypeSpec.Generator instead of the local InheritableSystemObjectModelProvider. This aligns with the upstream PR microsoft/typespec#9862 which adds SystemObjectModelProvider to the base generator. - ManagementTypeFactory: create SystemObjectModelProvider(replacedType, model) - InheritableSystemObjectModelVisitor: swap all type checks and property access - NameVisitor: use SystemObjectModelProvider pattern match - ManagementOutputLibrary: filter SystemObjectModelProvider Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…zation, and constructors - SystemObjectModelProvider now returns empty for BuildProperties, BuildFields, BuildSerializationProviders, BuildConstructors, and null for BuildRawDataField - ModelProvider.BuildProperties skips base properties when base chain includes SystemObjectModelProvider - ModelProvider.BuildRawDataField changed to protected virtual - MrwSerializationTypeDefinition uses virtual (not override) for create/persist methods when base is SystemObjectModelProvider This enables downstream generators (mgmt) to handle framework type bases natively without post-processing visitors. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Tests demonstrate capabilities that SystemObjectModelProvider provides that are missing from SystemObjectTypeProvider: 1. Type hierarchy: SystemObjectModelProvider extends ModelProvider (not TypeProvider), so it can serve as BaseModelProvider for derived models 2. Property deduplication: derived models skip properties defined in framework base 3. Raw data field: SystemObjectModelProvider returns null, derived models create own 4. Empty members: no generated properties/fields/constructors/serialization 5. Serialization modifiers: correct virtual vs override for 4 serialization methods 6. Name/namespace from system CSharpType Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…se property dedup from SystemObjectModelProvider chain - SetBaseModelProvider: public method allowing visitors to replace a model's base - Reset override: clears rawDataField, additionalPropertyFields/Properties, fullConstructor - InputModel property: exposes the private _inputModel field for external use - BuildProperties: when base is SystemObjectModelProvider, also includes base properties from its InputModel chain for proper dedup when custom code overrides base type Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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
Fixes #9234
Adds
SystemObjectModelProvider, a newModelProvidersubclass that represents model types from external/system assemblies (e.g.,TrackedResourceData,ResourceData) that are mapped from input model types. This enables downstream generators (like the Azure Management generator) to customize base types of generated models to non-generated framework types.Changes
New:
SystemObjectModelProviderModelProvider(notTypeProviderlike the existingSystemObjectTypeProvider)CSharpType(the system/framework type) and anInputModelType(the input model it replaces)SystemTypeproperty for accessing the underlying framework typeCrossLanguageDefinitionIdproperty for downstream generators that need to identify the modelBuildName()andBuildNamespace()since_systemTypemay be null when called from base constructor before field assignmentInvalidOperationExceptionfromBuildRelativeFilePath()since this type should never be written during generationFix:
ModelProvider.BuildBaseModelProvider()name-based fallbackCSharpTypeMap, framework CSharpTypes (fromtypeof()) and non-framework CSharpTypes (fromModelProvider) have different equality semantics — they hash to the same bucket but failEquals()because_typediffersCSharpTypeMapvalues when the direct lookup fails, ensuringSystemObjectModelProviderentries are found correctlyMotivation
In the Azure Management generator, ARM resource models inherit from system types like
TrackedResourceDataorResourceData. Previously, this required a localInheritableSystemObjectModelProviderclass. By addingSystemObjectModelProviderto the base generator, downstream generators can use it directly and the base generator can eventually handle property deduplication, serialization modifiers, and constructor updates natively for system model bases.Testing
SystemObjectModelProviderinstead of the localInheritableSystemObjectModelProvider