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

Commit ec80958

Browse files
msyycCopilot
andcommitted
docs: add Http.File response body section
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 272eb64 commit ec80958

2 files changed

Lines changed: 36 additions & 6 deletions

File tree

docs/developer/http_file_body_compatibility.md

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1-
# `Http.File` as Python Request Body
1+
# `Http.File` Compatibility for Python
22

33
## Overview
44

5-
TypeSpec `Http.File` maps to `IO | bytes` in generated Python SDK methods. This widens the Swagger `type: file` signature (previously `bytes` only) while keeping full backward compatibility.
5+
TypeSpec `Http.File` is emitted differently depending on whether it appears as a request body or a response body:
66

7-
## TypeSpec Definition
7+
- **Request body**: emits `IO | bytes` (widens legacy `bytes`-only signature)
8+
- **Response body**: emits `bytes` (identical to legacy signature)
9+
10+
Both cases preserve full backward compatibility with Swagger `type: file`.
11+
12+
## Request Body
13+
14+
### TypeSpec Definition
815

916
```typespec
1017
import "@typespec/http";
@@ -18,7 +25,7 @@ namespace Files;
1825
op upload(@body body: Http.File): void;
1926
```
2027

21-
## Generated Python SDK
28+
### Generated Python SDK
2229

2330
```python
2431
from typing import IO, overload
@@ -35,7 +42,30 @@ def upload(self, body: IO | bytes, **kwargs) -> None:
3542
...
3643
```
3744

38-
## Backward Compatibility
45+
### Backward Compatibility
3946

4047
Swagger `type: file`(e.g. [`operationId: "WebApps_GetWebSiteContainerLogs"`](https://github.com/Azure/azure-rest-api-specs/blob/main/specification/web/resource-manager/Microsoft.Web/AppService/stable/2024-11-01/WebApps.json#L2675)) generated `bytes`-only input (e.g. [`WebAppsOperations.get_web_site_container_logs(...)`](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/appservice/azure-mgmt-web/azure/mgmt/web/operations/_web_apps_operations.py#L22070)). After migrating to TypeSpec, the input type widens to `IO | bytes`. Since `bytes` is still accepted, existing callers require **no code changes**, making this migration **non-breaking**.
4148

49+
## Response Body
50+
51+
### TypeSpec Definition
52+
53+
```typespec
54+
@route("/files")
55+
namespace Files;
56+
57+
@get
58+
op download(): Http.File;
59+
```
60+
61+
### Generated Python SDK
62+
63+
```python
64+
def download(self, **kwargs) -> bytes:
65+
...
66+
```
67+
68+
### Backward Compatibility
69+
70+
Swagger `type: file` responses also generated `bytes`. The TypeSpec `Http.File` response emits the same `bytes` return type, so existing callers are **completely unaffected**.
71+

docs/developer/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ To test an unpublished branded emitter tarball, please follow these steps:
1515

1616
## Design Notes
1717

18-
- [`Http.File` request body compatibility for Python](./http_file_body_compatibility.md)
18+
- [`Http.File` compatibility for Python](./http_file_body_compatibility.md)

0 commit comments

Comments
 (0)