Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 17, 2025

Description

The management generator was not processing extension non-resource methods, which prevented these methods from being generated in the MockableArmClient extensions. These methods were being skipped due to the extension scope check at line 145 in ManagementOutputLibrary.cs.

Changes Made

ManagementOutputLibrary.cs:

  • Extract extension non-resource methods from resourcesAndMethodsPerScope[ResourceScope.Extension]
  • Pass them to MockableArmClientProvider.TryCreate for processing

MockableArmClientProvider.cs:

  • Updated constructor to accept IReadOnlyList<NonResourceMethod> nonResourceMethods parameter
  • Updated TryCreate method to accept and store non-resource methods
  • Added method generation logic in BuildMethods to process non-resource operations with async/sync variants
  • Removed obsolete TODO comment about supporting scope resources/operations
  • Changed creation check to allow creation if either resources or non-resource methods exist

MockableResourceProvider.cs:

  • Changed BuildServiceMethod from private to protected to allow derived classes to use it

OperationMethodParameterHelper.cs:

  • Added parameter transformation logic to convert first string parameter to ResourceIdentifier scope for extension operations in MockableArmClient
  • Ensures scope parameter is used correctly in generated methods

RequestPathPatternExtensions.cs:

  • Added ResourceIdentifier to string conversion when calling rest client operations

Test TypeSpec (scheduledaction.tsp):

  • Added test spec using ExtensionResource pattern matching ComputeSchedule spec
  • Validates generation of extension non-resource operations

Impact

Extension non-resource methods are now properly captured, stored, and generated in MockableArmClient and other mockable extensions based on scope. Generated methods use ResourceIdentifier scope parameter and support both async/sync variants with proper parameter transformation. Pattern matches the existing ComputeSchedule implementation. No breaking changes - existing functionality remains intact.


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.
Original prompt

This section details on the original issue you should resolve

<issue_title>mgmt generator is not processing non-LRO non-resource operations</issue_title>
<issue_description>

we should process non-LRO non-resource methods as well</issue_description>

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


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Updated ProcessLroMethod to handle both LRO and non-LRO methods by using the GetResponseBodyType extension method, which correctly extracts return types from both operation kinds. This ensures OperationSource providers are generated for all methods with model return types, not just LRO methods.

Co-authored-by: live1206 <[email protected]>
Copilot AI changed the title [WIP] Fix mgmt generator to process non-LRO non-resource operations Fix: Process non-LRO non-resource operations in management generator Dec 17, 2025
Copilot AI requested a review from live1206 December 17, 2025 04:24
- Split processing logic into two dedicated methods for better type safety
- ProcessLroMethod now takes InputLongRunningServiceMethod parameter
- ProcessNonLroMethod handles regular InputServiceMethod operations
- Extracted common logic into AddOperationSource helper method

Co-authored-by: live1206 <[email protected]>
@live1206
Copy link
Member

@copilot could you add a test to verify this scenario?

Added comprehensive test case Verify_NonLro_NonResource_Operation_Creates_OperationSource
that verifies OperationSource providers are correctly generated for non-LRO non-resource
operations with model return types. Test creates a basic service method (non-LRO) with
a response model and validates that the corresponding OperationSource is created in the
OperationSourceDict.

Co-authored-by: live1206 <[email protected]>
Copy link
Contributor Author

Copilot AI commented Dec 17, 2025

@copilot could you add a test to verify this scenario?

Added in commit 918b170. Test Verify_NonLro_NonResource_Operation_Creates_OperationSource verifies that OperationSource providers are correctly created for non-LRO non-resource operations with model return types. All 72 tests pass.

@live1206 live1206 marked this pull request as ready for review December 17, 2025 05:31
Copilot AI review requested due to automatic review settings December 17, 2025 05:31
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes an issue where the management generator was not processing non-LRO (Long-Running Operation) non-resource methods, preventing OperationSource providers from being generated for these methods when they have model return types.

Key Changes

  • Refactored operation processing logic in ManagementOutputLibrary.cs to handle both LRO and non-LRO operations for both resource and non-resource methods
  • Extracted AddOperationSource helper method to reduce code duplication
  • Introduced ProcessNonLroMethod to handle non-LRO operations by extracting return types from operation responses
  • Updated ProcessLroMethod to accept specifically InputLongRunningServiceMethod parameter for better type safety
  • Added comprehensive test coverage in OperationSourceProviderTests.cs to validate the new functionality

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
ManagementOutputLibrary.cs Refactored BuildOperationSources to dispatch to appropriate processing method (LRO vs non-LRO) for both resource and non-resource methods; extracted AddOperationSource helper and added ProcessNonLroMethod for handling non-LRO operations
OperationSourceProviderTests.cs Added new test Verify_NonLro_NonResource_Operation_Creates_OperationSource that validates OperationSource providers are correctly generated for non-LRO non-resource operations with model return types

@live1206
Copy link
Member

@copilot could you take a look at the comments?

Updated BuildOperationSources to use IsLongRunningOperation() extension method
instead of only checking for InputLongRunningServiceMethod. Modified ProcessLroMethod
to accept InputServiceMethod and handle both InputLongRunningServiceMethod and
InputLongRunningPagingServiceMethod types, ensuring both LRO types are processed
correctly for return type extraction.

Co-authored-by: live1206 <[email protected]>
Copy link
Contributor Author

Copilot AI commented Dec 17, 2025

@copilot could you take a look at the comments?

Fixed in commit 0cfe351. Updated to handle both InputLongRunningServiceMethod and InputLongRunningPagingServiceMethod using the IsLongRunningOperation() extension method. ProcessLroMethod now accepts InputServiceMethod and correctly extracts return types from both LRO types. All 72 tests pass.

Updated OperationMethodParameterHelper to transform string resourceUri parameters
to ResourceIdentifier scope for extension operations in MockableArmClient. Added
ResourceIdentifier to string conversion in RequestPathPatternExtensions. Generated
methods now use ResourceIdentifier scope parameter and convert to string when calling
rest client, matching the ComputeSchedule pattern.

Co-authored-by: live1206 <[email protected]>
@live1206
Copy link
Member

@copilot merge from latest main, resolve the conflicts and regenerate mgmt test

actions-user and others added 2 commits December 18, 2025 07:59
Regenerated TestProjects/Local/Mgmt-TypeSpec after merging latest changes from main.
All 71 tests pass. The tspCodeModel.json was updated during regeneration to reflect
the current state of the TypeSpec definitions.

Co-authored-by: live1206 <[email protected]>
Copy link
Contributor Author

Copilot AI commented Dec 18, 2025

@copilot merge from latest main, resolve the conflicts and regenerate mgmt test

Completed in commits 9f25f3f (merge) and 9c6f990 (regeneration). Merged latest changes from main branch, resolved the conflict in tspCodeModel.json, and regenerated the mgmt test project. All 71 generator tests pass successfully.

Removed the name check for resourceUri parameter since we can safely transform
the first string parameter in MockableArmClient extension operations. Added a
flag to ensure we only transform once. The logic is now more robust and doesn't
rely on specific parameter names, making it work for any extension operation
where the first parameter represents the scope.

Co-authored-by: live1206 <[email protected]>
@live1206
Copy link
Member

@copilot merge from latest main

Copilot AI and others added 2 commits December 18, 2025 08:40
…perations

# Conflicts:
#	eng/packages/http-client-csharp-mgmt/generator/TestProjects/Local/Mgmt-TypeSpec/tspCodeModel.json
Merged latest changes from main branch and regenerated TestProjects/Local/Mgmt-TypeSpec.
The tspCodeModel.json was updated during regeneration to reflect the merged state.
All 71 tests pass successfully.

Co-authored-by: live1206 <[email protected]>
Copy link
Contributor Author

Copilot AI commented Dec 18, 2025

@copilot merge from latest main

Completed in commits 25876b8 (merge) and 8f48e59 (regeneration). Merged latest changes from main branch, resolved the conflict in tspCodeModel.json, and regenerated the mgmt test project. All 71 tests pass successfully.

@live1206
Copy link
Member

/check-enforcer override

Removed the TODO comment about needing to support scope resources/operations
since this functionality has now been implemented. The provider now supports
both scope resources and non-resource operations as demonstrated by the
changes in this PR.

Co-authored-by: live1206 <[email protected]>
Copy link
Member

@ArcturusZhang ArcturusZhang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is still a concept of "specific extension" outside not implemented.
but as for now, this LGTM

@live1206
Copy link
Member

/check-enforcer override

@live1206 live1206 merged commit 1671f34 into main Dec 18, 2025
25 checks passed
@live1206 live1206 deleted the copilot/fix-non-lro-operations branch December 18, 2025 09:28
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.

mgmt generator is not processing non-LRO non-resource operations

5 participants