openapi-tools / swagger-maven-plugin

Maven plugin to activate the Swagger Core library to generate OpenAPI documentation.
MIT License
70 stars 45 forks source link

NullPointerException if no JaxRS/OpenApi classes found #59

Closed ipichris closed 3 years ago

ipichris commented 3 years ago

Motivation: When creating a project from scratch i want wo add swagger even before building the first webservice.

Currently if no class is found with @Path or @OpenAPIDefinition the swagger-maven-plugin will produce a NullPointerException

This is because OpenAPISorter will try to create a TreeMap with null.

Stacktrace:

Caused by: java.lang.NullPointerException
    at java.util.TreeMap.putAll (TreeMap.java:313)
    at java.util.TreeMap.<init> (TreeMap.java:185)
    at io.openapitools.swagger.OpenAPISorter.sortPaths (OpenAPISorter.java:50)
    at io.openapitools.swagger.OpenAPISorter.sort (OpenAPISorter.java:41)
    at io.openapitools.swagger.GenerateMojo.execute (GenerateMojo.java:127)

When at least one webservice is present the build succeeds.

langecode commented 3 years ago

That is a good finding. Thx. I will fix this asap.