[BUG] [Python] Incorrect name attribute when uploading file / form data
Created by: plague006
Bug Report Checklist
-
Have you provided a full/minimal spec to reproduce the issue? -
Have you validated the input using an OpenAPI validator (example)? -
Have you tested with the latest master to confirm the issue still exists? -
Have you searched for related issues/PRs? -
What's the actual output vs expected output? -
[Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
Uploads to API endpoints were not working. The server says that no file was uploaded. I traced the cause to
openapi-generator version
5.3.0 (since at least 5.1.X)
OpenAPI declaration file content or url
Full spec: https://cs.business.stingray.com/assets/swagger.yaml
Relevant snippet:
post:
parameters:
- in: formData
name: file-en
type: file
required: false
Generation Details
--generator-name python
Steps to reproduce
Attempt to upload a file, note that the name
sent is file_en
and not file-en
.
Related issues/PRs
Suggest a fix
I was able to get things working by changing params['file'][param_name] = [param_value]
to params['file'][base_name] = [param_value]
in api_client.py:745 and api_client.py:749 of my generated client. In the api_client mustache, that would be: https://github.com/OpenAPITools/openapi-generator/blob/b3ec7faa8fc55d89f8df5ccc7e394fb8cb87f299/modules/openapi-generator/src/main/resources/python/api_client.mustache#L765-L769