Skip to content

fix: simplify isBinaryPayload to use encode="bytes" as binary signal#3958

Merged
JialinHuang803 merged 8 commits into
mainfrom
copilot/revert-pr-3918-changes
May 25, 2026
Merged

fix: simplify isBinaryPayload to use encode="bytes" as binary signal#3958
JialinHuang803 merged 8 commits into
mainfrom
copilot/revert-pr-3918-changes

Conversation

Copilot AI commented May 12, 2026

Copy link
Copy Markdown
Contributor

Fixes #3913

Background

In TCGC, the encoding for a bytes body is determined as follows:

  • For */* and application/octet-stream content types, TCGC natively sets encode to "bytes".
  • For all other content types (e.g., application/json, application/xml), a bytes body defaults to "base64" encoding — unless the user explicitly annotates the body with @encode("bytes"), which overrides the encode to "bytes".

Change

Given the TCGC behavior above, isBinaryPayload is extended with an optional encode parameter. When encode === "bytes", the function returns true immediately.

This approach:

  • Naturally handles the */* case — since TCGC already sets encode to "bytes" for wildcard and application/octet-stream content types, no special-casing for */* is needed anymore. The dedicated */* wildcard detection path can be removed in favor of this unified encode-based check.
  • Correctly handles explicit @encode("bytes") annotations on non-binary content types (e.g., application/json + @encode("bytes") → treated as binary).
  • Keeps backward compatibility with m4 → TCGC migration, since the encode field reliably reflects the wire-level intent.

Call sites updated

Three Modular call sites in operationHelpers.ts are updated to pass getEncodeForType(...) as the new encode argument:

  • getDeserializePrivateFunction (response deserialization)
  • buildBodyParameter (request body serialization)
  • checkWrapNonModelReturn (non-model return wrapping)

Scope note

The RLC call site at transform/transformResponses.ts:176 is intentionally not updated in this PR. The RLC pipeline passes a raw TypeSpec Type (not a TCGC SdkType), so getEncodeForType is not directly available there. RLC behavior is unchanged by this PR.

Follow-up

A separate issue will track refactoring isBinaryPayload to operate on SdkType directly so we can drop the __raw dependency and the encode-based coupling. See #4001.

Tests

Added snapshot scenarios under test/modularUnit/scenarios/operations/bodyParam/bytesWithDifferentContentType.md covering:

  • bytes + */* → binary
  • bytes + application/xml + @encode("bytes") → binary
  • bytes + application/json + @encode("bytes") → binary
  • bytes + text/plain + @encode("bytes") (current behavior captured)
  • bytes + application/json (no @encode) → base64 (not binary)
  • Request-body variants of the above.

kazrael2119 and others added 3 commits May 12, 2026 08:28
(cherry picked from commit c2f06b1)

Co-authored-by: kazrael2119 <98569699+kazrael2119@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Azure/autorest.typescript/sessions/c5b9a83f-2fec-4bc7-b44b-2393f9d65a94

Co-authored-by: kazrael2119 <98569699+kazrael2119@users.noreply.github.com>
Copilot AI changed the title [WIP] Revert changes from PR #3918 Isolate binary payload @encode("bytes") handling from PR #3918 May 12, 2026
Copilot AI requested a review from kazrael2119 May 12, 2026 08:40
@kazrael2119 kazrael2119 changed the title Isolate binary payload @encode("bytes") handling from PR #3918 fix: simplify isBinaryPayload to use encode="bytes" as binary signal May 12, 2026
@qiaozha qiaozha added p0 priority 0 HRLC labels May 13, 2026
@JialinHuang803 JialinHuang803 marked this pull request as ready for review May 15, 2026 05:59
@JialinHuang803 JialinHuang803 enabled auto-merge (squash) May 25, 2026 08:32
@JialinHuang803 JialinHuang803 merged commit d219163 into main May 25, 2026
16 checks passed
@JialinHuang803 JialinHuang803 deleted the copilot/revert-pr-3918-changes branch May 25, 2026 08:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

HRLC p0 priority 0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[typespec-ts] */* content type should be treated as binary when body is bytes

4 participants