OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.88k stars 6.59k forks source link

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

Open viccie30 opened 1 month ago

viccie30 commented 1 month ago

Bug Report Checklist

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 commented 1 month ago

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

wing328 commented 1 month ago

please also try the modelNameMappings option: https://github.com/openapitools/openapi-generator/blob/master/docs/customization.md#name-mapping