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

Commit fd45d36

Browse files
msyycCopilot
andcommitted
docs: clarify Http.File request body compatibility
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>
1 parent 04d6229 commit fd45d36

2 files changed

Lines changed: 44 additions & 0 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# `Http.File` request body compatibility for Python
2+
3+
## Problem
4+
5+
When a TypeSpec operation uses `Http.File` as the request body type, the Python emitter generates an SDK method input type of `IO[bytes] | bytes`.
6+
7+
For migrated Swagger APIs, this must remain compatible with previous SDKs where Swagger `type: file` was represented as `bytes`.
8+
9+
## Compact example
10+
11+
TypeSpec:
12+
13+
```typespec
14+
import "@typespec/http";
15+
16+
using TypeSpec.Http;
17+
18+
@route("/files")
19+
namespace Files;
20+
21+
@post
22+
op upload(@body body: Http.File): void;
23+
```
24+
25+
Python SDK (generated shape):
26+
27+
```python
28+
from typing import IO, Union
29+
30+
def upload(self, body: Union[IO[bytes], bytes], **kwargs) -> None:
31+
...
32+
```
33+
34+
## Compatibility statement
35+
36+
- Swagger `type: file` callers pass `bytes`.
37+
- `bytes` is still accepted by `Union[IO[bytes], bytes]`.
38+
- Existing `bytes`-based callsites continue to work without code changes.
39+
40+
Therefore, migrating this shape from Swagger to TypeSpec is **non-breaking** for existing Python SDK consumers.

docs/developer/readme.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,7 @@ To test an unpublished branded emitter tarball, please follow these steps:
1212
6. Paste the url as the version for the `"@azure-tools/typespec-python"` package
1313
7. Run `tsp-client generate-lock-file` from the `azure-sdk-for-python/eng` folder
1414
8. Go to the sdk you'd like to regenerate with the tarball, then run `tsp-client update` how you normally would
15+
16+
## Design Notes
17+
18+
- [`Http.File` request body compatibility for Python](./http_file_body_compatibility.md)

0 commit comments

Comments
 (0)