OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.8k stars 6.58k forks source link

[BUG] [JAVA] Tag <generatorName> not working #10889

Open reiloe opened 2 years ago

reiloe commented 2 years ago
Description

According to the description you have to configure the generator plugin as follows:

<configuration>
    <inputSpec>${project.basedir}/src/main/resources/api.yaml</inputSpec>
    <generatorName>java</generatorName>
     ...
</configuration>

But this results in:

MojoExecutionException: The generator requires 'generatorName'. Refer to documentation for a list of options.

The tag is recognized, however, what you can see that another error is thrown if you specify any nonsense as a value

<configuration>
    <inputSpec>${project.basedir}/src/main/resources/api.yaml</inputSpec>
    <generatorName>nonsense</generatorName>
     ...
</configuration>

this results in:

GeneratorNotFoundException: Can't load config class with name 'nonsense'

The only way to get around this error is to write the generator name in the properties section of the pom.xml, then the tag can also be completely deleted from the section of the generator.

<properties>
    ...
    <openapi-generator-maven-plugin.version>5.3.0</openapi-generator-maven-plugin.version>
    <openapi.generator.maven.plugin.generatorName>spring</openapi.generator.maven.plugin.generatorName>
    ...
</properties>

<build>
    <plugins>
        <plugin>
            <groupId>org.openapitools</groupId>
            <artifactId>openapi-generator-maven-plugin</artifactId>
            <version>${openapi-generator-maven-plugin.version}</version>
            <executions>
                <execution>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                <configuration>
                    <inputSpec>${project.basedir}/src/main/resources/api.yaml</inputSpec>                
                    <configOptions>
                       <sourceFolder>src/gen/java/main</sourceFolder>
                    </configOptions>
                </configuration>
            </execution>
        </executions>
    </plugin>
...
</build>

This works, but it is not really useful. If you need different generator names, this workaround no longer works.

openapi-generator version

All versions > 4.3.1

Generation Details

Tested with:

Openapi-Generator-Plugin 5.0.0 to 5.3.0 AdoptOpenJdk 11 Intellij Ultimate 2021.2 Spring Boot 2.5.4 Maven 3.6.3

reiloe commented 2 years ago

Found the solution .... You have to add jakarta.annotation-api dependency instead javax.annotation. Pls add this as requirement in the description of the plugin

<dependency>
            <groupId>jakarta.annotation</groupId>
            <artifactId>jakarta.annotation-api</artifactId>
             <version>${jakarta.version}</version>
 </depdendency>