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.88k stars 6.03k forks source link

[Python] Generating Unique Module Names #8695

Open anilj1 opened 5 years ago

anilj1 commented 5 years ago
Description

I have two API specs, but the generator for python produces the same module name (openapi_client) for each one. I need to import both into a project. How can I configure the generator to produce to unique package names under the lib directory?

Swagger-codegen version

3.0.0

Swagger declaration file content or url

N/A

Command line used for generation

java -jar ../../Nemo-thirdparty/openapi-generator-3.2.0/modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -i ../test_spec_01.yaml -g python -o ./pyclient

Steps to reproduce

Run above command

Related issues/PRs

N/A

Suggest a fix/enhancement

N/A

anilj1 commented 5 years ago

It is important to know how to generate the python package with API specification specific name. Without it, when I install the package into my virtual python variable (and even in default system level paths), it overwrites the previous 'openapi_client' package.

Can someone please provide the way to generate unique/API specific python package?

I have tried to generate the model and api packages with specific names by using following command line options, but the main package is still the same.

--model-package mymodel --api-package myapi

anilj1 commented 5 years ago

Hi, for now, I programmatically, modified the setup.py file (after it is generated) and changed the value of NAME variable. This workaround has helped solve this problem and I am able to 'install' the individual python module.

Hope this helps others to follow the step and solve this problem in interim. This however should happen more formally from the code generator.

anilj1 commented 5 years ago

Programmatic modification of the NAME variable in setup.py is not helping as it is not really changing the module name "openapi_client" when it installs the package. Can someone please provide a correct method to address this issue? Thank you.

florentin commented 5 years ago

Try adding -DpackageName=new_name

RexGibson commented 5 years ago

running: swagger-codegen generate -i lookerapi.json -l python -o looker_sdk -c config.json didn't work but running: swagger-codegen generate -i lookerapi.json -l python -o looker_sdk -DpackageName=looker did. Thanks!

mkhaled87 commented 4 years ago

Does anyone have idea how to change the class-name in the generated python client code ? It is always "DefaultApi" and I cannot find a suitable param to set using the "-D" option.

Haibo-Zhou commented 1 month ago

-DpackageName

Thanks, swagger-codegen generate --help manual doesn't list this argument tho.

Lenormju commented 2 weeks ago

Here are the two options I use when running the CLI :

--model-name-prefix simulator_server     -D packageName=simulator_server

I'm still confused what they both mean. I put the same value for both.