fix: generate parameterized accessor for subclients with subclient-specific parameters#9919
Open
fix: generate parameterized accessor for subclients with subclient-specific parameters#9919
Conversation
Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
Copilot stopped work on behalf of
JoshLove-msft due to an error
March 4, 2026 20:36
commit: |
…hods Reverts incorrect JS emitter changes and implements the fix in the C# emitter (ClientProvider.cs) where the issue actually belongs. When a subclient has parameters not present on the parent client, the parent's accessor method now accepts those extra parameters and passes them to the subclient constructor. Caching is bypassed for parameterized accessors since different parameter values may produce different client instances. Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
Contributor
Author
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Copilot
AI
changed the title
[WIP] Add subclient parameters to accessors
Add subclient parameters to accessors in the C# emitter
Mar 4, 2026
.chronus/changes/http-client-csharp-subclient-accessor-params-2026-03-04-20-30-00.md
Outdated
Show resolved
Hide resolved
Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
...nt-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/ClientProvider.cs
Show resolved
Hide resolved
Copilot
AI
changed the title
Add subclient parameters to accessors in the C# emitter
Add subclient-specific parameters to parent accessor methods in C# emitter
Mar 4, 2026
…cessor-only parameters - Add HasAccessorOnlyParameters() to ClientProvider to detect subclient-specific params - BuildFields(): skip caching field when subclient has accessor-only params - BuildMethods(): generate parameterized accessor (no caching) when accessorMethodParams > 0 - Add unit tests for Parent-only subclients with accessor-only parameters - Add MetricsClientParams to SampleService/main.tsp giving Metrics a metricsNamespace param - Regenerate Sample-TypeSpec (SampleTypeSpecClient.GetMetricsClient now takes metricsNamespace) - Add individuallyParent Spector test project from azure-http-specs showing all 6 subclient accessors correctly parameterized (e.g. GetIndividuallyParentNestedWithQueryClient(string blobName)) Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
...lient-initialization/individuallyParent/src/Generated/Models/BlobProperties.Serialization.cs
Outdated
Show resolved
Hide resolved
Copilot
AI
changed the title
Add subclient-specific parameters to parent accessor methods in C# emitter
fix: generate parameterized accessor for subclients with subclient-specific parameters
Mar 4, 2026
Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
jorgerangel-msft
approved these changes
Mar 4, 2026
Contributor
|
@copilot run prettier on the tsp file being changed |
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.
When a subclient (initialized by parent, or individually+parent) has parameters absent from the parent, the parent was generating a non-functional caching field and an accessor with no parameters — making it impossible to pass the subclient-specific values.
Root cause
BuildFields()always added_clientCachingFieldfor any parent-initialized subclient.BuildMethods()had theaccessorMethodParams > 0branch to generate parameterized accessors, but the spurious caching field remained.Changes
ClientProvider.HasAccessorOnlyParameters()— new method that detects non-endpoint, non-apiversion subclient parameters absent from the parentBuildFields()— skips the caching field whenHasAccessorOnlyParameters()is true (different param values → different instances → caching is wrong)TestBuildMethods_ForParent_InitializedByParentOnly_WithSubClientParams_HasParameterizedAccessorandTestBuildFields_ForParent_InitializedByParentOnly_WithSubClientParams_NoCachingFieldGenerated output
Before (wrong —
blobNameunreachable, dead caching field):After (correct):
Test coverage
SampleService/main.tspto giveMetricsametricsNamespaceclient parameter not on the parent;SampleTypeSpecClient.GetMetricsClient(string metricsNamespace)now demonstrates the fix end-to-endIndividuallyParentandParent-only subclient scenarios with accessor-only parametersOriginal prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.