swagger-api / swagger-api/swagger-codegen
[PYTHON] Should be possibile to remove package name from the generated model names
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
I generate a python client from an open-api v2 spec that comes from a Golang project.
The generated python module names are prefixed with the source Golang package, for example take model_ + build_version_info.py from the screenshot below.
I believe this is expected because the related definition in the swagger file is "model.BuildVersionInfo". However, this is non-ideal because it makes the python client cluttered! I tried tinkering with --model-name-prefix but it'd just prepend a string and not overrides the existing prefix.
Swagger-codegen version
❯ swagger-codegen version
2.4.29
Swagger declaration file content or URL
https://raw.githubusercontent.com/filecoin-project/bacalhau/main/docs/swagger.json
Command line used for generation
❯ make clean all
rm -f -r python
rm -f *-config.json
cat config.json.template | \
sed -e "s/VERSION/0.3.15/g" | \
sed -e "s/PACKAGE-NAME/bacalhau_client/g"> python-config.json
rm -rf python/ && swagger-codegen generate \
-i ../docs/swagger.json \
-l $(basename python/) \
-o python/ \
-c $(basename python/)-config.json \
--remove-operation-id-prefix \
-Dmodels -DmodelTests=false -DmodelDocs \
-Dapis -DapiTests=false \
-DapiDocs
Related issues/PRs
https://github.com/swagger-api/swagger-codegen/issues/1255
Suggest a fix/enhancement
Instead, I'd like to either remove the model_ prefix, or have sub-packages within the models package. Is this even possible?
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 reproducing the generated Python client with the linked swagger.json, config.json.template, and the shown swagger-codegen generate command. Trace how the model.BuildVersionInfo definition becomes model_ in the Python models, then determine a supported way to remove or replace that prefix; done means generated model names no longer contain the unwanted package prefix without breaking references.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, python
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100