Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question][Python] Is posible to change to cammel case naming convention? #3813

Closed
jpascualsana opened this issue Aug 31, 2019 · 10 comments
Closed

Comments

@jpascualsana
Copy link

Description

Our project is wrote on camelCase convention. Is possible to generate python client following camelCase instead of the pythonic snake_case?

I looked at mustache templates on:

https://github.com/OpenAPITools/openapi-generator/tree/master/modules/openapi-generator/src/main/resources/python

And the instructions under openapi-generator config-help -g python.

Also I looked at PythonClientCodegen.java but I didn't find the answer.

openapi-generator version
➜ openapi-generator version
4.0.3
OpenAPI declaration file content or url

https://gitlab.com/snippets/1882068/raw

Note: this YAML is auto generated from a Doxygen documentation for RetroShare project using this

Command line used for generation
openapi-generator generate -i wrapper_openapi.yml -g python -o ../openapi-python-retroshare-api-wrapper
@auto-labeler
Copy link

auto-labeler bot commented Aug 31, 2019

👍 Thanks for opening this issue!
🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

@wing328
Copy link
Member

wing328 commented Sep 3, 2019

Is pythonic snake_case causing issues (e.g. JSON payload serialization/deserialization)?

@jpascualsana
Copy link
Author

For the moment it don't seems so, but we would like to use only CamelCase on our project, also in python wrappers, breaking with the pythonic rules.

Is there a way to modify the template to disable snake_case and use CamelCase for variable names an others?

@rmadisonhaynie
Copy link

We have a similar issue at the moment, a resolution would be great thanks

@spacether
Copy link
Contributor

spacether commented May 30, 2020

There is not yet a way to do this in the python clients.
Just so you know, the variable names that you are suggesting shapeType, go against the PEP8 python style guide, which would instead use shape_type

This is partially implemented in python-experimental when instantiating models.
See this example
Where we make a model like:

inst = petstore_api.Shape(_spec_property_naming=True, shapeType="Triangle", triangleType="IsoscelesTriangle")

But that only allows you to assign properties at initialization with spec variable names.
To access the property instances we are assuming that the the context is python and that the user wants:
inst.shape_type

I see a couple of ways to get this working:

  1. in Java add a CLI option to a python generator which uses the spec naming for all endpoint variable names and object variable names. This will probably involve editing functions to use this CLI option and change the property names that are use in Java.
  2. In the python-experimental generator add:
  • a Configuration class option spec_property_naming=False
  • use that Configuration instance when users access variable names in the OpenApiModel set_attribute
  • Fix the endpoints so they allow spec property names. To do that we would need to add a dict which goes from python variable names to spec variable names, and we could decorate the endpoint function with @convert_js_args_to_python_args like we do in the model __init__ method

We welcome any contributions on this.

@thebhushanp
Copy link

in Java add a CLI option to a python generator which uses the spec naming for all endpoint variable names and object variable names. This will probably involve editing functions to use this CLI option and change the property names that are use in Java.

@spacether Can you guide me little on where should I look in the code for this above approach ?

@spacether
Copy link
Contributor

Sure thing :)
So I think that this is where the parameter names are set in the python client
And here is an example of a PR that adds a CLI parameter in a python generator:
#4765

@spacether
Copy link
Contributor

spacether commented Jan 5, 2022

@jpascualsana @rm3l can you try the new python-experimental generator?
It uses spec naming for all model properties and endpoint parameters. It was added in: #8325

@spacether
Copy link
Contributor

spacether commented Jan 7, 2022

Can this issue be closed now that we have the python-experimental generator which uses only spec case?

@spacether
Copy link
Contributor

Closing this issue because the python-experimental generator uses spec (camel case) naming

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants