-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Fix: Process extension non-resource operations in management generator #54564
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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]>
.../http-client-csharp-mgmt/generator/Azure.Generator.Management/src/ManagementOutputLibrary.cs
Show resolved
Hide resolved
- 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]>
|
@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]>
There was a problem hiding this 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.csto handle both LRO and non-LRO operations for both resource and non-resource methods - Extracted
AddOperationSourcehelper method to reduce code duplication - Introduced
ProcessNonLroMethodto handle non-LRO operations by extracting return types from operation responses - Updated
ProcessLroMethodto accept specificallyInputLongRunningServiceMethodparameter for better type safety - Added comprehensive test coverage in
OperationSourceProviderTests.csto 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 |
.../http-client-csharp-mgmt/generator/Azure.Generator.Management/src/ManagementOutputLibrary.cs
Outdated
Show resolved
Hide resolved
.../http-client-csharp-mgmt/generator/Azure.Generator.Management/src/ManagementOutputLibrary.cs
Outdated
Show resolved
Hide resolved
.../http-client-csharp-mgmt/generator/Azure.Generator.Management/src/ManagementOutputLibrary.cs
Outdated
Show resolved
Hide resolved
|
@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]>
Fixed in commit 0cfe351. Updated to handle both |
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]>
|
@copilot merge from latest main, resolve the conflicts and regenerate mgmt test |
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]>
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. |
...rp-mgmt/generator/Azure.Generator.Management/src/Utilities/OperationMethodParameterHelper.cs
Show resolved
Hide resolved
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]>
|
@copilot merge from latest main |
…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]>
|
/check-enforcer override |
...-csharp-mgmt/generator/Azure.Generator.Management/src/Providers/MockableArmClientProvider.cs
Outdated
Show resolved
Hide resolved
.../http-client-csharp-mgmt/generator/Azure.Generator.Management/src/ManagementOutputLibrary.cs
Show resolved
Hide resolved
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]>
ArcturusZhang
left a comment
There was a problem hiding this 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
|
/check-enforcer override |
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:resourcesAndMethodsPerScope[ResourceScope.Extension]MockableArmClientProvider.TryCreatefor processingMockableArmClientProvider.cs:IReadOnlyList<NonResourceMethod> nonResourceMethodsparameterTryCreatemethod to accept and store non-resource methodsBuildMethodsto process non-resource operations with async/sync variantsMockableResourceProvider.cs:BuildServiceMethodfrom private to protected to allow derived classes to use itOperationMethodParameterHelper.cs:ResourceIdentifier scopefor extension operations in MockableArmClientRequestPathPatternExtensions.cs:ResourceIdentifierto string conversion when calling rest client operationsTest TypeSpec (
scheduledaction.tsp):ExtensionResourcepattern matching ComputeSchedule specImpact
Extension non-resource methods are now properly captured, stored, and generated in MockableArmClient and other mockable extensions based on scope. Generated methods use
ResourceIdentifier scopeparameter 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
Testing Guidelines
SDK Generation Guidelines
*.csprojandAssemblyInfo.csfiles have been updated with the new version of the SDK.Original prompt
💡 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.