openapi-generators / openapi-generators/openapi-python-client

Skip setting 'Content-Type' on file upload, when multiple bodies are supported

未关闭 适合新手
#947 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
Python
星标
2k
派生
293
平均合并
34 分钟
30 天内合并 PR
1

描述

Describe the bug
Form-style submissions to endpoints that support multiple different content types are missing the necessary "boundary" attribute on the Content-Type header.

POST https://.../items HTTP/1.1
Host: ...
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
User-Agent: python-httpx/0.25.2
Authorization: Bearer ...
Content-Type: multipart/form-data
Transfer-Encoding: chunked

Cause
https://github.com/openapi-generators/openapi-python-client/blob/660941dfe23a39ea9a22dd724e1db54afb130d08/openapi_python_client/templates/endpoint_module.py.jinja#L48-L63

In the template above, lines 60-62 have an "if content-type is not multipart/form-data" condition since httpx sets content type and multipart form boundary properly when files are provided. The same condition needs to be applied around line 54, which occurs when multiple body types are supported.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 openapi_python_client/templates/endpoint_module.py.jinja 开始,尤其检查第 48-63 行附近的 Content-Type 处理以及现有的 multipart 条件。验证支持多种 body 类型的 endpoint 所生成的 requests,并在 multipart 上传获得 Content-Type boundary 且不覆盖 httpx 的 header 处理时,视为工作完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
api
Issue 类型
缺陷
难度
2/5
预计耗时
1-3 小时
活跃度
停滞
描述清晰度
描述清楚
新手友好度
65/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。