OpenAPITools / OpenAPITools/openapi-generator
[BUG][python-flask] binary response type is generated with rtype `file`
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
When setting the response type as type: string and format: binary, the return type is generated as file, even though the documentation states that file is no longer a data type in OpenAPI 3.0, as mentioned here: https://swagger.io/docs/specification/data-models/data-types/#file
format: byte is correctly generated as bytearray.
This becomes a problem for us as we use custom templates to set the return type of functions ({{#returnType}} -> {{.}}{{/returnType}}), which will result in file, which is not valid in python, meaning the resulting generated code does not run.
openapi-generator version
Tested with 4.1.3, as well as these snapshots:
openapi-generator-cli-4.2.1-20191104.150105-22
openapi-generator-cli-5.0.0-20191024.154544-16
OpenAPI declaration file content or url
openapi: 3.0.0
info:
title: Python binary response
version: 1.0.0
paths:
"/foo":
post:
responses:
"200":
description: "Success"
content:
application/octet-stream:
schema:
type: string
format: binary
Command line used for generation
java -jar openapi-generator-cli-4.1.3.jar generate -g python-flask -i openapi.yml
Steps to reproduce
- Copy yaml above to
openapi.yml - Run
java -jar openapi-generator-cli-4.1.3.jar generate -g python-flask -i openapi.yml openapi_server/controllers/default_controller.pynow contains a single function, with:rtype: file
Related issues/PRs
None which I could find
Suggest a fix/enhancement
I am unfamiliar with the code base, but what I could find was that here the type file is declared as a primitive of Python, which I don't think is the case. It also maps file to file. Presumably this should map to something like str or bytearray.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the issue with the supplied OpenAPI YAML and python-flask generation command, then inspect PythonAbstractConnexionServerCodegen.java and the generated openapi_server/controllers/default_controller.py. Compare the binary response mapping with the correctly generated byte mapping. Done means the generated return type is valid Python rather than file, while the existing byte behavior remains unchanged.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- flask, java, openapi, python
- Domain
- api, backend, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 38/100