Bug Report Checklist
Description
When generating a Python FastAPI server with OpenAPI Generator, the generated import paths do not respect the custom folder names set via --additional-properties (e.g., modelPackage=dto, apiPackage=service). Instead, the generated code incorrectly references default folders, leading to errors. When using default folder names, imports are generated correctly. It is only using custom folder names via the --aditional-properties flag, the generated imports for both server and client code do not always reflect the custom folder names.
-
The generated imports for models incorrectly reference the default folder name (e.g., models) instead of the custom folder (e.g dto).
from serverPetAPI.models.user import User
Uses default 'models' instead of 'dto'. This causes the error
from serverPetAPI.models.user import User ModuleNotFoundError: No module named 'serverPetAPI.models'
-
The generated imports may incorrectly reference the base folder (e.g., service) rather than the expected custom folder structure (e.g., serverPetAPI.service).
from service.user_api_base import BaseUserApi
Imports directly from service instead of serverPetAPI. This causes the error
from service.user_api_base import BaseUserApi ModuleNotFoundError: No module named 'service'
Both cases can be found in the user_api.py file:
- Incorrect generated file can be found here
- Expected generated file can be found here
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-fastapi
--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 FastAPI server with OpenAPI Generator, the generated import paths do not respect the custom folder names set via --additional-properties (e.g., modelPackage=dto, apiPackage=service). Instead, the generated code incorrectly references default folders, leading to errors. When using default folder names, imports are generated correctly. It is only using custom folder names via the
--aditional-propertiesflag, the generated imports for both server and client code do not always reflect the custom folder names.The generated imports for models incorrectly reference the default folder name (e.g., models) instead of the custom folder (e.g dto).
from serverPetAPI.models.user import UserUses default 'models' instead of 'dto'. This causes the error
from serverPetAPI.models.user import User ModuleNotFoundError: No module named 'serverPetAPI.models'The generated imports may incorrectly reference the base folder (e.g., service) rather than the expected custom folder structure (e.g., serverPetAPI.service).
from service.user_api_base import BaseUserApiImports directly from service instead of serverPetAPI. This causes the error
from service.user_api_base import BaseUserApi ModuleNotFoundError: No module named 'service'Both cases can be found in the user_api.py file:
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-fastapi
--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