[http-client-csharp] Fix protocol method call-site argument order#11097
Open
JoshLove-msft wants to merge 1 commit into
Open
[http-client-csharp] Fix protocol method call-site argument order#11097JoshLove-msft wants to merge 1 commit into
JoshLove-msft wants to merge 1 commit into
Conversation
…0160) When an optional parameter (e.g. an optional path parameter) appears before a required body parameter, the protocol method orders its parameters required-first, which differs from the CreateRequest builder's declaration order. The call site forwarded the protocol parameters positionally, binding them to the wrong CreateRequest parameters (swapping the request body with the optional parameter) and producing malformed request URLs. Map each CreateRequest argument to the protocol parameter with the same name so values are passed in the order the builder expects. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
You can try these changes here
|
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.
Summary
Fixes the generated C# (
@typespec/http-client-csharp) protocol method call site passing arguments to theCreateRequestbuilder in the wrong positional order.Reported in Azure/azure-sdk-for-net#60160 for Key Vault
updateSecret/updateCertificate.Root cause
The protocol method orders its parameters required-first (optional parameters and the request options/context parameter are moved to the end so they can carry default values). The
CreateRequestbuilder keeps the operation declaration order. When an optional parameter appears before a required body parameter, these two orders diverge.The call site forwarded the protocol method's parameters to
CreateRequestpositionally, so the arguments bound to the wrong builder parameters. For Key VaultupdateSecretthis routed theRequestContentinto thesecret-versionURL path slot:The resulting
PATCHURL became/secrets/{name}/{garbage-content-bytes}and 404'd.Fix
Map each
CreateRequestargument to the protocol parameter with the same name, so values are passed in the order the builder expects (falling back to the previous positional behavior if names can't be reconciled).Tests
ProtocolMethodCallsCreateRequestWithArgumentsInBuilderOrderreproduces the optional-path-before-required-body scenario and verifies the call site uses the builder's order.TestMultipartClient_UploadMethods_OptionalBodybaseline: it previously showed the sync and asyncUploadoverloads passing arguments to the sameCreateUploadRequestbuilder in different orders — i.e. the same latent bug. Both now correctly use(content, contentType, options).Microsoft.TypeSpec.Generator.ClientModelsuite passes (1440 tests).Fixes Azure/azure-sdk-for-net#60160