Add SystemObjectModelProvider for non-generated base type customization#9862
Open
live1206 wants to merge 18 commits into
Open
Add SystemObjectModelProvider for non-generated base type customization#9862live1206 wants to merge 18 commits into
live1206 wants to merge 18 commits into
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>
Remove BuildProperties() => [] and BuildConstructors() => [] overrides so that SystemObjectModelProvider builds properties and constructors from its input model. This allows derived models to correctly include base class parameters (e.g., id, name, resourceType, systemData, tags, location) in their constructors and generate proper :base() initializer calls. Without this fix, derived models lose all base class constructor parameters because the empty overrides make the base model invisible to the constructor building logic in ModelProvider.BuildConstructorParameters(). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Access _inputModel directly in BuildProperties() since private members are accessible within the declaring class on any instance. This avoids adding unnecessary public API surface. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Fold base model provider changes into ModelProvider.Update() instead of a separate public SetBaseModelProvider() method. This follows the existing Update() pattern and automatically resets dependent members when the base model changes. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…-model-provider Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…er' into feature/system-object-model-provider
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
| { | ||
| outputProperty.Modifiers |= MethodSignatureModifiers.New; | ||
| var fieldName = $"_{baseProperty.Name.ToVariableName()}"; | ||
| var fieldName = $"_{baseProperty.Property.Name.ToVariableName()}"; |
Contributor
There was a problem hiding this comment.
why are there so many changes here? Can we also get a regen preview please?
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, aModelProvidersubclass for input models that map to existing framework/system model types such asTrackedResourceDataandResourceData. This lets downstream generators, especially the Azure Management generator, use non-generated framework types as model bases while still allowing the base generator to reason about inherited properties, constructors, and serialization.Key changes
SystemObjectModelProviderCSharpTypeplus theInputModelTypeit replaces.ModelProvider, unlikeSystemObjectTypeProvider, so it can be used asBaseModelProviderfor generated derived models.SystemTypeandCrossLanguageDefinitionIdfor downstream generator logic.id,name,resourceType,systemData,tags, andlocation.Model inheritance handling
ModelProvider.BuildBaseModelProvider()now resolves customized base types throughBaseType, including generated-model customizations and a name+namespace fallback for framework/non-frameworkCSharpTypeequality differences.ModelProvider.Update(...)now acceptsbaseModelProvider, replacing the earlier dedicated setter API and resetting cached members when the base changes.SystemObjectModelProviderbase chain, so derived generated models do not re-emit framework-owned properties.SystemObjectModelProviderbases.Constructor initializer fix
: base(location0)when the actual constructor parameter islocation.Motivation
The Azure Management generator has ARM resource models that inherit from framework types such as
TrackedResourceDataandResourceData. Previously it needed a localInheritableSystemObjectModelProviderwith custom constructor and property handling. Moving this capability into the shared generator lets downstream generators reuse normalModelProviderbehavior for inheritance, property deduplication, serialization modifiers, and constructor generation.Validation
npm run build:generatorinpackages/http-client-csharppasses.eng/packages/http-client-csharp-mgmt/eng/scripts/Generate.ps1completed successfully.dotnet test eng/packages/http-client-csharp-mgmt/generator/Azure.Generator.Management/test/Azure.Generator.Mgmt.Tests.csprojpassed: 194/194 tests.Companion PR