Fix MPG generator to emit model factory methods for models with flattened read-only properties #54447
+19
−6
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.
Description
The MPG generator was not emitting model factory methods for models with flattened read-only properties. Models like
QuotaAllocationRequestBasethat have internal nested properties (Properties.Name) with read-only flattened accessors (Value,LocalizedValue) were incorrectly excluded from model factory generation, requiring custom workaround code.Root cause: Model factory eligibility was determined during
ModelFactoryVisitor.VisitType()beforeFlattenPropertyVisitorhad processed all models. Models were evaluated pre-flattening and incorrectly excluded.Changes made:
EnsureModelTypesBuilt()to allow explicit invocation after all model transformationsPostVisitType()and explicitly callsEnsureModelTypesBuilt()to ensure eligibility is evaluated after flattening completesExample impact:
SDK teams can now remove custom model factory workarounds after regeneration.
This checklist is used to make sure that common guidelines for a pull request are followed.
General Guidelines
Testing Guidelines
SDK Generation Guidelines
*.csprojandAssemblyInfo.csfiles have been updated with the new version of the SDK.Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
www.powershellgallery.com/usr/bin/pwsh pwsh eng/common/scripts/TypeSpec-Project-Generate.ps1 sdk/quota/Azure.ResourceManager.Quota -client-csharp-mgmt/generator/TestProjects/Local/Mgmt-TypeSpec/tspconfig.yaml tion�� re-sdk-for-net/azure-sdk-for-net/eng/packages/http-client-csharp-mgmt/generator/TestProjects/Locbash k/azure-sdk-for-net/azure-sdk-for-net/sdk/postgr/home/REDACTED/work/azure-sdk-for-net/azure-sdk-fo--norc /opt/pipx_bin/grep ryProvider eSql/Generated/M/usr/local/bin/npx grep grep .Ser�� ryProvider k/azure-sdk-for-@azure-typespec/http-client-csharp-mgmt ndor/bin/sh ryProvider reSql/src/Postgr--norc rgo/bin/grep ns.cs(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.