Openapi-generator: [Question][Python] Is posible to change to cammel case naming convention?

Created on 1 Sep 2019  ·  7Comments  ·  Source: OpenAPITools/openapi-generator

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
Python

Most helpful comment

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

All 7 comments

👍 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.

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

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?

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

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:
  3. a Configuration class option spec_property_naming=False
  4. use that Configuration instance when users access variable names in the OpenApiModel set_attribute
  5. 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.

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 ?

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:
https://github.com/OpenAPITools/openapi-generator/pull/4765

Was this page helpful?
0 / 5 - 0 ratings