Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #4468
Closed
Open
Issue created Nov 12, 2019 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[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

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.

Assignee
Assign to
Time tracking