Open frjonsen opened 5 years ago
👍 Thanks for opening this issue! 🏷 I have applied any labels matching special text in your issue.
The team will review the labels and make any necessary changes.
I think this issue still exists. The comments in https://github.com/OpenAPITools/openapi-generator/blob/7bb7c72cc53c8063c781ea0b38691cca4955a29f/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonCodegen.java#L94-L98 mention a "workaround", can anyone shed some light on what is worked around here?
I use Docker image openapitools/openapi-generator-cli:v5.4.0
. For me both binary
as well as byte
result in type file
. Support for Python2 is disabled in the generator (supportPython2: false
).
It looks like byte
results in type string
(with 5.4.0) - i dont believe this is correct either - a byte definition in the openapi spec should result in the generator expecting type bytes
edit: my findings are in python
not python-flask
Per the spec https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.2.md#data-types
type: string
format: byte
means base64 encoded characters
so while one could convert the value to binary, the value starts out as a base64 encoded string, so I think that storing a string is appropriate for that base64 encoded string
value
One can also have a schema like:
someString:
allOf:
- type: string
- type: string
format: byte
So it helps to have the data type be consistent for the two allOf schemas inside someString.allOf
Description
When setting the response type as
type: string
andformat: binary
, the return type is generated asfile
, even though the documentation states thatfile
is no longer a data type in OpenAPI 3.0, as mentioned here: https://swagger.io/docs/specification/data-models/data-types/#fileformat: byte
is correctly generated asbytearray
.This becomes a problem for us as we use custom templates to set the return type of functions (
{{#returnType}} -> {{.}}{{/returnType}}
), which will result infile
, 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
Command line used for generation
java -jar openapi-generator-cli-4.1.3.jar generate -g python-flask -i openapi.yml
Steps to reproduce
openapi.yml
java -jar openapi-generator-cli-4.1.3.jar generate -g python-flask -i openapi.yml
openapi_server/controllers/default_controller.py
now 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 mapsfile
tofile
. Presumably this should map to something likestr
orbytearray
.