Fix mgmt generator: use longest prefix match for parent resource detection#56180
Merged
ArthurMa1978 merged 1 commit intomainfrom Feb 11, 2026
Merged
Fix mgmt generator: use longest prefix match for parent resource detection#56180ArthurMa1978 merged 1 commit intomainfrom
ArthurMa1978 merged 1 commit intomainfrom
Conversation
12fdb3c to
9aff20c
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes legacy ARM resource parent/child detection in the management generator emitter by selecting the most specific parent (longest prefix match) rather than the first prefix encountered, preventing incorrect parenting for 3+ level nested resources. It also expands the multiplepaths.tsp test scenario to include a third nesting level and updates the expected generated output accordingly.
Changes:
- Update legacy resource detection to choose the longest matching parent path when inferring
parentResourceId. - Add a 3rd-level nested resource scenario (
BestPracticeVersionDetail) to themultiplepaths.tspTypeSpec test. - Refresh generated C# baseline output to include the new nested resource, its collection, REST operations, paging helpers, and ArmClient extensions.
Reviewed changes
Copilot reviewed 2 out of 13 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| eng/packages/http-client-csharp-mgmt/emitter/src/resource-detection.ts | Fix parent detection by tracking the longest matching prefix instead of breaking on first match. |
| eng/packages/http-client-csharp-mgmt/generator/TestProjects/Local/Mgmt-TypeSpec/multiplepaths.tsp | Add 3rd-level nested resource operations to validate longest-prefix parent inference. |
| eng/packages/http-client-csharp-mgmt/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/BestPracticeVersionResource.cs | Add APIs to access BestPracticeVersionDetail collection and single-resource getters. |
| eng/packages/http-client-csharp-mgmt/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/BestPracticeVersionDetailCollection.cs | New collection type for nested version details under a version resource. |
| eng/packages/http-client-csharp-mgmt/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/BestPracticeVersionDetailResource.cs | New resource type representing a version detail instance and its operations. |
| eng/packages/http-client-csharp-mgmt/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/BestPracticeVersionDetailResource.Serialization.cs | Add model serialization glue for the new resource wrapper. |
| eng/packages/http-client-csharp-mgmt/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/RestOperations/BestPracticeVersionDetailsRestOperations.cs | New REST operations client for version detail endpoints. |
| eng/packages/http-client-csharp-mgmt/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/CollectionResults/BestPracticeVersionDetailsGetAllCollectionResultOfT.cs | New sync paging implementation for listing version details. |
| eng/packages/http-client-csharp-mgmt/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/CollectionResults/BestPracticeVersionDetailsGetAllAsyncCollectionResultOfT.cs | New async paging implementation for listing version details. |
| eng/packages/http-client-csharp-mgmt/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Extensions/MockableAzureGeneratorMgmtTypeSpecTestsArmClient.cs | Add mockable ArmClient helper to construct BestPracticeVersionDetailResource from an id. |
| eng/packages/http-client-csharp-mgmt/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Extensions/AzureGeneratorMgmtTypeSpecTestsExtensions.cs | Add ArmClient extension method to access BestPracticeVersionDetailResource. |
| eng/packages/http-client-csharp-mgmt/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/AzureGeneratorMgmtTypeSpecTestsContext.cs | Register the new resource type for model reader/writer source generation. |
...mgmt/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/BestPracticeVersionResource.cs
Outdated
Show resolved
Hide resolved
7 tasks
Contributor
|
@ArthurMa1978 I've opened a new pull request, #56181, to work on those changes. Once the pull request is ready, I'll request review from you. |
live1206
reviewed
Feb 11, 2026
eng/packages/http-client-csharp-mgmt/emitter/src/resource-detection.ts
Outdated
Show resolved
Hide resolved
9aff20c to
d6f4951
Compare
…ction Fix a bug in resource-detection.ts where parent-child resource detection used first-match instead of longest-prefix-match when iterating the resource metadata map. This caused resources with 3+ levels of nesting (e.g., BestPractice → BestPracticeVersion → BestPracticeVersionDetail) to potentially be placed on the wrong parent if a shorter prefix (grandparent) was iterated before the correct parent. The fix replaces the inner loop's 'break' on first match with tracking the longest matching prefix by segment count, ensuring the most specific parent resource is always selected. Also adds a 3-level nesting test case (BestPracticeVersionDetail) to the multiplepaths.tsp test file to verify the fix.
d6f4951 to
d3277b9
Compare
live1206
reviewed
Feb 11, 2026
live1206
approved these changes
Feb 11, 2026
live1206
added a commit
that referenced
this pull request
Feb 11, 2026
…esource-detection - Add getSegmentCount helper to utils.ts to avoid redundant path splitting - Replace isPrefix + getSharedSegmentCount combo in resource-detection.ts with direct getSharedSegmentCount + getSegmentCount calls - Update isPrefix itself to use getSegmentCount instead of inline splits - Remove isPrefix import from resource-detection.ts (no longer needed) This eliminates redundant string splitting operations where isPrefix was called followed by getSharedSegmentCount on the same paths. Addresses feedback from PR #56180 (discussion r2791991621).
This was referenced Feb 11, 2026
Closed
live1206
added a commit
to azure-sdk/azure-sdk-for-net
that referenced
this pull request
Feb 12, 2026
…urce parent change The parent detection fix (PR Azure#56180) correctly moved SignalRReplicaSharedPrivateLinkResource from SignalRResource to SignalRReplicaResource. Add [Obsolete] shim methods to preserve backward compatibility with the 1.1.4 stable API surface.
live1206
added a commit
to azure-sdk/azure-sdk-for-net
that referenced
this pull request
Feb 12, 2026
…urce parent change The parent detection fix (PR Azure#56180) correctly moved SignalRReplicaSharedPrivateLinkResource from SignalRResource to SignalRReplicaResource. Add backward-compatible shim methods with [EditorBrowsable(Never)] to preserve the old API surface with full working implementations.
live1206
added a commit
to azure-sdk/azure-sdk-for-net
that referenced
this pull request
Feb 12, 2026
…urce parent change The parent detection fix (PR Azure#56180) correctly moved SignalRReplicaSharedPrivateLinkResource from SignalRResource to SignalRReplicaResource. Add backward-compatible shim methods with [EditorBrowsable(Never)] to preserve the old API surface with full working implementations.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fix a bug in resource-detection.ts where parent-child resource detection used first-match instead of longest-prefix-match when iterating the resource metadata map. This caused resources with 3+ levels of nesting (e.g., BestPractice → BestPracticeVersion → BestPracticeVersionDetail) to potentially be placed on the wrong parent if a shorter prefix (grandparent) was iterated before the correct parent.
The fix replaces the inner loop's 'break' on first match with tracking the longest matching prefix by segment count, ensuring the most specific parent resource is always selected.
Also adds a 3-level nesting test case (BestPracticeVersionDetail) to the multiplepaths.tsp test file to verify the fix.
Contributing to the Azure SDK
Please see our CONTRIBUTING.md if you are not familiar with contributing to this repository or have questions.
For specific information about pull request etiquette and best practices, see this section.