Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 31, 2025

The management generator incorrectly promoted path parameters like subscriptionId and resourceProviderName to constructor fields in collection classes when they should remain as method parameters. This occurred for resources accessed across scope boundaries (e.g., ManagementGroup accessing per-subscription resources).

Changes

Added scope transition detection (HasScopeTransition)

  • Detects when subscriptionId appears in path after non-subscription parent
  • When detected, all intermediate path parameters remain as method parameters
  • Prevents incorrect field promotion for cross-scope resource access

Added parameter-specific rules (ShouldParameterRemainAsMethodParameter)

  • subscriptionId: method parameter when parent is not subscription-scoped
  • resourceProviderName: always method parameter (filtering/scoping parameter)

Refactored scope checking (IsParentSubscriptionScoped)

  • Extracted common subscription-scope checking logic

Example

For path /providers/Microsoft.Management/managementGroups/{managementGroupId}/subscriptions/{subscriptionId}/providers/Microsoft.Quota/groupQuotas/{groupQuotaName}/resourceProviders/{resourceProviderName}/quotaAllocations/{location}:

Before: subscriptionId, groupQuotaName, resourceProviderName as constructor parameters

internal SubscriptionQuotaAllocationsListCollection(ArmClient client, ResourceIdentifier id, 
    string subscriptionId, string groupQuotaName, string resourceProviderName)

After: All as method parameters

internal SubscriptionQuotaAllocationsListCollection(ArmClient client, ResourceIdentifier id)

public Task<Response<T>> GetAsync(string subscriptionId, string groupQuotaName, 
    string resourceProviderName, AzureLocation location, ...)

Aligns with autorest.csharp behavior. Fixes Azure.ResourceManager.Quota SDK generation.

Original prompt

This section details on the original issue you should resolve

<issue_title>subscriptionId should be generated as method parameter</issue_title>
<issue_description>while onboarding Azure.ResourceManager.Quota to new mpg generator, subscriptionId was generated as client field in resourceCollection:

internal SubscriptionQuotaAllocationsListCollection(ArmClient client, ResourceIdentifier id, string managementGroupId, string subscriptionId, string groupQuotaName, string resourceProviderName) : base(client, id)

the expecting constructor should be
internal SubscriptionQuotaAllocationsListCollection(ArmClient client, ResourceIdentifier id) : base(client, id)

The original logic of populating additional constructor parameter in autorest.csharp is https://github.com/Azure/autorest.csharp/blob/d93297d16162903b0f2647f890a5db99535e2009/src/AutoRest.CSharp/Mgmt/Output/ResourceCollection.cs#L81-L132

refine the mgmt generator to align with autorest.csharp</issue_description>

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

@live1206 `resourceProviderName` should be method parameter instead of client parameter as well https://github.com/Azure/azure-sdk-for-net/blob/f9bc06044da09ca30956c242c9eb887ce5833e05/sdk/quota/Azure.ResourceManager.Quota/src/Generated/GroupQuotasEnforcementStatusCollection.cs#L44

✨ 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 and others added 3 commits October 31, 2025 03:31
…lectionClientProvider

Added logic to prevent subscriptionId and resourceProviderName from becoming constructor parameters when they should be method parameters. These parameters identify individual resources in a collection rather than the collection's scope.

Co-authored-by: live1206 <[email protected]>
Added HasScopeTransition method to detect when subscriptionId appears after non-subscription parent, ensuring all subsequent parameters remain as method parameters rather than constructor parameters.

Co-authored-by: live1206 <[email protected]>
… duplication

Extracted duplicated subscription-scope checking logic into a separate method to improve code maintainability and consistency.

Co-authored-by: live1206 <[email protected]>
Copilot AI changed the title [WIP] Fix subscriptionId generation as method parameter Fix path parameter generation for cross-scope collection resources Oct 31, 2025
Copilot AI requested a review from live1206 October 31, 2025 03:43
Copilot finished work on behalf of live1206 October 31, 2025 03:43
@live1206 live1206 closed this Nov 10, 2025
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.

subscriptionId should be generated as method parameter

2 participants