OpenAPITools / OpenAPITools/openapi-generator

[BUG] Schema named `map` unusable with Python code generator

Open
#19,655 2 comments 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

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.

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 in modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonCodegen.java at the two mappings identified around lines 712-715 and 742-747. Run the reported Python generation command against the provided OpenAPI YAML and inspect output/openapi_client/models/map.py and api/default_api.py. Done means the generated API imports the existing map model rather than the nonexistent Dict model.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.