openapi-generators / openapi-generators/openapi-python-client
`File.file_name` marked as `Optional` but is required when used in `multipart/form-data`
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 2k
- フォーク
- 293
- 平均マージ
- 34分
- マージ済み PR(30日)
- 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 にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
リンクされた templates/types.py.jinja の定義から始め、生成されたクライアントで multipart/form-data のファイルフィールドがどのように表現されるかを追跡します。提示された UploadRequest 仕様を再現し、その後、必須の multipart ファイルでは生成された型で file_name も必須となり、報告されたバックエンドエラーを回避できることを確認します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- api
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100