Commit be01338
Add SystemObjectModelProvider for non-generated base type customization (#9862)
## Summary
Fixes #9234
Adds `SystemObjectModelProvider`, a `ModelProvider` subclass for input
models that map to existing framework/system model types such as
`TrackedResourceData` and `ResourceData`. This lets downstream
generators, especially the Azure Management generator, use non-generated
framework types as model bases while still allowing the shared generator
to reason about inherited properties, constructors, and serialization.
## Key changes
### `SystemObjectModelProvider`
- Represents a framework/system model type using a `CSharpType` plus the
`InputModelType` it replaces.
- Extends `ModelProvider`, unlike `SystemObjectTypeProvider`, so it can
be used as `BaseModelProvider` for generated derived models.
- Exposes `SystemType` and `CrossLanguageDefinitionId` for downstream
generator logic.
- Uses the framework type name/namespace and never writes a generated
file.
- Builds properties and constructors from the input model so derived
models can correctly reason about inherited constructor parameters such
as `id`, `name`, `resourceType`, `systemData`, `tags`, and `location`.
- Does not generate fields, serialization providers, or a raw data field
because the framework type owns those implementation details.
- Resets cached provider state after assigning the wrapped `CSharpType`,
because the base constructor can evaluate cached type metadata before
the derived field is assigned.
### Base-provider and inheritance handling
- `ModelProvider.BuildBaseModelProvider()` is now `protected virtual`,
so customized base-provider resolution can be specialized without adding
a broad `Update(baseModelProvider)` mutation API.
- Removed the `Update(baseModelProvider)` path that could create
ambiguous call sites with the existing `Update(...)` method.
- `BuildBaseModelProvider()` resolves customized base types through
`BaseType`, including generated-model customizations and a
name+namespace fallback for framework/non-framework `CSharpType`
equality differences.
- Added provider hooks for base-provider-specific generated behavior:
- `ShouldSkipDerivedModelProperties` for framework-owned properties that
should not be re-emitted by derived models.
- `ShouldSkipDerivedSerializationMethodOverrides` for serialization
methods that should remain virtual instead of overriding framework-owned
methods.
- Property generation now tracks normal base properties separately from
skipped base property names. This avoids concrete
`SystemObjectModelProvider` checks and preserves multi-layer inheritance
behavior: properties owned by a skipped framework base are omitted,
while properties owned by an intermediate generated base can still drive
normal `override`/`new` behavior.
- Raw-data and serialization behavior now accounts for
`SystemObjectModelProvider` bases through provider hooks instead of
concrete type checks in common paths.
### Constructor initializer fix
- Fixed base constructor initializer argument selection after public
input parameters are substituted. This prevents generated code like `:
base(location0)` when the actual constructor parameter is `location`.
## Motivation
The Azure Management generator has ARM resource models that inherit from
framework types such as `TrackedResourceData` and `ResourceData`.
Previously it needed a local `InheritableSystemObjectModelProvider` with
custom constructor and property handling. Moving this capability into
the shared generator lets downstream generators reuse normal
`ModelProvider` behavior for inheritance, property deduplication,
serialization modifiers, and constructor generation while keeping
management-specific wiring in the management generator.
## Validation
TypeSpec / MTG validation:
- `npm run build:generator` in `packages/http-client-csharp` passed.
- `SystemObjectModelProviderTests` passed.
- `SystemObjectModelSerializationTests` passed.
- Fixed the CI failure in
`JsonModelWriteCore_IsOverride_WhenBaseIsSystemObject` by keeping JSON
write-core overrides independent from the hook that suppresses
persistable/create-core overrides.
Azure SDK / MPG validation with the companion PR and local
`C:\src\typespec` checkout:
- `eng/packages/http-client-csharp-mgmt/eng/scripts/Generate.ps1`
completed successfully.
- `dotnet test
eng/packages/http-client-csharp-mgmt/generator/Azure.Generator.Management/test/Azure.Generator.Mgmt.Tests.csproj`
passed: 194/194 tests.
- Regenerated two real management-plane SDKs with local MTG + local MPG
generator:
- `Azure.ResourceManager.Advisor`
- `Azure.ResourceManager.CloudHealth`
- Both selected SDK regenerations completed successfully (`2 passed, 0
failed`) and both regenerated packages built successfully.
## Companion PR
- SDK: Azure/azure-sdk-for-net#56634
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent 1e5f02d commit be01338
5 files changed
Lines changed: 757 additions & 21 deletions
File tree
- packages/http-client-csharp/generator
- Microsoft.TypeSpec.Generator.ClientModel
- src/Providers
- test/Providers/MrwSerializationTypeDefinitions
- Microsoft.TypeSpec.Generator
- src/Providers
- test/Providers
Lines changed: 5 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
| 69 | + | |
69 | 70 | | |
70 | 71 | | |
71 | 72 | | |
| |||
91 | 92 | | |
92 | 93 | | |
93 | 94 | | |
| 95 | + | |
94 | 96 | | |
95 | 97 | | |
96 | 98 | | |
| |||
482 | 484 | | |
483 | 485 | | |
484 | 486 | | |
485 | | - | |
| 487 | + | |
486 | 488 | | |
487 | 489 | | |
488 | 490 | | |
| |||
506 | 508 | | |
507 | 509 | | |
508 | 510 | | |
509 | | - | |
| 511 | + | |
510 | 512 | | |
511 | 513 | | |
512 | 514 | | |
| |||
554 | 556 | | |
555 | 557 | | |
556 | 558 | | |
557 | | - | |
| 559 | + | |
558 | 560 | | |
559 | 561 | | |
560 | 562 | | |
| |||
Lines changed: 205 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
0 commit comments