Skip to content

[http-client-csharp] Fix explode object query parameter serialization#11124

Merged
JoshLove-msft merged 1 commit into
microsoft:mainfrom
JoshLove-msft:jolov/csharp-explode-query-fix
Jul 1, 2026
Merged

[http-client-csharp] Fix explode object query parameter serialization#11124
JoshLove-msft merged 1 commit into
microsoft:mainfrom
JoshLove-msft:jolov/csharp-explode-query-fix

Conversation

@JoshLove-msft

Copy link
Copy Markdown
Contributor

Fixes #11123

Problem

A model-typed query parameter marked with @query(#{ explode: true }) was serialized via the object's ToString, producing the type name in the URL:

uri.AppendQuery("filter", TypeFormatters.ConvertToString(filter), true);
// => GET /api/v1/items?filter=Example.FilterOptions

Fix

RestClientProvider.BuildAppendQueryStatement now expands a model-typed explode query parameter into one query entry per property, using each property's wire name (RFC 6570 form explode):

uri.AppendQuery("field", filter.Field, true);
uri.AppendQuery("value", filter.Value, true);
// => GET /parameters/query/explode/object?field=status&value=active

Models whose properties are all simple scalars/enums are expanded. Nested objects and collections fall back to the previous behavior pending a separate design decision (they are not defined by RFC 6570 form explode).

Tests

  • Added TestBuildCreateRequestMethodWithExplodedModelQueryParameter unit test.
  • All 70 RestClientProviderTests pass (no regressions).

The end-to-end Spector scenario and C# Spector test that exercise this against a live mock server are in a follow-up PR (the shared @typespec/http-specs scenario + generated client).

…property entries

A model-typed query parameter marked with @query(#{ explode: true }) was
serialized via the object's ToString, producing the type name in the URL
(e.g. ?filter=Namespace.FilterOptions).

Expand such parameters into one query entry per property using the property's
wire name (RFC 6570 form explode, e.g. ?field=status&value=active). Nested
objects and collections fall back to the previous behavior pending a separate
design decision.

Co-authored-by: Copilot <223556219+Copilot@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 Jul 1, 2026
@pkg-pr-new

pkg-pr-new Bot commented Jul 1, 2026

Copy link
Copy Markdown

Open in StackBlitz

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

commit: b283582

@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

No changes needing a change description found.

@JoshLove-msft JoshLove-msft added this pull request to the merge queue Jul 1, 2026
@JoshLove-msft JoshLove-msft removed this pull request from the merge queue due to a manual request Jul 1, 2026
@JoshLove-msft JoshLove-msft added this pull request to the merge queue Jul 1, 2026
Merged via the queue into microsoft:main with commit 3e10b83 Jul 1, 2026
29 checks passed
@JoshLove-msft JoshLove-msft deleted the jolov/csharp-explode-query-fix branch July 1, 2026 23:47
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.

[Bug]: C# client emits wrong query string for @query(#{explode: true}) on nested object models

2 participants