OpenAPITools / OpenAPITools/openapi-generator

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

Open
#19,835 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
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!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the minimal OpenAPI declaration with the OpenAPI Generator Gradle plugin and compare its Python output with the npx openapi-generator-cli output. Inspect the generated API operation methods around the response_data statement; done means the Gradle-generated client has valid Python syntax and matches the working npx output.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.