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] Schema named map unusable with Python code generator #19655

Open
5 of 6 tasks
viccie30 opened this issue Sep 23, 2024 · 2 comments
Open
5 of 6 tasks

[BUG] Schema named map unusable with Python code generator #19655

viccie30 opened this issue Sep 23, 2024 · 2 comments

Comments

@viccie30
Copy link

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

Referencing a schema component named map makes openapi-generator generate incorrect Python code for API calls using that component.

openapi-generator version

7.8.0 and SNAPSHOT 7.9.0-20240922.165752-71

OpenAPI declaration file content or url
openapi: 3.0.1
info:
  title: Title
  version: "0"
paths:
  /:
    get:
      responses:
        "200":
          description: Successful operation
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/map"
components:
  schemas:
    map:
      type: object
      properties:
        description:
          type: string
Generation Details

java -jar openapi-generator-cli.jar generate -g python -i openapi.yaml -o output

Steps to reproduce
  1. Generate a Python client library using the command line above.
  2. Note that output/openapi_client/models/map.py is created, containing a class Map.
  3. Note that output/openapi_client/api/default_api.py tries to import the non-existing class Dict from the non-existing module openapi_client.models.dict instead.
Related issues/PRs
Suggest a fix

It seems that the type map is mapped twice in AbstractPythonCodegen.java. Once on lines 712-715 and again on lines 742-747. I don't know what the expected behavior is supposed to be, but this does not seem right.

@viccie30
Copy link
Author

A workaround is to add --type-mappings map=Map to the command line.

@viccie30 viccie30 reopened this Sep 23, 2024
@wing328
Copy link
Member

wing328 commented Sep 23, 2024

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