Apply @@override options bags to protocol methods - #11523
Open
m-nash wants to merge 5 commits into
Open
Conversation
When `@@override` groups an operation's parameters into an options bag, the protocol method now adopts the same grouped shape instead of listing every parameter individually. The protocol method keeps taking raw request content when the body is declared outside the bag. If the body itself was folded into the bag, the protocol method stays flattened so a raw payload can still be sent. Fixes microsoft#11214 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 69b166be-7096-4882-9251-6e998d9288ae
m-nash
requested review from
JoshLove-msft,
jorgerangel-msft,
joseharriaga and
jsquire
as code owners
August 3, 2026 21:42
commit: |
Contributor
|
No changes needing a change description found. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the C# http-client generator so that when @@override groups operation parameters into an options bag, the protocol method can also adopt the grouped signature (while still preserving a raw request-body escape hatch when needed), addressing #11214.
Changes:
- Apply
@@overrideoptions-bag grouping to protocol methods when safe (body not folded into the bag), keepingCreateRequestparameter flattening intact. - Expand grouped parameters back into flattened wire parameters when calling
CreateRequest, including enum-to-serialized conversions. - Add/adjust tests and baselines to validate protocol/convenience behavior across grouped/no-body, body-outside-bag, and body-inside-bag scenarios.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/TestData/ScmMethodProviderCollectionTests/MethodParameterSegments_RenamedGroupedQueryParam_MapsByClientName.cs | Updates baseline to forward the options bag through the convenience method. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/TestData/ScmMethodProviderCollectionTests/MethodParameterSegments_EnumGroupedQueryParam_SerializesToProtocol.cs | Updates baseline to forward the options bag through the convenience method. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/ScmMethodProviderCollectionTests.cs | Adds new test coverage for protocol-method options-bag grouping and body placement cases. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/ScmMethodProviderCollection.cs | Implements protocol-to-CreateRequest argument expansion from grouped options bags and resolves request-options naming collisions. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/RestClientProvider.cs | Switches protocol method parameter sourcing to grouped parameters when applicable and improves body handling for grouped shapes. |
TCGC does not validate that a required wire parameter maps to a required property on the options bag, so the generated constructor may not force callers to supply it. Grouping the protocol method in that case would silently drop the compile-time guarantee the flattened signature provides, so grouping is skipped. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 69b166be-7096-4882-9251-6e998d9288ae
jorgerangel-msft
left a comment
Contributor
There was a problem hiding this comment.
triggered a regen preview https://dev.azure.com/azure-sdk/internal/_build/results?buildId=6653318&view=results
An options bag can take the `options` name used by the request options parameter, which causes that parameter to be renamed. The CreateRequest call still bound its trailing argument by the original name, so it passed the bag instead and the generated client did not compile. Match ungrouped CreateRequest arguments on name and type, falling back to a unique type match when the bag has taken the name. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 69b166be-7096-4882-9251-6e998d9288ae
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 12a20512-4c49-4d6b-83d9-4e6f6261c5bf
Preserve generator parameter metadata when protocol method customizations rename grouped options parameters. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 12a20512-4c49-4d6b-83d9-4e6f6261c5bf
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 #11214
When
@@overridegroups an operation's parameters into an options bag, only the convenience method adopted the grouped shape. The protocol method kept listing every parameter individually, so a spec that hides the convenience method (or a caller that wants the protocol surface) still got a 40-parameter signature.Before / after
Behavior
The protocol method must always retain a way to send a raw payload, so grouping is applied conditionally:
(Options options, RequestOptions requestOptions)(BinaryContent content, Options options, RequestOptions requestOptions)Implementation
RestClientProviderGetMethodParameterssources protocol parameters fromserviceMethod.Parameters(the grouped shape) when grouping applies.CreateRequestcontinues to use the flattenedoperation.Parameters.InputMethodParameter { Location: Body }so a body declared outside the bag still becomes request content.ShouldGroupProtocolParametersdecides applicability: at least one operation parameter carriesMethodParameterSegments, and the segment root is not the request body.ScmMethodProviderCollectionBuildGroupedCreateRequestArgumentsexpands each grouped parameter back out of the bag when callingCreateRequest, carrying over the enum-to-serialized-form conversion.ResolveRequestOptionsNameCollisionrenames the trailing request options parameter when the options bag is itself namedoptions, which would otherwise emit a duplicate parameter name.Tests
Three new tests cover the grouped shape, the body-outside-bag case, and the body-inside-bag fallback.
Two existing baselines changed: the convenience method now forwards the bag straight through instead of unpacking it. The client-name-mapping and enum-serialization logic those tests covered moved to the protocol-to-
CreateRequestboundary, so I added assertions on the protocol body in the same tests rather than dropping that coverage.Microsoft.TypeSpec.Generator.ClientModel1543/1543 andMicrosoft.TypeSpec.Generator1810/1810 pass.