OpenAPITools / OpenAPITools/openapi-generator
[REQ] [python-fastapi] Automatically importing sub-packages modules in implementation package
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Is your feature request related to a problem? Please describe.
Currently only modules placed in the package {{fastapiImplementationPackage}} are automatically imported: https://github.com/OpenAPITools/openapi-generator/blob/ba169342a1154d8f6694dbb9e759b03aa56e1619/modules/openapi-generator/src/main/resources/python-fastapi/api.mustache#L33-L35
A small improvement would be to also import automatically modules in sub-packages of FastAPI implementation package.
Describe the solution you'd like
This could be supported by replacing pkgutil.iter_modules with pkgutil.walk_packages in modules/openapi-generator/src/main/resources/python-fastapi/api.mustache.
Before:
ns_pkg = {{fastapiImplementationPackage}}
for _, name, _ in pkgutil.iter_modules(ns_pkg.__path__, ns_pkg.__name__ + "."):
importlib.import_module(name)
After:
ns_pkg = {{fastapiImplementationPackage}}
for _, name, _ in pkgutil.walk_packages(ns_pkg.__path__, ns_pkg.__name__ + "."):
importlib.import_module(name)
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/resources/python-fastapi/api.mustache and inspect the existing automatic import loop around pkgutil.iter_modules. Update the template so nested modules in the FastAPI implementation package are included, then verify generated output imports modules from sub-packages as well as the top-level package.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- fastapi, python
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100