openapi-generators / openapi-generators/openapi-python-client
`File.file_name` marked as `Optional` but is required when used in `multipart/form-data`
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 2k
- Fork
- 293
- Merge trung bình
- 34 phút
- Pull request đã merge (30 ngày)
- 1
Mô tả
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
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu từ định nghĩa được liên kết trong templates/types.py.jinja và theo dõi cách các trường tệp multipart/form-data được biểu diễn trong các client được tạo. Tái hiện đặc tả UploadRequest được cung cấp, sau đó xác minh rằng một tệp multipart bắt buộc cũng yêu cầu file_name trong kiểu được tạo và tránh được lỗi backend đã báo cáo.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- api
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100