fix: simplify isBinaryPayload to use encode="bytes" as binary signal#3958
Merged
Conversation
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>
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 May 12, 2026
@encode("bytes") handling from PR #3918
@encode("bytes") handling from PR #3918
JialinHuang803
approved these changes
May 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3913
Background
In TCGC, the encoding for a bytes body is determined as follows:
*/*andapplication/octet-streamcontent types, TCGC natively setsencodeto"bytes".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,
isBinaryPayloadis extended with an optionalencodeparameter. Whenencode === "bytes", the function returnstrueimmediately.This approach:
*/*case — since TCGC already setsencodeto"bytes"for wildcard andapplication/octet-streamcontent types, no special-casing for*/*is needed anymore. The dedicated*/*wildcard detection path can be removed in favor of this unified encode-based check.@encode("bytes")annotations on non-binary content types (e.g.,application/json+@encode("bytes")→ treated as binary).encodefield reliably reflects the wire-level intent.Call sites updated
Three Modular call sites in
operationHelpers.tsare updated to passgetEncodeForType(...)as the newencodeargument:getDeserializePrivateFunction(response deserialization)buildBodyParameter(request body serialization)checkWrapNonModelReturn(non-model return wrapping)Scope note
The RLC call site at
transform/transformResponses.ts:176is intentionally not updated in this PR. The RLC pipeline passes a raw TypeSpecType(not a TCGCSdkType), sogetEncodeForTypeis not directly available there. RLC behavior is unchanged by this PR.Follow-up
A separate issue will track refactoring
isBinaryPayloadto operate onSdkTypedirectly so we can drop the__rawdependency and the encode-based coupling. See #4001.Tests
Added snapshot scenarios under
test/modularUnit/scenarios/operations/bodyParam/bytesWithDifferentContentType.mdcovering:*/*→ binaryapplication/xml+@encode("bytes")→ binaryapplication/json+@encode("bytes")→ binarytext/plain+@encode("bytes")(current behavior captured)application/json(no@encode) → base64 (not binary)