2
votes

I have an existing Spring 4 API and have successfully integrated springdoc-openapi to generate the OpenAPI 3 spec in JSON/YAML and also display the Swagger UI using springdoc-openapi 1.2.29 and Spring Boot 15.2.2.RELEASE, however there appear to be various bugs that were fixed and enhancements added in later versions of springdoc-openapi. Unfortunately I am running into various compatibility issues with Spring 4 if I use versions higher than springdoc-openapi 1.2.29.

Is there an availability compatibility matrix for springdoc-openapi and Spring 4? As I read through the springdoc-openapi documentation, I do not see any readme or release notes suggesting there is a Spring 5 requirement, however as noted below there are Spring 5 classes used in the underlying springdoc-openapi once you reach a certain version.

My relevant POM:

    <!-- springdoc-openapi-ui -->
    <!-- anything over 1.2.33 uses Spring 5 MethodParameter.getParameter()-->
    <!-- anything over 1.2.29 uses Spring 5 org.springframework.http.codec.multipart.FilePart -->
    <!-- webjars-locator-jboss-vfs is required for running under JBOSS and exposing the swagger-ui -->
    <dependency>
        <groupId>org.springdoc</groupId>
        <artifactId>springdoc-openapi-ui</artifactId>
        <version>1.2.29</version>
    </dependency>
    <!--  
    <dependency>
        <groupId>org.springdoc</groupId>
        <artifactId>springdoc-openapi-security</artifactId>
        <version>1.2.29</version>
    </dependency>
    -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot</artifactId>
        <version>1.5.22.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-autoconfigure</artifactId>
        <version>1.5.22.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.webjars</groupId>
        <artifactId>webjars-locator-jboss-vfs</artifactId>
        <version>0.1.0</version>
    </dependency>

When using springdoc-openapi-ui 1.2.30, it will subsequently bring in springdoc-openapi-common-1.2.30.jar which throw an exception trying to use org.springframework.http.codec.multipart.FilePart. Likewise, using 1.2.34 or higher will throw an exception on MethodParameter.getParameter().

12:15:05,003 ERROR [stderr] (ajp-localhost/127.0.0.1:8009-1) Caused by: java.lang.NoClassDefFoundError: org/springframework/http/codec/multipart/FilePart
12:15:05,003 ERROR [stderr] (ajp-localhost/127.0.0.1:8009-1)    at org.springdoc.core.GenericParameterBuilder.isFile(GenericParameterBuilder.java:271)
12:15:05,003 ERROR [stderr] (ajp-localhost/127.0.0.1:8009-1)    at org.springdoc.core.GenericParameterBuilder.isFile(GenericParameterBuilder.java:296)
12:15:05,003 ERROR [stderr] (ajp-localhost/127.0.0.1:8009-1)    at org.springdoc.core.AbstractRequestBuilder.buildParams(AbstractRequestBuilder.java:271)
12:15:05,003 ERROR [stderr] (ajp-localhost/127.0.0.1:8009-1)    at org.springdoc.core.AbstractRequestBuilder.build(AbstractRequestBuilder.java:174)
12:15:05,003 ERROR [stderr] (ajp-localhost/127.0.0.1:8009-1)    at org.springdoc.api.AbstractOpenApiResource.calculatePath(AbstractOpenApiResource.java:205)
12:15:05,003 ERROR [stderr] (ajp-localhost/127.0.0.1:8009-1)    at org.springdoc.api.OpenApiResource.calculatePath(OpenApiResource.java:134)
12:15:05,003 ERROR [stderr] (ajp-localhost/127.0.0.1:8009-1)    at org.springdoc.api.OpenApiResource.getPaths(OpenApiResource.java:99)
12:15:05,003 ERROR [stderr] (ajp-localhost/127.0.0.1:8009-1)    at org.springdoc.api.AbstractOpenApiResource.getOpenApi(AbstractOpenApiResource.java:124)
12:15:05,003 ERROR [stderr] (ajp-localhost/127.0.0.1:8009-1)    at org.springdoc.api.OpenApiResource.openapiJson(OpenApiResource.java:83)
12:15:05,003 ERROR [stderr] (ajp-localhost/127.0.0.1:8009-1)    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
12:15:05,003 ERROR [stderr] (ajp-localhost/127.0.0.1:8009-1)    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
12:15:05,004 ERROR [stderr] (ajp-localhost/127.0.0.1:8009-1)    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
12:15:05,004 ERROR [stderr] (ajp-localhost/127.0.0.1:8009-1)    at java.lang.reflect.Method.invoke(Method.java:498)
12:15:05,004 ERROR [stderr] (ajp-localhost/127.0.0.1:8009-1)    at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205)
12:15:05,004 ERROR [stderr] (ajp-localhost/127.0.0.1:8009-1)    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133)
12:15:05,004 ERROR [stderr] (ajp-localhost/127.0.0.1:8009-1)    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:116)
12:15:05,004 ERROR [stderr] (ajp-localhost/127.0.0.1:8009-1)    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
12:15:05,004 ERROR [stderr] (ajp-localhost/127.0.0.1:8009-1)    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
12:15:05,004 ERROR [stderr] (ajp-localhost/127.0.0.1:8009-1)    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
12:15:05,004 ERROR [stderr] (ajp-localhost/127.0.0.1:8009-1)    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963)
12:15:05,004 ERROR [stderr] (ajp-localhost/127.0.0.1:8009-1)    ... 61 more

Spring 5 reference: https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/http/codec/multipart/FilePart.html

public interface FilePart
extends Part

Specialization of Part that represents an uploaded file received in a multipart request.

Since:
    5.0

Any suggestions on how to work around this to leverage the bug fixes and enhancements in springdoc-openapi in later versions?

1

1 Answers

2
votes

Issue confirmed and will be resolved as part of 1.3.3. Please see the issue logged with Springdoc below. Kudos to @bnasslahsen for incredibly fast identification and correction!

https://github.com/springdoc/springdoc-openapi/issues/563