openapi-generators / openapi-generators/openapi-python-client
`File.file_name` marked as `Optional` but is required when used in `multipart/form-data`
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 2k
- 派生
- 293
- 平均合并
- 34 分钟
- 30 天内合并 PR
- 1
描述
Describe the bug
In types.py:
file_name is marked Optional, so it seems like the user could omit it. But if they do to a multipart/form endpoint, backends such as DjangoRestFramework will return:
Status Code: 400 (Bad Request)
Content : {"file":["The submitted data was not a file. Check the encoding type on the form."]}
This means that users will not get a type checking error if they forget to include a file_name in this scenario.
It seems like perhaps a MultipartFile type is needed to be used to correctly model this?
@define
class MultipartFile:
"""Contains information for multipart file uploads"""
payload: BinaryIO
file_name: str
mime_type: Optional[str] = None
...
OpenAPI Spec File
/upload/:
post:
operationId: upload
requestBody:
content:
multipart/form-data:
schema:
$ref: '#/components/schemas/UploadRequest'
required: true
components:
schemas:
UploadRequest:
type: object
properties:
file:
type: string
format: binary
required:
- file
Desktop (please complete the following information):
- OS: macOS 13.6.4
- Python Version: 3.12.0
- openapi-python-client version: 0.16.1
Additional context
The generated Swagger UI page for this endpoint looks like:
Backend versions:
- Django 4.2.11
- djangorestframework 3.14.0
- drf-spectacular 0.27.1
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从链接的 templates/types.py.jinja 定义开始,跟踪 multipart/form-data 文件字段在生成的客户端中的表示方式。复现提供的 UploadRequest 规范,然后验证必需的 multipart 文件在生成的类型中也要求 file_name,并避免报告的后端错误。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- api
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100