springdoc / springdoc-openapi

Library for OpenAPI 3 with spring-boot
https://springdoc.org
Apache License 2.0
3.28k stars 495 forks source link

NPE in io.swagger.v3.core.jackson.ModelResolver when trying to retrieve /v3/api-docs #486

Closed planetf1 closed 4 years ago

planetf1 commented 4 years ago

After launching my springdoc-enabled application, I get an exception when attempting to load the swagger ui api definition:

2020-03-11 11:41:19.898 ERROR 58508 --- [nio-8080-exec-3] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause

java.lang.NullPointerException: null
    at io.swagger.v3.core.jackson.ModelResolver$GeneratorWrapper.process(ModelResolver.java:1110) ~[swagger-core-2.1.1.jar!/:2.1.1]
    at io.swagger.v3.core.jackson.ModelResolver$GeneratorWrapper.access$100(ModelResolver.java:976) ~[swagger-core-2.1.1.jar!/:2.1.1]
    at io.swagger.v3.core.jackson.ModelResolver$GeneratorWrapper$2.processAsProperty(ModelResolver.java:1032) ~[swagger-core-2.1.1.jar!/:2.1.1]
    at io.swagger.v3.core.jackson.ModelResolver$GeneratorWrapper.processJsonIdentity(ModelResolver.java:1092) ~[swagger-core-2.1.1.jar!/:2.1.1]
    at io.swagger.v3.core.jackson.ModelResolver.resolve(ModelResolver.java:291) ~[swagger-core-2.1.1.jar!/:2.1.1]
    at org.springdoc.core.converters.AdditionalModelsConverter.resolve(AdditionalModelsConverter.java:49) ~[springdoc-openapi-common-1.2.33.jar!/:1.2.33]
    at org.springdoc.core.converters.PropertyCustomizingConverter.resolve(PropertyCustomizingConverter.java:42) ~[springdoc-openapi-common-1.2.33.jar!/:1.2.33]

The full log is at https://gist.github.com/1f461620f990b1f1386314ae4298d4ee

I tried to follow the simple approach of mostly using defaults (I get the same error without application.properties), but am unsure why I get the NPE when trying to access the api docs.

I of course hit the same issue when the maven plugin runs integration tests.

Spring boot - 2.2.5.RELEASE sprindoc-openapi - springdoc-openapi-ui @ 1.2.33

I don't currently have simplified sample code

the project was previously using springfox, but just as you summarised in the project intro, that project is not seeing suitable support any more so were were interesting in trying springdocs instead

The primary changes made to the module to support springdocs was to add

        <dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-ui</artifactId>
        </dependency>

We also enforce the dependency version in our top level pom (using your latest version).

All springfox changes, including the dependencies, doclets, @EnableSwagger2 annotations were removed.

Our project: https://github.com/odpi/egeria A PR with my springfox removal/adding springdoc -> https://github.com/odpi/egeria/pull/2729

**

bnasslahsen commented 4 years ago

Hi @planetf1,

This issue is not related to springdoc-openapi but to swagger-core project. It happens on classes with cyclic reference using @JsonIdentityInfo annotation.

You have a workaround described on the link below:

planetf1 commented 4 years ago

Thanks for the super helpful response. Have it working now :-)

daniel-schel commented 3 years ago

I have created a fix for this issue in the following PR: https://github.com/swagger-api/swagger-core/pull/3908