Skip to content

fix: generate parameterized accessor for subclients with subclient-specific parameters#9919

Merged
JoshLove-msft merged 13 commits intomainfrom
copilot/add-subclient-parameters-accessors
Mar 6, 2026
Merged

fix: generate parameterized accessor for subclients with subclient-specific parameters#9919
JoshLove-msft merged 13 commits intomainfrom
copilot/add-subclient-parameters-accessors

Conversation

Copy link
Contributor

Copilot AI commented Mar 4, 2026

  • Fix ClientProvider.cs: HasAccessorOnlyParameters() detects subclient-specific params; BuildFields() skips caching field; BuildMethods() generates parameterized accessor
  • Add unit tests for Parent-only subclients with accessor-only parameters
  • Add MetricsClientParams to SampleService/main.tsp; regenerate Sample-TypeSpec
  • Revert Spector azure test project changes
  • Run prettier on SampleService/main.tsp
  • Run Generate.ps1 and check in regenerated files
Original prompt

This section details on the original issue you should resolve

<issue_title>Subclient parameters need to be included in accessors</issue_title>
<issue_description>For subclients that can be created individually or from the parent, the subclient parameters are not included in the subclient accessors currently. </issue_description>

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


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
@microsoft-github-policy-service microsoft-github-policy-service bot added the emitter:client:js Issue for the JS client emitter: @typespec/http-client-js label Mar 4, 2026
@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 4, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/http-client-csharp@9919

commit: ca820f4

…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>
@microsoft-github-policy-service microsoft-github-policy-service bot added the emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp label Mar 4, 2026
Copy link
Contributor Author

Copilot AI commented Mar 4, 2026

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:

  • aka.ms
    • Triggering command: /usr/bin/curl curl -L REDACTED -o /tmp/install-dotnet.sh act-api |accessor\|Accessor de/node/bin/bash (dns block)

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
Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 4, 2026

@copilot run prettier on the tsp file being changed

Done in dd06669 — prettier collapsed the multi-line params into a single line.

@JoshLove-msft
Copy link
Contributor

@copilot run Generate.ps1 and check in the changes

Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 5, 2026

@copilot run Generate.ps1 and check in the changes

Done in cb0f232 — ran Generate.ps1 -filter "Sample-TypeSpec" and committed the 3 regenerated files (SampleTypeSpecClient.cs, Metrics.cs, Metrics.RestClient.cs). All 243 ClientProvider unit tests pass.

Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
…ection per TCGC behavior

Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
Restores the MetricsClientParams model and @clientInitialization parameters
on the Metrics interface. Regenerated all generated libraries to validate
the parameterized accessor behavior.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions
Copy link
Contributor

github-actions bot commented Mar 6, 2026

No changes needing a change description found.

@JoshLove-msft JoshLove-msft enabled auto-merge March 6, 2026 03:30
…eneration

Remove redundant IsApiVersion/IsEndpoint filters in accessor loop (already
handled by earlier branches). Use _inputClient.Parameters instead of
_allClientParameters for parent comparison. Retain parent comparison for
correctness in MultiServiceClient scenarios where params are shared.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@JoshLove-msft JoshLove-msft added this pull request to the merge queue Mar 6, 2026
Merged via the queue into main with commit 537c5d5 Mar 6, 2026
33 checks passed
@JoshLove-msft JoshLove-msft deleted the copilot/add-subclient-parameters-accessors branch March 6, 2026 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Subclient parameters need to be included in accessors

3 participants