[BUG] Java Spring snapshotVersion not working with Maven plugin.
Created by: scottmcarthur-heb
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
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.