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

[BUG] Java Spring snapshotVersion not working with Maven plugin. #4468

Closed
5 of 6 tasks
scottmcarthur-heb opened this issue Nov 12, 2019 · 2 comments
Closed
5 of 6 tasks

Comments

@scottmcarthur-heb
Copy link

scottmcarthur-heb commented Nov 12, 2019

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

Using the openapi-generator-maven-plugin version 4.2.0, the Java spring generator does not honor the snapshotVersion parameter as documented.

From the help:

snapshotVersion
  Uses a SNAPSHOT version.
    true - Use a SnapShot Version
    false - Use a Release Version

POM Configuration:

<configuration>
  <inputSpec>${project.build.directory}/openapi.yaml</inputSpec>
  <generatorName>spring</generatorName>
  <output>${project.build.directory}/generated-sources/spring-server</output>
  <configOptions>
    <snapshotVersion>true</snapshotVersion>-->
  </configOptions>
</configuration>

results in an exception:

[ERROR] /Users/XXXXXXXXX/git/servicegenerator/target/openapi.yaml [0:0]: unexpected error in Open-API generation
java.lang.ClassCastException: java.lang.Boolean cannot be cast to java.lang.String
    at org.openapitools.codegen.languages.AbstractJavaCodegen.preprocessOpenAPI (AbstractJavaCodegen.java:1058)
    at org.openapitools.codegen.languages.SpringCodegen.preprocessOpenAPI (SpringCodegen.java:495)
    at org.openapitools.codegen.DefaultGenerator.configureGeneratorProperties (DefaultGenerator.java:197)
    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:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)

Changing the value to "1.0.0-SNAPSHOT" does not cause an error, but the version is not used in the generated POM

CLI seems to generate the POM file as expected using command line
openapi-generator generate -i ./openapi.yaml -o ./tmp -g spring -p snapshotVersion=true

openapi-generator version

4.2.0

OpenAPI declaration file content or url

Any spec will cause this

Command line used for generation

Maven generation, JavaSpring

Steps to reproduce

Create a pom.xml file with this in the plugins section

<plugin>
    <groupId>org.openapitools</groupId>
    <artifactId>openapi-generator-maven-plugin</artifactId>
    <version>4.2.0</version>
    <executions>
        <execution>
            <id>spring-server</id>
            <goals>
                <goal>generate</goal>
            </goals>

            <configuration>
                <inputSpec>openapi.yaml</inputSpec>
                <generatorName>spring</generatorName>
                <configOptions>
                    <snapshotVersion>true</snapshotVersion>
                </configOptions>
            </configuration>

        </execution>
    </executions>
</plugin>
Related issues/PRs
Suggest a fix

https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java#L1058

This line needs to be modified to check for a Boolean type and not cast as String if so. If all incoming types are non primitives, then using .toString() may be the easiest.

@auto-labeler
Copy link

auto-labeler bot commented Nov 12, 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.

@scottmcarthur-heb scottmcarthur-heb changed the title [BUG] Description [BUG] Java Spring snapshotVersion not working with Maven plugin. Nov 12, 2019
@janweinschenker
Copy link
Contributor

PR #4495 fixes this. Made use of a previous fix that was already applied to the kotlin generation.

wing328 pushed a commit that referenced this issue Nov 17, 2019
#4495)

* issue 4468 fix: prevent ClassCastException when handling options of type boolean

*  #4468 fix: remove duplicate code
@wing328 wing328 closed this as completed Nov 17, 2019
jimschubert added a commit to jimschubert/openapi-generator that referenced this issue Nov 17, 2019
…ulti-level-model-hierarchy

* origin/master:
  minor fix to CI failure
  feat(dart-dio): correctly handle Map<String, Object>, List<Object> using JsonObject (OpenAPITools#4401)
  [OCAML] Fixes cloud.drone.io ocaml-test (OpenAPITools#4501)
  [elm] Add support for oneOf (OpenAPITools#4434)
  [BUG] [Java] Client resttemplate and webclient. Form Params are badly added when they are lists  (OpenAPITools#4461)
  fix: prevent ClassCastException when handling options of (issue OpenAPITools#4468) (OpenAPITools#4495)
  Fixes Python client Configuration class so each instance uses its own dicts (OpenAPITools#4485)
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

3 participants