OpenAPITools / OpenAPITools/openapi-generator
[BUG] [python-fastapi] fastapiImplementationPackage ignores packageName option in favor of the "openapi_server.impl" default package name
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 running the openapi-generator with the argument
All generated apis Python files will import
import openapi_server.impl
instead of the expected
import my_package.impl
I did not provide an example swagger.yml file as this is a general problem for arbitrary files.
openapi-generator version
v7.9.0
Generation Details
generate -i swagger.yml \
-g python-fastapi \
-o out \
--additional-properties=packageName=my_package
Suggest a fix
I think the following line within modules\openapi-generator\src\main\java\org\openapitools\codegen\languages\PythonFastAPIServerCodegen.java could fix for that (or the documentation of python-fastapi generator should be adapted):
@Override
public void processOpts() {
super.processOpts();
if (additionalProperties.containsKey(CodegenConstants.PACKAGE_NAME)) {
setPackageName((String) additionalProperties.get(CodegenConstants.PACKAGE_NAME));
}
should read
@Override
public void processOpts() {
super.processOpts();
if (additionalProperties.containsKey(CodegenConstants.PACKAGE_NAME)) {
setPackageName((String) additionalProperties.get(CodegenConstants.PACKAGE_NAME));
this.implPackage = ((String) additionalProperties.get(CodegenConstants.PACKAGE_NAME)).concat(".impl");
}
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 in modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonFastAPIServerCodegen.java and inspect processOpts(), especially how packageName and implPackage are initialized. Run the supplied python-fastapi CLI command with packageName=my_package and verify that generated API files import my_package.impl instead of openapi_server.impl.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- fastapi, java, openapi, python
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100