Skip to content
This repository was archived by the owner on May 22, 2026. It is now read-only.

Python SDK design for Http.File when it appears in non-multipart request body and response body (DO NOT MERGE) - #3351

Closed
Yuchao Yan (msyyc) wants to merge 9 commits into
mainfrom
docs/http-file-body-compatibility
Closed

Python SDK design for Http.File when it appears in non-multipart request body and response body (DO NOT MERGE)#3351
Yuchao Yan (msyyc) wants to merge 9 commits into
mainfrom
docs/http-file-body-compatibility

Conversation

@msyyc

@msyyc Yuchao Yan (msyyc) commented Feb 25, 2026

Copy link
Copy Markdown
Member

No description provided.

Yuchao Yan (msyyc) and others added 6 commits February 25, 2026 10:01
Add a compact design note explaining why TypeSpec Http.File emitting IO[bytes] | bytes is backward compatible with legacy Swagger file APIs that accepted bytes.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@msyyc Yuchao Yan (msyyc) changed the title docs: clarify Http.File request body compatibility Python SDK design for Http.File when it appears in non-multipart request body and response body (DO NOT MERGE) Feb 25, 2026
### Generated Python SDK

```python
def download(self, **kwargs) -> bytes:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This loses both content type and suggested file name. And it is a very dangerous operation for large amounts of data.

@msyyc Yuchao Yan (msyyc) Feb 26, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For

  @route("/base64")
  @scenario
  @scenarioDoc("""
    Test base64 encode for bytes body.
    Expected body:
    "dGVzdA==" (base64 encode of test, in JSON string)
    """)
  op base64(): {
    @header
    contentType: "application/json";

    @body
    @encode(BytesKnownEncoding.base64)
    value: bytes;
  };

Python SDK API will decode it with base64 like

. But what if "content-type" is "application/json" but the response body is not encoded with base64 like this case: https://github.com/microsoft/typespec/blob/4d4afdabef3fed9b2d5f017a61e34286970bbff2/packages/http-specs/specs/type/file/main.tsp#L39-L47. Then typespec type bytes can't work and only Http.File could reprensent this scenario.

That's my understanding why we need Http.File as response body.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants