Michal Špondr
Michal Špondr

Reputation: 1535

springdoc-openapi-ui:1.6.7 and higher does not display API UI

I have this Spring project:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.7.5</version>
    <relativePath/>
</parent>

and this dependency:

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

Everything works, API UI is displayed.

However, when I upgrade springdoc-openapi-ui to version 1.6.7 and higher, I get this exception when I visit the API UI:

HttpStatus: 500 INTERNAL_SERVER_ERROR: {}.
org.springframework.web.util.NestedServletException: handler dispatch failed; nested exception is java.lang.NoClassDefFoundError: io/swagger/v3/oas/annotations/media/PatternProperties

This is displayed when you visit the API UI page: enter image description here

Update:

Here's related mvn dependency:tree output:

[INFO] |  +- org.springframework.kafka:spring-kafka:jar:2.8.10:compile
[INFO] |  |  +- org.springframework:spring-context:jar:5.3.23:compile
[INFO] |  |  +- org.springframework:spring-messaging:jar:5.3.23:compile
[INFO] |  |  +- org.springframework:spring-tx:jar:5.3.23:compile
[INFO] |  |  \- org.apache.kafka:kafka-clients:jar:3.1.2:compile
[INFO] |  |     +- com.github.luben:zstd-jni:jar:1.5.0-4:runtime
[INFO] |  |     +- org.lz4:lz4-java:jar:1.8.0:runtime
[INFO] |  |     \- org.xerial.snappy:snappy-java:jar:1.1.8.4:runtime
[INFO] |  \- io.confluent:kafka-avro-serializer:jar:7.2.1:compile
[INFO] |     +- org.apache.avro:avro:jar:1.11.0:compile
[INFO] |     +- io.confluent:kafka-schema-serializer:jar:7.2.1:compile
[INFO] |     +- io.confluent:kafka-schema-registry-client:jar:7.2.1:compile
[INFO] |     |  \- io.swagger.core.v3:swagger-annotations:jar:2.1.10:compile

What has changed and what needs to be modified?

Upvotes: 1

Views: 2342

Answers (2)

Tasos Zervos
Tasos Zervos

Reputation: 686

I have found that when using org.springdoc:springdoc-openapi-starter-webmvc-ui:2.1.0, the exclusion solution wasn't working anymore.

There is a jakarta-related change to its dependencies and it now uses:
io.swagger.core.v3:swagger-annotations-jakarta! related announcement

This is the solution that worked for me:

dependencies {
    modules {
        module("io.swagger.core.v3:swagger-annotations") {
            replacedBy("io.swagger.core.v3:swagger-annotations-jakarta", "swagger-annotations now supports jakarta namespace")
        }
    }
...

Upvotes: 2

Michal Špondr
Michal Špondr

Reputation: 1535

The problem was caused by the older version of package io.swagger.core.v3:swagger-annotations:2.1.10, which was added to the project by a transitive dependency (latest version is 2.2.6 at the moment).

There are 2 possible solutions:

Force the use of the latest version of the swagger-annotations package.

or

Exclude the swagger-annotations package dependency:

<dependency>
<groupId>io.confluent</groupId>
<artifactId>kafka-avro-serializer</artifactId>
<version>7.2.2</version>
<exclusions>
    <exclusion>
        <groupId>io.swagger.codegen.v3</groupId>
        <artifactId>swagger-annotations</artifactId>
    </exclusion>
</exclusions>
</dependency>

swagger-annotations then enters the project as a transitive dependency of the springdoc-openapi-ui package.

Upvotes: 4

Related Questions