swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
16.91k stars 6.03k forks source link

[PYTHON] Should be possibile to remove package name from the generated model names #11993

Open enricorotundo opened 1 year ago

enricorotundo commented 1 year ago
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.

Screenshot 2022-12-15 at 11 29 40

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?

enricorotundo commented 1 year ago

Similar but not quite the same question. The generated API modules are suffixed with _api. I argue that's not needed because they're already within the api folder. Is there an option to disable this?

Screenshot 2022-12-15 at 12 21 40