Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Python client generator doesn't handle schema clashes #19612

Closed
5 of 6 tasks
brendanator opened this issue Sep 18, 2024 · 2 comments
Closed
5 of 6 tasks

[BUG] Python client generator doesn't handle schema clashes #19612

brendanator opened this issue Sep 18, 2024 · 2 comments

Comments

@brendanator
Copy link

brendanator commented Sep 18, 2024

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

The GitHub openapi spec contains a commit object which contains an inner commit object.

When I generate a client using the Python generator only the inner commit object is generated

openapi-generator version
$ docker run --rm openapitools/openapi-generator-cli:latest --version
openapi-generator-cli 7.9.0-SNAPSHOT
  commit : ca378b4
  built  : -999999999-01-01T00:00:00+18:00
  source : https://github.com/openapitools/openapi-generator
  docs   : https://openapi-generator.tech/
OpenAPI declaration file content or url

Here's the full GitHub openapi spec and here's the relevant snippet

      "commit": {
        "title": "Commit",
        "description": "Commit",
        "type": "object",
        "properties": {
          ...
          "commit": {
            "type": "object",
            "properties": {
              "url": {
                "type": "string",
                "format": "uri",
                "example": "https://api.github.com/repos/octocat/Hello-World/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e"
              },
              "author": {
                "$ref": "#/components/schemas/nullable-git-user"
              },
              "committer": {
                "$ref": "#/components/schemas/nullable-git-user"
              },
              "message": {
                "type": "string",
                "example": "Fix all the bugs"
              },
              "comment_count": {
                "type": "integer",
                "example": 0
              },
              "tree": {
                "type": "object",
                "properties": {
                  "sha": {
                    "type": "string",
                    "example": "827efc6d56897b048c772eb4087f854f46256132"
                  },
                  "url": {
                    "type": "string",
                    "format": "uri",
                    "example": "https://api.github.com/repos/octocat/Hello-World/tree/827efc6d56897b048c772eb4087f854f46256132"
                  }
                },
                "required": [
                  "sha",
                  "url"
                ]
              },
              "verification": {
                "$ref": "#/components/schemas/verification"
              }
            },
            "required": [
              "author",
              "committer",
              "comment_count",
              "message",
              "tree",
              "url"
            ]
          },
          ...
Generation Details
docker run --rm -v /tmp:/local openapitools/openapi-generator-cli:latest generate \
  --input-spec https://raw.githubusercontent.com/github/rest-api-description/main/descriptions/api.github.com/api.github.com.2022-11-28.json \
  --generator-name python \
  --output /local
Steps to reproduce
  1. Run the docker generation command above
  2. cat /tmp/openapi_client/models/commit.py
  3. See that it is the inner commit object and the outer one does not exist
Suggest a fix

I suggest including the outer name in the name of nested objects - in this case the inner class would be named CommitCommit

@wing328
Copy link
Member

wing328 commented Sep 24, 2024

to have complete control of inline schema naming, please refer to https://github.com/openapitools/openapi-generator/blob/master/docs/customization.md#inline-schema-naming

@brendanator
Copy link
Author

Thanks @wing328

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants