openapi-generators / openapi-generators/openapi-python-client
`File.file_name` marked as `Optional` but is required when used in `multipart/form-data`
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 2k
- Fork
- 293
- Merge medio
- 34m
- PR unite (30g)
- 1
Descrizione
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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia dalla definizione collegata in templates/types.py.jinja e traccia il modo in cui i campi file multipart/form-data sono rappresentati nei client generati. Riproduci la specifica UploadRequest fornita, quindi verifica che un file multipart obbligatorio richieda anche file_name nel tipo generato ed eviti l'errore segnalato del backend.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- api
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100