Bug Report Checklist
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
Suggest a fix
Bug Report Checklist
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 FakeApiInstead 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
Suggest a fix