OpenAPITools / OpenAPITools/openapi-generator
[BUG][PYTHON-CLIENT] Generated Imports Do Not Respect Custom Folder Names Set via --additional-properties
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
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: https://github.com/claudiadpp/openapi-python-demo/pull/1
Suggest a fix
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 by running the reported Docker generation command with the petstore API and custom modelPackage=dto and apiPackage=service values. Inspect the generated init.py and pet_api.py files, comparing their imports with the linked expected output. Done means all generated imports consistently use the configured folder names without references to default modules.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100