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

[kotlin] [bugfix] [maven-plugin]: prevent ClassCastException with boolean config options #4361

Merged
merged 7 commits into from
Nov 8, 2019

Conversation

janweinschenker
Copy link
Contributor

This change will prevent a ClassCastException during execution of the generator maven plugin.

When executed as maven plugin, boolean config options have the type java.lang.Boolean. When executed as CLI generator boolean config options have the type java.lang.String. Before this fix, only the latter case could be handled properly and the first case caused a ClassCastException.

PR checklist

  • Read the contribution guidelines.
  • If contributing template-only or documentation-only changes which will change sample output, build the project before.
  • Run the shell script(s) under ./bin/ (or Windows batch scripts under.\bin\windows) to update Petstore samples related to your fix. This is important, as CI jobs will verify all generator outputs of your HEAD commit, and these must match the expectations made by your contribution. You only need to run ./bin/{LANG}-petstore.sh, ./bin/openapi3/{LANG}-petstore.sh if updating the code or mustache templates for a language ({LANG}) (e.g. php, ruby, python, etc).
  • File the PR against the correct branch: master, 4.3.x, 5.0.x. Default: master.
  • Copy the technical committee to review the pull request if your PR is targeting a particular programming language. @wing328

@auto-labeler
Copy link

auto-labeler bot commented Nov 4, 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 Nov 6, 2019

Thanks for the PR. I tested locally but still got the same error:

[ERROR]
java.lang.ClassCastException: java.lang.Boolean cannot be cast to java.lang.String
    at org.openapitools.codegen.languages.AbstractKotlinCodegen.processOpts (AbstractKotlinCodegen.java:437)
    at org.openapitools.codegen.languages.KotlinClientCodegen.processOpts (KotlinClientCodegen.java:144)
    at org.openapitools.codegen.DefaultGenerator.configureGeneratorProperties (DefaultGenerator.java:196)
    at org.openapitools.codegen.DefaultGenerator.generate (DefaultGenerator.java:913)
    at org.openapitools.codegen.plugin.CodeGenMojo.execute (CodeGenMojo.java:727)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:208)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:154)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:146)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:290)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:194)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)

I may have done something wrong locally. Does the fix work for you locally in your machine?

@wing328 wing328 added this to the 4.2.1 milestone Nov 6, 2019
@wing328
Copy link
Member

wing328 commented Nov 6, 2019

@janweinschenker
Copy link
Contributor Author

I build my fork of openapi-generator locally with mvn clean install and the used the maven plugin with version 4.2.1-SNAPSHOT. It worked correctly.

But of course, you are right, there needs to be a reproduceable unit test. I will add one or more as needed.

@wing328
Copy link
Member

wing328 commented Nov 7, 2019

For tests, I mean adding the following:

mvn clean compile -f modules/openapi-generator-maven-plugin/examples/kotlin.xml

to https://github.com/OpenAPITools/openapi-generator/blob/master/.travis.yml#L140

@janweinschenker
Copy link
Contributor Author

Will this do?

@wing328 wing328 merged commit f9af3c2 into OpenAPITools:master Nov 8, 2019
jimschubert added a commit to jimschubert/openapi-generator that referenced this pull request Nov 10, 2019
* master: (28 commits)
  [meta] Support Kotlin meta generator (OpenAPITools#4156)
  [Go][Server] minor enhancement to the template (OpenAPITools#4417)
  Replace the old ResourceSupport (OpenAPITools#4426)
  [Core, Rust Server, ASP.NET Core] Fix Codegen Operation Scope Consistency (OpenAPITools#3495)
  Add Go Server featureCORS option (OpenAPITools#4400)
  Fix treatment of nullable types in a few more places (OpenAPITools#4315)
  prefix local variable with localVar (OpenAPITools#4402)
  [kotlin][client] gson complete integration (OpenAPITools#4332)
  [kotlin] [bugfix] [maven-plugin]: prevent ClassCastException with boolean config options (OpenAPITools#4361)
  add sbt, bazel to integration (OpenAPITools#4416)
  Add a blog post tutorial about generating Java clients using OpenAPI v3 (OpenAPITools#4405)
  add freshcells to company list (OpenAPITools#4414)
  Update isSet when the object is received from callback. (OpenAPITools#4385)
  Ruby client nullable (OpenAPITools#4391)
  Fixes Kotlin client property names that include a dollar sign for template override (OpenAPITools#4351)
  [Python] [Performance] Avoid unnessacary checks inside the loop (OpenAPITools#4305)
  Add QEDIT as a company that's using OpenAPI Generator (OpenAPITools#4392)
  update cpp flag for pistache (OpenAPITools#4386)
  Feature optional emit default values (OpenAPITools#4347)
  skip the test as async call may have finished (OpenAPITools#4377)
  ...
@wing328
Copy link
Member

wing328 commented Nov 15, 2019

@janweinschenker thanks for the PR, which has been included in the v4.2.1 release: https://twitter.com/oas_generator/status/1195339336922759168

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

Successfully merging this pull request may close these issues.

2 participants