Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 11, 2025

Description

The MPG generator was not emitting model factory methods for models with flattened read-only properties. Models like QuotaAllocationRequestBase that 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() before FlattenPropertyVisitor had processed all models. Models were evaluated pre-flattening and incorrectly excluded.

Changes made:

  • ManagementOutputLibrary.cs: Exposed EnsureModelTypesBuilt() to allow explicit invocation after all model transformations
  • ModelFactoryVisitor.cs: Deferred filtering to PostVisitType() and explicitly calls EnsureModelTypesBuilt() to ensure eligibility is evaluated after flattening completes

Example impact:

// Previously missing, now auto-generated:
public static QuotaAllocationRequestBase QuotaAllocationRequestBase(
    long? limit = null, 
    string value = null,           // flattened from Properties.Name.Value
    string localizedValue = null,  // flattened from Properties.Name.LocalizedValue
    string region = null)
{
    return new QuotaAllocationRequestBase(
        new QuotaAllocationRequestBaseProperties(
            limit, 
            new QuotaAllocationRequestBasePropertiesName(value, localizedValue, null), 
            region, 
            null), 
        null);
}

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

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.

Testing Guidelines

  • Pull request includes test coverage for the included changes.

SDK Generation Guidelines

  • If an SDK is being regenerated based on a new swagger spec, a link to the pull request containing these swagger spec changes has been included above.
  • The generate.cmd file for the SDK has been updated with the version of AutoRest, as well as the commitid of your swagger spec or link to the swagger spec, used to generate the code.
  • The *.csproj and AssemblyInfo.cs files 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
    • Triggering command: /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

This section details on the original issue you should resolve

<issue_title>Method missing in ModelFactory with new MPG generator</issue_title>
<issue_description>While generate SDK for Azure.ResourceManager.Quota, QuotaAllocationRequestBase is missing.
Added it back with custom code for now in

// Will remove this custom code while https://github.com/Azure/azure-sdk-for-net/issues/54298 is fixed.
/// <summary> Initializes a new instance of <see cref="Models.QuotaAllocationRequestBase"/>. </summary>
/// <param name="limit"> The new quota limit for the subscription. The incremental quota will be allocated from pre-approved group quota. </param>
/// <param name="value"> Resource name. </param>
/// <param name="localizedValue"> Resource display name. </param>
/// <param name="region"> The location for which the subscription is allocated. </param>
/// <returns> A new <see cref="Models.QuotaAllocationRequestBase"/> instance for mocking. </returns>
public static QuotaAllocationRequestBase QuotaAllocationRequestBase(long? limit = null, string value = null, string localizedValue = null, string region = null)
{
return new QuotaAllocationRequestBase(new QuotaAllocationRequestBaseProperties(limit, new QuotaAllocationRequestBasePropertiesName(value, localizedValue, additionalBinaryDataProperties: null), region, additionalBinaryDataProperties: null), additionalBinaryDataProperties: null);
}
</issue_description>

<agent_instructions>Investigate why the method is missing from generated model factory. The goal is to fix MPG generator to generate it and remove the custom code.</agent_instructions>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Fix missing method in ModelFactory for MPG generator Fix MPG generator to emit model factory methods for models with flattened read-only properties Dec 11, 2025
Copilot AI requested a review from live1206 December 11, 2025 09:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Method missing in ModelFactory with new MPG generator

2 participants