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

[REQ] Support modelPropertyNaming=original for Python #5214

Closed
jonashaag opened this issue Feb 5, 2020 · 12 comments
Closed

[REQ] Support modelPropertyNaming=original for Python #5214

jonashaag opened this issue Feb 5, 2020 · 12 comments

Comments

@jonashaag
Copy link
Contributor

jonashaag commented Feb 5, 2020

Add support for modelPropertyNaming (or similar) to Python codegen.

If you have definitions like this one:

      parameters:
        - name: FooID
          in: query

Then the resulting code uses underscore notation:

    def myendpoint(self, foo_id, ..., **kwargs):  # noqa: E501

It should also be supported to leave the identifiers as-is, so that the code is:

    def myendpoint(self, FooID, ..., **kwargs):  # noqa: E501

Related tickets:

@spacether
Copy link
Contributor

spacether commented Jan 18, 2021

This is being worked in my the new python-expeirmental generator in this PR: #8325
Implementing this feature helps with composition. For example:

ModelA
- someProp

ModelB:
- some_prop

ModelC:
allOf:
- ModelA
- ModelB

ModelC should contain properties someProp and some_prop

Also per this ticket:
#1227
Some users actually include properties like _id and id in the same object

@spacether
Copy link
Contributor

spacether commented Jan 5, 2022

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

@rm3l
Copy link
Contributor

rm3l commented Jan 6, 2022

@spacether Sure. I just tried to quickly run the python-experimental generator (which I guess is included in the latest 5.4.0-SNAPSHOT). Unfortunately, I got the error below. Any ideas why ?
From the exception message, I guess the wrong templating engine is passed to the PythonExperimentalClientCodegen instance, but don't know why.

❯ OPENAPI_GENERATOR_VERSION=5.4.0-SNAPSHOT openapi-generator-cli generate -i openapi.yaml -g python-experimental -o python-experimental-client

[INFO] Scanning for projects...                                                                                                                                                                                                           
[INFO]                                                                                                                                                                                                                                    
[INFO] ------------------< org.apache.maven:standalone-pom >-------------------                                                                                                                                                           
[INFO] Building Maven Stub Project (No POM) 1                                                                                                                                                                                             
[INFO] --------------------------------[ pom ]---------------------------------                                                                                                                                                           
[INFO]                                                                                                                                                                                                                                    
[INFO] --- maven-dependency-plugin:2.9:get (default-cli) @ standalone-pom ---                                                                                                                                                             
[INFO] Resolving org.openapitools:openapi-generator-cli:jar:5.4.0-SNAPSHOT                                                                                                                                                                
Downloading from central: https://oss.sonatype.org/content/repositories/snapshots/org/openapitools/openapi-generator-cli/5.4.0-SNAPSHOT/maven-metadata.xml                                                                                
Downloaded from central: https://oss.sonatype.org/content/repositories/snapshots/org/openapitools/openapi-generator-cli/5.4.0-SNAPSHOT/maven-metadata.xml (2.0 kB at 2.3 kB/s)                                                            
Downloading from central: https://oss.sonatype.org/content/repositories/snapshots/org/openapitools/openapi-generator-cli/5.4.0-SNAPSHOT/openapi-generator-cli-5.4.0-20220105.225636-15.jar                                                
Downloaded from central: https://oss.sonatype.org/content/repositories/snapshots/org/openapitools/openapi-generator-cli/5.4.0-SNAPSHOT/openapi-generator-cli-5.4.0-20220105.225636-15.jar (25 MB at 1.3 MB/s)                             
[WARNING] destination/dest parameter is deprecated: it will disappear in future version.                                                                                                                                                  
[INFO] Copying /home/asoro/.m2/repository/org/openapitools/openapi-generator-cli/5.4.0-SNAPSHOT/openapi-generator-cli-5.4.0-SNAPSHOT.jar to /home/asoro/.local/bin/openapi-generator-cli-5.4.0-SNAPSHOT.jar                               
[INFO] ------------------------------------------------------------------------                                                                                                                                                           
[INFO] BUILD SUCCESS                                                                                                                                                                                                                      
[INFO] ------------------------------------------------------------------------                                                                                                                                                           
[INFO] Total time:  22.250 s                                                                                                                                                                                                              
[INFO] Finished at: 2022-01-06T16:44:34+01:00                                                                                                                                                                                             
[INFO] ------------------------------------------------------------------------
[main] INFO  o.o.codegen.DefaultGenerator - Generating with dryRun=false
[main] INFO  o.o.c.ignore.CodegenIgnoreProcessor - Output directory (/home/asoro/Work/tmp/openapi-gen-python/python-experimental-client) does not exist, or is inaccessible. No file (.openapi-generator-ignore) will be evaluated.
[main] INFO  o.o.codegen.DefaultGenerator - OpenAPI Generator: python-experimental (client)
[main] INFO  o.o.codegen.DefaultGenerator - Generator 'python-experimental' is considered experimental.
[main] INFO  o.o.c.l.AbstractPythonCodegen - Environment variable PYTHON_POST_PROCESS_FILE not defined so the Python code may not be properly formatted. To define it, try 'export PYTHON_POST_PROCESS_FILE="/usr/local/bin/yapf -i"' (Linux/Mac)
[main] INFO  o.o.c.l.AbstractPythonCodegen - NOTE: To enable file post-processing, 'enablePostProcessFile' must be set to `true` (--enable-post-process-file for CLI).
Exception in thread "main" java.lang.RuntimeException: Only the HandlebarsEngineAdapter is supported for this generator
        at org.openapitools.codegen.languages.PythonExperimentalClientCodegen.processOpts(PythonExperimentalClientCodegen.java:219)
        at org.openapitools.codegen.DefaultGenerator.configureGeneratorProperties(DefaultGenerator.java:251)
        at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:894)
        at org.openapitools.codegen.cmd.Generate.execute(Generate.java:441)
        at org.openapitools.codegen.cmd.OpenApiGeneratorCommand.run(OpenApiGeneratorCommand.java:32)
        at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:66)

@spacether
Copy link
Contributor

spacether commented Jan 6, 2022

Thanks for letting me know. It looks like our code is defaulting to mustache templates and the generator is erroring. You should be able to get past it by passing in the -e handlebars. I will fix it.

@spacether
Copy link
Contributor

I have a PR posted to fix it and I am waiting on a review from the core team:
#11245
In the meantime pass in -e handlebars to using python-experimental to specify the needed handlebars templating engine.

@rm3l
Copy link
Contributor

rm3l commented Jan 7, 2022

Thanks. The generator command worked with -e handlebars.

@rm3l
Copy link
Contributor

rm3l commented Jan 7, 2022

I'm not a Python expert, but after quickly taking a look at the code generated, this looks good to me, at least for the names of endpoint parameters and model properties.
Is it also planned to have method names respect the operation names set in the OpenAPI definition? (This may be a different issue, perhaps related to #3813)
Anyways, thanks again for your work in #8325 on this generator.

@spacether
Copy link
Contributor

Doing that is possible. If you want it please thumbs up vote it in the issue that I have created here:
OpenAPITools/openapi-json-schema-generator#32

@spacether
Copy link
Contributor

spacether commented Jan 7, 2022

Can this issue be closed now that model property naming is consistent with spec naming in python-experimental?

@rm3l
Copy link
Contributor

rm3l commented Jan 10, 2022

Can this issue be closed now that model property naming is consistent with spec naming in python-experimental?

Looks good to me with python-experimental.
@jonashaag Maybe you have additional feedback, since you initially reported this issue?

@spacether
Copy link
Contributor

Update: I just merged by above PR that defaults the templating engine to handlebars for the python-experimental generator. So one no longer needs to pass in the -e handlebars templating engine for python-experimental.

@spacether
Copy link
Contributor

Closing this issue because we now have the python-experimental generator which uses spec case for model properties and endpoint parameters.

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

4 participants
@jonashaag @rm3l @spacether and others