swagger-api / swagger-api/swagger-codegen

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

Open
#11,993 1 comment 1 reaction 0 assignees View on GitHub

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.

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?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.