OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.96k stars 6.59k forks source link

[BUG][python-flask] file as primitive #17114

Open RomainCendre opened 1 year ago

RomainCendre commented 1 year ago

Hi everyone, I'm using openapi generator to generate python-flask server for a few weeks, and I have had some concerns since I start using multipart/form-data with a blob. It seems to generate this kind of things : @property def profile_image(self) -> file: 'file' is not defined, but yeah I never seen this kind of type in Python? Is that normal that 'file' is considered as a primitive type even in documentation? I will update the issue if it's a real concern, I'm not sure about it. Thanks a lot

test.yaml:

openapi: 3.1.0
info:
  title: Webhook Example
  version: 1.0.0
servers:
- url: /
paths:
  /somes:
    post:
      operationId: somes_post
      requestBody:
        content:
          multipart/form-data:
            schema:
              $ref: '#/components/schemas/Something'
        description: Somes something
      responses:
        "200":
          description: Return a 200 status to indicate that the data was received
            successfully
      x-openapi-router-controller: openapi_server.controllers.default_controller
components:
  schemas:
    Something:
      properties:
        id:
          format: uuid
          type: string
        address:
          $ref: '#/components/schemas/Something_address'
        profileImage:
          format: binary
          type: string
    Something_address:
      properties:
        street:
          title: street
          type: string
        city:
          title: city
          type: string
      title: Something_address

Generation command: openapi-generator_7.2.0.sh generate -i ./api/v1/test.yaml -g python-flask -o src/test --global-property skipFormModel=false

Run command: python3 -m openapi_server

wing328 commented 1 year ago

@property def profile_image(self) -> file:

Agreed it's a bug that should be fixed.

Ideally what should be used instead of file for your use cases?

RomainCendre commented 1 year ago

@wing328 Thanks for the answer. I should have said probably bytes, as the file was generated for taking care of blob? What do you think? Is there any quick fix that can be done in the openapi-generator project files ? EDIT: Looking at https://github.dev/OpenAPITools/openapi-generator/tree/master/modules/openapi-generator/src/main/resources/python-flask, I still canot understand where file type is considered