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

[BUG][Python] Gradle plugin produces a broken Python client with syntax errors #19835

Open sqeph opened 1 month ago

sqeph commented 1 month ago

Bug Report Checklist

Description

I have an OpenAPI spec for which I can build a working Python client without errors using npx openapi-generator-cli generate. In our bigger project setup we use the Gradle plugin to generate a variety of clients for our API. In this setting, the generated Python client is exactly the same as the NPX CLI version, except for a syntax error due to a missing newline (see example below).

class DefaultApi:
    ..
    @validate_call
    def get_root(..):
        ..
        _response_types_map: Dict[str, Optional[str]] = {
            '200': "object",
        }        response_data = self.api_client.call_api(  # Note the missing newline here (before response_data)
            *_param,
            _request_timeout=_request_timeout
        )
        ..
    ..

The spec given here is a minimal example, but for a bigger spec the error repeats itself across all API operation methods, i.e. wherever the response_data = .. statement appears. The client built using NPX does not have this issue.

openapi-generator version

7.8.0

OpenAPI declaration file content or url
{
    "openapi": "3.1.0",
    "info": {
        "title": "My API",
        "version": "0.1.0"
    },
    "paths": {
        "/": {
            "get": {
                "summary": "Get Root",
                "operationId": "get_root",
                "responses": {
                    "200": {
                        "description": "Successful Response",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "title": "Response Get Root"
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Generation Details
generatorName: python
additionalProperties:
  packageName: my_python_client
  packageVersion: 0.1.0
  projectName: my-python-client
Steps to reproduce

Build Python client based on above specs using the OpenAPI Generator Gradle plugin.

Related issues/PRs

No related issues found.

Suggest a fix

Clueless as to why this happens with the Gradle plugin. Any help is much appreciated!

wing328 commented 1 month ago

7.8.0

we just released openapi generator v7.9.0

please upgrade and see if the issue persists