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.3k stars 6.44k forks source link

[BUG] [Python] Response deserealisation is broken, content type #19190

Open genestack-okunitsyn opened 2 months ago

genestack-okunitsyn commented 2 months ago

Bug Report Checklist

Description

Response serialisation doesn't support any other text content types but text/plain. In the openapi declaration provided example that contains content-type: text/csv.

openapi-generator version

7.7.0

OpenAPI declaration file content or url
openapi: "3.0.0"
info:
  version: 1.0.0
  title: Swagger Petstore
servers:
  - url: http://petstore.swagger.io/v1
paths:
  /pets:
    get:
      summary: List all pets
      operationId: listPets
      tags:
        - pets
      parameters:
        - name: type
          in: query
          description: Type of pet
          required: false
          schema:
            enum:
              - cat
              - dog
            type: string
      responses:
        '200':
          description: A paged array of pets
          content:
            text/csv:
              schema:
                $ref: "#/components/schemas/Pets"
        default:
          description: unexpected error
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
components:
  schemas:
    Pet:
      type: object
      required:
        - id
        - name
      properties:
        id:
          type: integer
          format: int64
        name:
          type: string
        tag:
          type: string
    Pets:
      type: array
      maxItems: 100
      items:
        $ref: "#/components/schemas/Pet"
    Error:
      type: object
      required:
        - code
        - message
      properties:
        code:
          type: integer
          format: int32
        message:
          type: string
Generation Details
openapi-generator generate -i definition.yaml -g python -o openapi
Steps to reproduce

It would require any server implementation that returns a response in text/csv format. I haven't one. But from other declaration with the very same content type I have got an error:

E   odm_api.exceptions.ApiException: (0)
E   Reason: Unsupported content type: text/csv;charset=UTF-8
Related issues/PRs

https://github.com/OpenAPITools/openapi-generator/commit/6ae8a8f4c7b00ed15bbb3cfdc49a7b99dbb56c4b

Suggest a fix

I suppose we can substitute this condition in template:

        elif content_type.startswith("text/plain"):

to more general one:

        elif content_type.startswith("text/"):

Link in the code: https://github.com/OpenAPITools/openapi-generator/blob/2f5529a1845d7e5a9239a3b547a487fa5b3cfd29/samples/client/echo_api/python/openapi_client/api_client.py#L408

Adrien-LUDWIG commented 1 week ago

Related to #19285 which describes the same problem for json related MIME types.