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.81k stars 6.58k forks source link

[BUG][PYTHON] Deserialize json vendor extensions broken since 7.7.0 #19285

Closed kevinferrare closed 2 months ago

kevinferrare commented 3 months ago

Bug Report Checklist

Description

Since this commit, generated python api_client cannot handle deserializing json with a content type that does not start with application/json. For example vendor extensions like application/vnd.amadeus+json

https://www.iana.org/assignments/media-types/application/vnd.amadeus+json

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

openapi-generator version

7.7.0

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  title: Test
  version: '1.0'
paths:
  '/test':
    get:
      requestBody:
        content:
          application/vnd.amadeus+json:
            schema:
              type: object
              title: TestObject
              properties:
                id:
                  type: string
      responses:
        '200':
          description: OK
Generation Details

java -jar openapi-generator-cli-7.8.0-SNAPSHOT.jar generate -o ./generated -i ./test-api.yaml -g python

Steps to reproduce

Save the API declaration in a file and generate it.

When calling test_get() method, it fails with an exception because it doesnt understand application/vnd.amadeus+json is json:

ApiException: (0) Reason: Unsupported content type: application/vnd.amadeus+json;charset=UTF-8
Related issues/PRs

None I could find

Suggest a fix

In the api_client files updated by the commit I mention, Replace:

elif content_type.startswith("application/json"):

With:

elif content_type.startswith("application/json") or content_type.endswith("+json"):
fa0311 commented 3 months ago

related: #18800