You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/developer/http_file_body_compatibility.md
+35-5Lines changed: 35 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,17 @@
1
-
# `Http.File`as Python Request Body
1
+
# `Http.File`Compatibility for Python
2
2
3
3
## Overview
4
4
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:
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**.
41
48
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
+
defdownload(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**.
0 commit comments