Skip to content

[BUG][PYTHON-CLIENT] Generated Imports Do Not Respect Custom Folder Names Set via --additional-properties #20918

Description

@claudiadpp

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

When generating a Python client with OpenAPI Generator, the generated import paths do not respect the custom folder names set via --additional-properties (e.g., modelPackage=dto, apiPackage=service). Although some imports correctly use the custom folder names, others incorrectly reference the default folder names (models and service), leading to inconsistencies and potential import errors.

Examples of incorrect and correct imports:

  • In the generated init.py APIs are incorrectly imported as
    from service.fake_api import FakeApi
    Instead of the expected
    from openapi_client.service.fake_api import FakeApi.

  • However, in the same file, model imports are correctly generated
    from openapi_client.dto.api_response import ApiResponse.

  • In other files, such as pet_api.py, models are incorrectly imported from the default modules folder, instead of the specified dto folder from openapi_client.models.api_response import ApiResponse.

Expected Behaviour

The generator should consistently apply the modelPackage and apiPackage folder names across all imports, avoiding mismatches between expected and generated imports.

openapi-generator version

7.11.0

OpenAPI declaration file content or url

OpenAPI's Generator petstore api examples:

Command line used for generation

docker run --rm
-v ${PWD}:/local openapitools/openapi-generator-cli generate
-i /local/apis/petstore.yml
-g python
--additional-properties=sourceFolder=,modelPackage=dto,apiPackage=service
-o /local/generated-docker

Steps to reproduce

running the command line on the specified api

Related issues/PRs

A full example, including generated code and expected output, can be found here: claudiadpp/openapi-python-demo#1

  • Generated Code (Incorrect Imports): View Here
  • Expected Output (Fixed Imports): View Here
Suggest a fix

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions