Skip to content

Add warning when bytes body is used with XML content type#9972

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/fix-xml-bytes-serialization
Draft

Add warning when bytes body is used with XML content type#9972
Copilot wants to merge 3 commits intomainfrom
copilot/fix-xml-bytes-serialization

Conversation

Copy link
Contributor

Copilot AI commented Mar 9, 2026

When bytes is used as a body type with an XML content type (e.g. application/xml), the payload is silently treated as raw binary data rather than structured XML. This adds a warning diagnostic at the @typespec/http level so all downstream emitters (OpenAPI3, AutoRest, etc.) surface the issue.

// Now emits @typespec/http/bytes-xml-body warning
@post op upload(@header contentType: "application/xml", @body body: bytes): void;
  • packages/http/src/lib.ts — New bytes-xml-body warning diagnostic
  • packages/http/src/payload.ts — Detection in resolveHttpPayload() after body resolution; matches XML content types via regex (application/xml, text/xml, application/*+xml); walks scalar inheritance chain to catch types extending bytes
  • packages/http/test/parameters.test.ts — Tests for application/xml, text/xml, application/soap+xml, response bodies, and negative case (application/octet-stream)
Original prompt

This section details on the original issue you should resolve

<issue_title>application/xml bytes treated as binary payload</issue_title>
<issue_description>Following the rule those bytes should be serialized as xml. Which on a different note not sure what it means

Playground Link

bug in typespec-autorest too</issue_description>

Comments on the Issue (you are @copilot in this section)

@markcowl - add a warning when a spec uses this pattern

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix application/xml bytes treated as binary payload Add warning when bytes body is used with XML content type Mar 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

application/xml bytes treated as binary payload

2 participants