Fix default parameter merging bugs, add MergedParameters to RestResponse#2349
Fix default parameter merging bugs, add MergedParameters to RestResponse#2349alexeyzimarev merged 6 commits intodevfrom
Conversation
…2282) Merge default parameters into RestRequest.Parameters early in ExecuteRequestAsync so they are visible via response.Request.Parameters. Remove the now-redundant separate merges in RequestContent, BuildUriExtensions, RequestHeaders, and OAuth1Authenticator. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Review Summary by QodoFix default parameters missing from RestResponse.Request.Parameters
WalkthroughsDescription• Merges default parameters into RestRequest early in ExecuteRequestAsync • Makes default headers visible in RestResponse.Request.Parameters collection • Removes redundant default parameter merges from multiple components • Adds integration test verifying default headers appear in response Diagramflowchart LR
A["ExecuteRequestAsync"] -->|"Merge default params"| B["RestRequest.Parameters"]
B -->|"Now includes defaults"| C["RestResponse.Request.Parameters"]
D["RequestContent"] -->|"Removed redundant merge"| E["Simplified"]
F["BuildUriExtensions"] -->|"Removed redundant merge"| E
G["RequestHeaders"] -->|"Removed redundant merge"| E
H["OAuth1Authenticator"] -->|"Removed redundant merge"| E
File Changes1. src/RestSharp/RestClient.Async.cs
|
Code Review by Qodo
1.
|
Deploying restsharp with
|
| Latest commit: |
3519080
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://d059ea3b.restsharp.pages.dev |
| Branch Preview URL: | https://fix-default-params-in-respon.restsharp.pages.dev |
Test Results 42 files 42 suites 17m 36s ⏱️ Results for commit 0015698. ♻️ This comment has been updated with latest results. |
| var (uri, resource) = client.Options.BaseUrl.GetUrlSegmentParamsValues( | ||
| request.Resource, | ||
| client.Options.Encode, | ||
| request.Parameters, | ||
| client.DefaultParameters | ||
| request.Parameters | ||
| ); | ||
| return uri.MergeBaseUrlAndResource(resource); |
There was a problem hiding this comment.
2. Builduri skips defaults 🐞 Bug ✓ Correctness
BuildUriWithoutQueryParameters and GetRequestQuery no longer include client.DefaultParameters, so client.BuildUri* omits default URL segments and query parameters unless the request was previously executed/mutated. This is a behavioral regression for a public API that’s expected to reflect defaults used “on every request.”
Agent Prompt
### Issue description
`BuildUri*` no longer considers `client.DefaultParameters`, so URLs built via `client.BuildUri()` / `BuildUriString()` can omit default query params and URL segments.
### Issue Context
These methods are public API and are commonly used to inspect/preview the final request URI.
### Fix Focus Areas
- src/RestSharp/BuildUriExtensions.cs[50-58]
- src/RestSharp/BuildUriExtensions.cs[66-70]
- src/RestSharp/Request/UriExtensions.cs[50-66]
- src/RestSharp/IRestClient.cs[31-35]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
Code reviewFound 1 issue:
RestSharp/src/RestSharp/RestClient.Async.cs Lines 104 to 110 in f18501c 🤖 Generated with Claude Code - If this code review was useful, please react with 👍. Otherwise, react with 👎. |
Revert per-site merging to restore original design and fix three bugs: 1. Multi-value dedup — same-name defaults (AllowMultipleDefaultParametersWithSameName) were silently dropped 2. Public API breakage — BuildUriString/GetRequestQuery didn't include defaults when called outside ExecuteAsync 3. Request mutation — stale defaults persisted on reused requests when DefaultParameters changed Add MergedParameters property on RestResponse to satisfy the original #2282 requirement of making default parameters visible after execution. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Updated: Fix default parameter merging bugsThis push fixes three bugs introduced by the original merge-into-request approach:
Approach
Test results
|
The addition of RestSharp.slnx alongside RestSharp.sln causes MSB1011
("more than one project or solution file") when running bare dotnet test.
Run each test project explicitly instead.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
/review |
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
- Initialize to empty RequestParameters() so consumers never need null checks - Restrict setter to internal to prevent external mutation of response state Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|



Summary
Fixes #2282 while correcting three bugs introduced by the initial approach of merging
DefaultParametersintorequest.Parametersearly inExecuteRequestAsync:AllowMultipleDefaultParametersWithSameName) were silently dropped because the merge loop skipped parameters with matching name+typeBuildUriString/GetRequestQuerydidn't include defaults when called outsideExecuteAsync, since defaults were only merged insideExecuteRequestAsyncRestRequestobjects whenDefaultParameterschanged between executionsApproach
DefaultParametersare merged at each usage site (BuildUriExtensions,RequestContent,RequestHeaders,OAuth1Authenticator) rather than mutatingrequest.ParametersRestResponse.MergedParameters— a non-null, read-only (internal setter)ParametersCollectionthat provides a snapshot ofrequest.Parametersunioned withDefaultParametersat execution time, satisfying the original RestClient default headers missing from RestResponse.Request.Parameters #2282 requirementAPI design
MergedParametersis:RequestParameters(), so consumers never need null checksinternal set— onlyRestClientpopulates it; external consumers cannot alter response stateRestResponseBase— available on bothRestResponseandRestResponse<T>Test plan
BuildUriStringwithout execute, request mutationMergedParameterstest verifies both request and default params are present on the responseRestSharp.Tests, all target frameworks)RestSharp.Tests.Integrated, except pre-existing NTLM env failures)dotnet teston individual test projects (avoids MSB1011 with dual.sln/.slnx)🤖 Generated with Claude Code