openapi-generators / openapi-generators/openapi-python-client
Support array of format: binary items in multipart/form-data request bodies
未关闭
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 2k
- 派生
- 293
- 平均合并
- 34 分钟
- 30 天内合并 PR
- 1
描述
Describe the bug
When an OpenAPI 3.0 schema defines a property as an array of binaries inside a multipart/form-data requestBody, the generator currently treats it as a JSON body and emits a single body parameter. As a result:
- The generated
sync_detailed(...)signature has only:
def sync_detailed(
*,
client: Client,
body: UploadFilesPostBody,
hash_: str,
) -> Response[Any]:
…
- Internally
body.files(a list ofFileobjects withpayload: BinaryIO) is passed tojson=…, causing serialization errors.
OpenAPI Spec File
paths:
/upload_files:
post:
requestBody:
content:
multipart/form-data:
schema:
type: object
properties:
hash_:
type: string
files:
type: array
items:
type: string
format: binary
responses:
'200':
description: OK
What actually happens
- The generator emits a single body: UploadFilesPostBody parameter.
- When calling sync_detailed(..., body=…), httpx is invoked with json=… and fails on BinaryIO because it isn’t valid JSON.
Desktop:
- OS: Windows 10
- Python Version: cPython 3.12.8
- openapi-python-client version 0.24.3
Additional context
None - if anything is needed, please let me know
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先跟踪处理 multipart/form-data 请求正文的 generator 路径,并将其与 issue 中描述的生成的 sync_detailed(...) 方法进行比较。确认生成的 client 将 files 字段作为 multipart 数据发送,而不是通过 httpx json= 发送;如果 repository 中有相关的 generator 测试位置,则为提供的 OpenAPI schema 添加覆盖测试。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- openapi, python
- 领域
- api, tooling
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 48/100