OpenAPITools / OpenAPITools/openapi-generator
[BUG] Schema named `map` unusable with Python code generator
Nobody has claimed this yet.
- 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
- Generate a Python client library using the command line above.
- Note that output/openapi_client/models/map.py is created, containing a class
Map. - Note that output/openapi_client/api/default_api.py tries to import the non-existing class
Dictfrom the non-existing moduleopenapi_client.models.dictinstead.
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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