Skip to content

[BUG][python-flask] binary response type is generated with rtype file #4372

@frjonsen

Description

@frjonsen
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
  1. Copy yaml above to openapi.yml
  2. Run java -jar openapi-generator-cli-4.1.3.jar generate -g python-flask -i openapi.yml
  3. 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 maps file to file. Presumably this should map to something like str or bytearray.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions