Repository navigation
Fix C# paging helper naming collisions and long filenames - #12292
Open
Dapeng Zhang (ArcturusZhang) wants to merge 5 commits into
Open
Dapeng Zhang (ArcturusZhang) wants to merge 5 commits into
Dapeng Zhang (ArcturusZhang) wants to merge 5 commits into
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 268abd28-b2c0-4898-87f0-4ca429090c1f
commit: |
Contributor
|
No changes needing a change description found. |
Document the collections partial declaration and let the output library reuse the client-owned provider. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 268abd28-b2c0-4898-87f0-4ca429090c1f
Drop redundant client prefixes and original-name fallback; document client-local numeric collision suffixes. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 268abd28-b2c0-4898-87f0-4ca429090c1f
…erty Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 268abd28-b2c0-4898-87f0-4ca429090c1f
Dapeng Zhang (ArcturusZhang)
marked this pull request as ready for review
October 19, 2026 08:21
Dapeng Zhang (ArcturusZhang)
requested review from
JoshLove-msft,
Jorge Rangel (jorgerangel-msft),
Jose Arriaga Maldonado (joseharriaga) and
m-nash
as code owners
October 19, 2026 08:21
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Naming collisions and compatibility and identity propagation defects can produce uncompilable generated SDKs.
3 open issues
What changed in this PR
Addresses #12147 by nesting C# paging helpers inside their owning clients, reducing filename length and separating helper names across clients.
Changes:
- Groups helpers into per-client
.Collections.csfiles with deterministic collision suffixes. - Extends visitor and dependency traversal to nested helpers and excludes collections partials from API stubs.
- Adds regression coverage, updates fixtures, and regenerates sample output.
Paths below omit packages/http-client-csharp/generator/. Prefixes: Sample = TestProjects/Local/Sample-TypeSpec/src/Generated; Core = Microsoft.TypeSpec.Generator; ClientModel = Microsoft.TypeSpec.Generator.ClientModel.
| File | Description |
|---|---|
| Sample/SampleTypeSpecClient.cs | Uses nested paging helpers. |
| Sample/SampleTypeSpecClient.Collections.cs | Groups client paging helpers. |
| Sample/ExperimentalSamples.cs | Uses nested paging helpers. |
| Sample/ExperimentalSamples.Collections.cs | Groups experimental paging helpers. |
| Sample/CollectionResults/SampleTypeSpecClientGetWithStringNextLinkCollectionResultOfT.cs | Removed; helper moved into client. |
| Sample/CollectionResults/SampleTypeSpecClientGetWithStringNextLinkCollectionResult.cs | Removed; helper moved into client. |
| Sample/CollectionResults/SampleTypeSpecClientGetWithStringNextLinkAsyncCollectionResultOfT.cs | Removed; helper moved into client. |
| Sample/CollectionResults/SampleTypeSpecClientGetWithStringNextLinkAsyncCollectionResult.cs | Removed; helper moved into client. |
| Sample/CollectionResults/SampleTypeSpecClientGetWithPagingCollectionResultOfT.cs | Removed; helper moved into client. |
| Sample/CollectionResults/SampleTypeSpecClientGetWithPagingCollectionResult.cs | Removed; helper moved into client. |
| Sample/CollectionResults/SampleTypeSpecClientGetWithPagingAsyncCollectionResultOfT.cs | Removed; helper moved into client. |
| Sample/CollectionResults/SampleTypeSpecClientGetWithPagingAsyncCollectionResult.cs | Removed; helper moved into client. |
| Sample/CollectionResults/SampleTypeSpecClientGetWithNextLinkCollectionResultOfT.cs | Removed; helper moved into client. |
| Sample/CollectionResults/SampleTypeSpecClientGetWithNextLinkCollectionResult.cs | Removed; helper moved into client. |
| Sample/CollectionResults/SampleTypeSpecClientGetWithNextLinkAsyncCollectionResultOfT.cs | Removed; helper moved into client. |
| Sample/CollectionResults/SampleTypeSpecClientGetWithNextLinkAsyncCollectionResult.cs | Removed; helper moved into client. |
| Sample/CollectionResults/SampleTypeSpecClientGetWithContinuationTokenHeaderResponseCollectionResultOfT.cs | Removed; helper moved into client. |
| Sample/CollectionResults/SampleTypeSpecClientGetWithContinuationTokenHeaderResponseCollectionResult.cs | Removed; helper moved into client. |
| Sample/CollectionResults/SampleTypeSpecClientGetWithContinuationTokenHeaderResponseAsyncCollectionResultOfT.cs | Removed; helper moved into client. |
| Sample/CollectionResults/SampleTypeSpecClientGetWithContinuationTokenHeaderResponseAsyncCollectionResult.cs | Removed; helper moved into client. |
| Sample/CollectionResults/SampleTypeSpecClientGetWithContinuationTokenCollectionResultOfT.cs | Removed; helper moved into client. |
| Sample/CollectionResults/SampleTypeSpecClientGetWithContinuationTokenCollectionResult.cs | Removed; helper moved into client. |
| Sample/CollectionResults/SampleTypeSpecClientGetWithContinuationTokenAsyncCollectionResultOfT.cs | Removed; helper moved into client. |
| Sample/CollectionResults/SampleTypeSpecClientGetWithContinuationTokenAsyncCollectionResult.cs | Removed; helper moved into client. |
| Sample/CollectionResults/ExperimentalSamplesGetAllCollectionResultOfT.cs | Removed; helper moved into client. |
| Sample/CollectionResults/ExperimentalSamplesGetAllCollectionResult.cs | Removed; helper moved into client. |
| Sample/CollectionResults/ExperimentalSamplesGetAllAsyncCollectionResultOfT.cs | Removed; helper moved into client. |
| Sample/CollectionResults/ExperimentalSamplesGetAllAsyncCollectionResult.cs | Removed; helper moved into client. |
| Core/test/ReferenceMap/ProviderReferenceMapAnalyzerTests.cs | Tests nested-helper dependency retention. |
| Core/test/OutputLibraryVisitorTests.cs | Tests nested member visitation. |
| Core/src/ReferenceMap/ProviderReferenceMapAnalyzer.BodyReferences.cs | Includes nested providers in dependency analysis. |
| Core/src/LibraryVisitor.cs | Recursively visits nested members. |
| ClientModel/test/Providers/TestData/ScmMethodProviderCollectionTests/OptionsBagOverride_PagingMethodExpandsBagForCollectionResult(Protocol).cs | Updates qualified helper reference. |
| ClientModel/test/Providers/TestData/ScmMethodProviderCollectionTests/OptionsBagOverride_PagingMethodExpandsBagForCollectionResult(Convenience).cs | Updates qualified helper reference. |
| ClientModel/test/Providers/ScmMethodProviderCollectionTests.cs | Finds helpers in nested providers. |
| ClientModel/test/Providers/CollectionResultDefinitions/TestData/NextLinkTests/NormalizedDateTimeReinjectedParameterFiltersNextLinkArguments.cs | Updates helper-name baseline. |
| ClientModel/test/Providers/CollectionResultDefinitions/TestData/NextLinkTests/NextLinkInHeaderOfTAsync.cs | Updates helper-name baseline. |
| ClientModel/test/Providers/CollectionResultDefinitions/TestData/NextLinkTests/NextLinkInHeaderOfT.cs | Updates helper-name baseline. |
| ClientModel/test/Providers/CollectionResultDefinitions/TestData/NextLinkTests/NextLinkInHeaderAsync.cs | Updates helper-name baseline. |
| ClientModel/test/Providers/CollectionResultDefinitions/TestData/NextLinkTests/NextLinkInHeader.cs | Updates helper-name baseline. |
| ClientModel/test/Providers/CollectionResultDefinitions/TestData/NextLinkTests/NextLinkInBodyOfTAsync.cs | Updates helper-name baseline. |
| ClientModel/test/Providers/CollectionResultDefinitions/TestData/NextLinkTests/NextLinkInBodyOfT.cs | Updates helper-name baseline. |
| ClientModel/test/Providers/CollectionResultDefinitions/TestData/NextLinkTests/NextLinkInBodyAsync.cs | Updates helper-name baseline. |
| ClientModel/test/Providers/CollectionResultDefinitions/TestData/NextLinkTests/NextLinkInBody.cs | Updates helper-name baseline. |
| ClientModel/test/Providers/CollectionResultDefinitions/TestData/NextLinkTests/NestedNextLinkInBodyOfTAsync.cs | Updates helper-name baseline. |
| ClientModel/test/Providers/CollectionResultDefinitions/TestData/NextLinkTests/NestedNextLinkInBodyOfT.cs | Updates helper-name baseline. |
| ClientModel/test/Providers/CollectionResultDefinitions/TestData/NextLinkTests/NestedNextLinkInBodyAsync.cs | Updates helper-name baseline. |
| ClientModel/test/Providers/CollectionResultDefinitions/TestData/NextLinkTests/NestedNextLinkInBody.cs | Updates helper-name baseline. |
| ClientModel/test/Providers/CollectionResultDefinitions/TestData/NextLinkTests/InheritedNextLinkInBodyOfTAsync.cs | Updates helper-name baseline. |
| ClientModel/test/Providers/CollectionResultDefinitions/TestData/NextLinkTests/InheritedNextLinkInBodyOfT.cs | Updates helper-name baseline. |
| ClientModel/test/Providers/CollectionResultDefinitions/TestData/NextLinkTests/InheritedNextLinkInBodyAsync.cs | Updates helper-name baseline. |
| ClientModel/test/Providers/CollectionResultDefinitions/TestData/NextLinkTests/InheritedNextLinkInBody.cs | Updates helper-name baseline. |
| ClientModel/test/Providers/CollectionResultDefinitions/TestData/ListPageableTests/NoNextLinkOrContinuationTokenOfTAsync.cs | Updates helper-name baseline. |
| ClientModel/test/Providers/CollectionResultDefinitions/TestData/ListPageableTests/NoNextLinkOrContinuationTokenOfT.cs | Updates helper-name baseline. |
| ClientModel/test/Providers/CollectionResultDefinitions/TestData/ListPageableTests/NoNextLinkOrContinuationTokenAsync.cs | Updates helper-name baseline. |
| ClientModel/test/Providers/CollectionResultDefinitions/TestData/ListPageableTests/NoNextLinkOrContinuationToken.cs | Updates helper-name baseline. |
| ClientModel/test/Providers/CollectionResultDefinitions/TestData/ContinuationTokenTests/NestedContinuationTokenInBodyOfTAsync.cs | Updates helper-name baseline. |
| ClientModel/test/Providers/CollectionResultDefinitions/TestData/ContinuationTokenTests/NestedContinuationTokenInBodyOfT.cs | Updates helper-name baseline. |
| ClientModel/test/Providers/CollectionResultDefinitions/TestData/ContinuationTokenTests/NestedContinuationTokenInBodyAsync.cs | Updates helper-name baseline. |
| ClientModel/test/Providers/CollectionResultDefinitions/TestData/ContinuationTokenTests/NestedContinuationTokenInBody.cs | Updates helper-name baseline. |
| ClientModel/test/Providers/CollectionResultDefinitions/TestData/ContinuationTokenTests/ContinuationTokenInHeaderOfTAsync.cs | Updates helper-name baseline. |
| ClientModel/test/Providers/CollectionResultDefinitions/TestData/ContinuationTokenTests/ContinuationTokenInHeaderOfT.cs | Updates helper-name baseline. |
| ClientModel/test/Providers/CollectionResultDefinitions/TestData/ContinuationTokenTests/ContinuationTokenInHeaderAsync.cs | Updates helper-name baseline. |
| ClientModel/test/Providers/CollectionResultDefinitions/TestData/ContinuationTokenTests/ContinuationTokenInHeader.cs | Updates helper-name baseline. |
| ClientModel/test/Providers/CollectionResultDefinitions/TestData/ContinuationTokenTests/ContinuationTokenInBodyOfTAsync.cs | Updates helper-name baseline. |
| ClientModel/test/Providers/CollectionResultDefinitions/TestData/ContinuationTokenTests/ContinuationTokenInBodyOfT.cs | Updates helper-name baseline. |
| ClientModel/test/Providers/CollectionResultDefinitions/TestData/ContinuationTokenTests/ContinuationTokenInBodyAsync.cs | Updates helper-name baseline. |
| ClientModel/test/Providers/CollectionResultDefinitions/TestData/ContinuationTokenTests/ContinuationTokenInBody.cs | Updates helper-name baseline. |
| ClientModel/test/Providers/CollectionResultDefinitions/NextLinkTests.cs | Uses nested helper names and lookups. |
| ClientModel/test/Providers/CollectionResultDefinitions/ListPageableTests.cs | Uses nested helper names and lookups. |
| ClientModel/test/Providers/CollectionResultDefinitions/ContinuationTokenTests.cs | Uses nested helper names and lookups. |
| ClientModel/test/Providers/CollectionResultDefinitions/CollectionResultDefinitionTests.cs | Tests ownership, collisions, and bounded filenames. |
| ClientModel/test/Providers/ClientProviders/TestData/ClientProviderCustomizationTests/SuppressedPagingProtocolMethodKeepsPagingHelpers/TestClient.cs | References nested helper from custom code. |
| ClientModel/test/Providers/ClientProviders/ClientProviderTests.cs | Updates paging-helper assertions. |
| ClientModel/test/Providers/ClientProviders/ClientProviderCustomizationTests.cs | Checks retained nested helpers. |
| ClientModel/src/ScmOutputLibrary.cs | Registers per-client collections partials. |
| ClientModel/src/Providers/CollectionResultDefinition.cs | Adds nesting and local name disambiguation. |
| ClientModel/src/Providers/ClientProvider.cs | Lazily caches collections provider. |
| ClientModel/src/Providers/ClientCollectionsProvider.cs | Defines partial containing paging helpers. |
| Microsoft.TypeSpec.Generator.ClientModel.StubLibrary/src/StubLibraryVisitor.cs | Excludes collections partials from stubs. |
| docs/architecture.md | Documents helper ownership and naming. |
Review effort: Balanced
|
|
||
| protected override string BuildRelativeFilePath() => Path.Combine("src", "Generated", $"{Name}.Collections.cs"); | ||
|
|
||
| protected override TypeSignatureModifiers BuildDeclarationModifiers() => Client.DeclarationModifiers; |
| /// <summary> | ||
| /// Gets the partial client declaration containing this client's nested paging helpers. | ||
| /// </summary> | ||
| public ClientCollectionsProvider CollectionResultProviders => _collectionResultProviders ??= new ClientCollectionsProvider(this); |
Comment on lines
+195
to
+196
| var operations = Client.InputClient.Methods.OfType<InputPagingServiceMethod>().Select(m => m.Operation).Distinct().ToArray(); | ||
| var name = GetName(Operation, IsAsync); |
Avoid duplicate compatibility overloads in the collections partial and propagate client identity updates to cached nested paging helpers while preserving constructor customizations. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 268abd28-b2c0-4898-87f0-4ca429090c1f
This branch has not been deployed
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.

Fixes #12147.
Summary
<ClientName>.Collections.cs, following option 2 discussed in the issue.ClientProvider.CollectionResultProviderslazily creates and caches this partial declaration.<OperationName>[Async]CollectionResult[OfT], without a redundant client-name prefix or original-name fallback. Resolve same-client normalized-name and sync/async collisions in input operation order: keep the first name unchanged, then append2,3, etc. For example, two operations normalized toGetAllproduceGetAllCollectionResultandGetAllCollectionResult2.Generated SDK public APIs and paging iteration logic are unchanged. Internal helper names and qualified locations change with the nested layout.
Validation
net8.0with the initial nested layout and emitted five per-client collections files instead of per-operation files.pnpm formatpassed after the latest changes.Spector HTTP runtime integration tests were not run.