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
22.02k stars 6.6k forks source link

[BUG] [python-legacy] No return value if only 'default' response type specified #11793

Open felixvd opened 2 years ago

felixvd commented 2 years ago

Bug Report Checklist

Summary: For endpoints that only specify a default response, python-legacy clients always return None.

Description

If only the default response exists for an endpoint in the schema, that endpoint will pass an empty response_types_map to call_api:

        response_types_map = {}

This is fatal, because it causes the response not to be serialized in __call_api of api_client.py, so each call will return None.

Endpoints where the responses field contains the number codes '200' work:

        response_types_map = {
            200: "list[Pet]",
            400: None,
        }
openapi-generator version

5.4.0

OpenAPI declaration file content or url

https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/test/resources/3_0/petstore_oas3_test.yaml

Generation Details

openapi-generator-cli generate -i petstore_oas3_test.yaml -g python-legacy has both non-working and working endpoints

Steps to reproduce
cd $YOUR_OPENAPI_GENERATOR_REPO
mkdir openapi-legacy-bugged-client && cd openapi-legacy-bugged-client
openapi-generator-cli generate -i ../modules/openapi-generator/src/test/resources/3_0/petstore_oas3_test.yaml -g python-legacy

Open api/pet_api.py with your favorite editor and search for response_types_map = { to see the issue.

Suggest a fix

I don't know yet, but the python generator does not have this problem, so the solution can surely be found in that template. If you know where to look I am thankful for pointers.

resposit commented 6 months ago

I stumbled here because I have exactly the same problem, in my endpoints I only have a default response and I get

response_types_map = {}

I'm using python generator with openapi-generator-cli 7.5.0

Is there a workaround ?

tgrtb commented 4 months ago

Same here, using openapi-generator-cli 7.7.0 and the python generator (not python-legacy)