Skip to content

[http-client-csharp] Place contentType after body per .NET SDK parameter ordering guideline#10403

Draft
Copilot wants to merge 6 commits intomainfrom
copilot/fix-contenttype-header-order
Draft

[http-client-csharp] Place contentType after body per .NET SDK parameter ordering guideline#10403
Copilot wants to merge 6 commits intomainfrom
copilot/fix-contenttype-header-order

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 16, 2026

Operations with a contentType header placed it before body, violating the .NET SDK parameter ordering guideline. This applies to all operations (both multipart and non-multipart).

Before:

UpdateSkillDefaultVersion(string skillId, string contentType, BinaryContent content, RequestOptions options = null)

After:

UpdateSkillDefaultVersion(string skillId, BinaryContent content, string contentType, RequestOptions options = null)

Changes

  • RestClientProvider.GetMethodParameters: Added a contentType sorting bucket (350) between body (200/300) and optional query/header (400). Content-type headers detected via InputHeaderParameter.IsContentType are routed to this bucket instead of the regular required/optional header buckets. Updated the IsMultipartFormData content-type insertion to also use the contentType bucket for consistency.
  • Back-compat via BackCompatProvider: Added HasContentTypeBeforeBodyInLastContract helper that checks client.BackCompatProvider.LastContractView for a matching method where contentType appears before content (body). If the previous contract had that ordering, the content-type parameter falls through to the regular header bucket to preserve backward compatibility.
  • Tests: Added parameterized TestGetMethodParameters_ContentTypeAfterBody(bool isRequired, bool isExtensibleEnum) using [TestCase] to cover all four combinations of required/optional and string/extensible-enum content-type headers. Added ContentTypeOrderPreservedFromLastContractView validating that the previous ordering is preserved when the last contract had contentType before body, and ContentTypeAfterBodyInLastContractView validating correct ordering when the last contract already had contentType after body.
  • Documentation: Updated backward-compatibility.md with a new "Content-Type Parameter Ordering" section documenting the back-compat preservation case.

… per .NET SDK parameter ordering guideline

Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/1e1f8979-043f-491d-99fb-56cc88deb5ec

Co-authored-by: jorgerangel-msft <102122018+jorgerangel-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 Apr 16, 2026
Copilot AI changed the title [WIP] Fix contentType header order in non-multipart operations [http-client-csharp] Place contentType after body in non-multipart operations per .NET SDK parameter ordering guideline Apr 16, 2026
Copilot AI requested a review from jorgerangel-msft April 16, 2026 19:35
@jorgerangel-msft
Copy link
Copy Markdown
Contributor

@copilot we should also ensure we run Generate.ps1 to regenerate all the test libraries

Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/ef9e7dc8-4921-4b05-a1f3-3250a6daabf4

Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 16, 2026

@copilot we should also ensure we run Generate.ps1 to regenerate all the test libraries

Ran eng/scripts/Generate.ps1 — it completed successfully with no file changes. The generated test libraries are already up to date since none of the Spector specs or Sample-TypeSpec include operations with union content-type headers that would be affected by the parameter reordering. All 1305 unit tests continue to pass.

Comment thread packages/http-client-csharp/generator/docs/backward-compatibility.md Outdated
Comment thread packages/http-client-csharp/generator/docs/backward-compatibility.md Outdated
Comment thread packages/http-client-csharp/generator/docs/backward-compatibility.md Outdated
Comment thread packages/http-client-csharp/generator/docs/backward-compatibility.md Outdated
Comment thread packages/http-client-csharp/generator/docs/backward-compatibility.md Outdated
…ble, improve helper method, simplify docs, add test

Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/fccee42c-bdca-4682-959f-10d2a38d1cad

Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Copilot AI changed the title [http-client-csharp] Place contentType after body in non-multipart operations per .NET SDK parameter ordering guideline [http-client-csharp] Place contentType after body per .NET SDK parameter ordering guideline Apr 16, 2026
Copilot AI requested a review from jorgerangel-msft April 16, 2026 20:18
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 16, 2026

Open in StackBlitz

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

commit: 036e36c

…union scenario

Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/13f79d47-a99d-4a0f-9e22-2fb882de151c

Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 16, 2026

@copilot we should also ensure we run Generate.ps1 to regenerate all the test libraries

Ran eng/scripts/Generate.ps1 after the latest changes — completed successfully with no generated file changes. All 1306 tests pass.

…ng string and extensible enum

Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/db78a7d0-362c-4f81-bed0-5e27e4f10088

Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
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.

[http-client-csharp] Non-multipart operations place contentType header before body, violating .NET parameter ordering guideline

2 participants