swagger-maven-plugin icon indicating copy to clipboard operation
swagger-maven-plugin copied to clipboard

Cannot invoke "java.util.Map.size()" because "map" is null

Open nobody102 opened this issue 1 year ago • 10 comments

wildfly 27. Using swagger maven plugin, with JDK 21, and getting the above error.
<groupId>io.openapitools.swagger</groupId> <artifactId>swagger-maven-plugin</artifactId>

            <configuration>
                <resourcePackages>
                    <resourcePackage>com.hsntech.bannerjwt.rest</resourcePackage>
                </resourcePackages>
                <outputDirectory>${project.build.directory}/swagger-ui/META-INF/resources/webjars/swagger-ui/${swagger-ui.version}</outputDirectory>
                <outputFilename>openapi</outputFilename>
                <outputFormats>
                    <outputFormat>JSON</outputFormat>
                    <outputFormat>YAML</outputFormat>
                </outputFormats>
                <prettyPrint>true</prettyPrint>
                <swaggerConfig>
                    <servers>
                        <server>
                            <url>/SecurityService/rest</url>
                            <description>Endpoint URL for Banner Security Service API's</description>
                        </server>
                    </servers>
                    <info>
                        <title>Security Service - OpenAPI</title>
                        <version>1.0.0</version>

                        <description>REST API Framework designed to allow third party vendors the ability to
                            access Banner client data without having to go through the Banner UI Framework.</description>
                    </info>
                </swaggerConfig>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <!-- Download Swagger UI webjar. -->
            <artifactId>maven-dependency-plugin</artifactId>
            <version>${maven-dependency-plugin.version}</version>
            <executions>
                <execution>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>unpack</goal>
                    </goals>
                    <configuration>
                        <artifactItems>
                            <artifactItem>
                                <groupId>org.webjars</groupId>
                                <artifactId>swagger-ui</artifactId>
                                <version>${swagger-ui.version}</version>
                            </artifactItem>
                        </artifactItems>
                        <outputDirectory>${project.build.directory}/swagger-ui</outputDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <!-- Add Swagger UI resources to the war file. -->
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>${maven-war-plugin.version}</version>
            <configuration>
                <webResources combine.children="append">
                    <resource>
                        <directory>${project.build.directory}/swagger-ui/META-INF/resources/webjars/swagger-ui/${swagger-ui.version}</directory>
                        <includes>
                            <include>**/*.*</include>
                        </includes>
                        <targetPath>swagger-ui</targetPath>
                    </resource>
                </webResources>
            </configuration>
        </plugin>
        <plugin>
            <!-- Replace the OpenAPI specification example URL with the local one. -->
            <groupId>com.google.code.maven-replacer-plugin</groupId>
            <artifactId>replacer</artifactId>
            <version>${replacer.version}</version>
            <executions>
                <execution>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>replace</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <file>${project.build.directory}/swagger-ui/META-INF/resources/webjars/swagger-ui/${swagger-ui.version}/index.html</file>
                <replacements>
                    <replacement>
                        <token>http://petstore.swagger.io/v2/swagger.json</token>
                        <!-- value>/api/openapi.json</value -->
                        <!-- value>'http://localhost:8080/SecurityService/openapi.json'</value -->
                        <value>openapi.yaml</value>
                    </replacement>
                </replacements>
            </configuration>
        </plugin>
    </plugins>
</build>

nobody102 avatar Nov 13 '23 16:11 nobody102

Same issue here

salake avatar Nov 16 '23 09:11 salake

Same here

ataraxus avatar Jan 14 '24 17:01 ataraxus

Ah got it, used already jakarta but this plugin searches for javax :/

ataraxus avatar Jan 14 '24 17:01 ataraxus

@ataraxus seems to be quite annoying, anybody knows about someone fixing this ?

dgautier avatar Feb 12 '24 13:02 dgautier

@ataraxus so this library can't be used to generate for jakarta apis.Did you got any other plugin to generate open api spec

prabhat2020 avatar Mar 08 '24 12:03 prabhat2020

I wrote a custom plugin. My API Definitions are in a separate Module and my plugin, stubs them all during compiletime and generates the openApi spec using this plugin.

ataraxus avatar Mar 08 '24 19:03 ataraxus

I do not know if this is the exact issue we ran into, but it sounds so similar that maybe this info helps.

We saw this exact same error and the reason seems to be that when there are no classes with @Path annotations in the package defined in <resourcePackage> of the plugin.

At first I thought the workaround was adding more <resoucePackage> to the plugins config, but we just needed to add the following to the config:

<useResourcePackagesChildren>true</useResourcePackagesChildren>

bdevos avatar Apr 04 '24 06:04 bdevos

I wrote a custom plugin. My API Definitions are in a separate Module and my plugin, stubs them all during compiletime and generates the openApi spec using this plugin.

Could you share that custom plugin that you wrote or atleast a working example. I am running into this issue now and it seems like the fix hasn't been merged yet by the mainainer.

mali30 avatar Apr 08 '24 15:04 mali30

I do not know if this is the exact issue we ran into, but it sounds so similar that maybe this info helps.

We saw this exact same error and the reason seems to be that when there are no classes with @Path annotations in the package defined in <resourcePackage> of the plugin.

At first I thought the workaround was adding more <resoucePackage> to the plugins config, but we just needed to add the following to the config:

<useResourcePackagesChildren>true</useResourcePackagesChildren>

I tried this but it didn't work for me unfortunantly.

mali30 avatar Apr 08 '24 15:04 mali30

Same issue in JDK 17

traviscollins avatar May 17 '24 16:05 traviscollins