Spring boot 3 and Swagger ui java.lang.NoSuchMethodError: 'io.swagger.v3.oas.annotations.media.Schema$AdditionalPropertiesValue additionalProperties()
Asked Answered
A

5

13

I'm having an issue with swagger ui after upgrading to spring boot 3. The swagger-ui doesn't work anymore and I got a 404 and "White Label" page as response.

After taking a closer look, I need to change from: implementation(group: 'org.springdoc', name: 'springdoc-openapi-ui', version: '1.5.8')

to: implementation(group: 'org.springdoc', name: 'springdoc-openapi-starter-webmvc-ui', version: '2.0.3')

After that, it did work. However, in one of my other projects we had an issue with a dependency conflict, so the swagger-ui was throwing a 500 where trying to the fetch the /v3/api-docs/: between: io.confluent:kafka-avro-serializer:7.3.1 and springdoc-openapi-starter-webmvc-ui:2.0.3 Those 2 dependencies need to use io.swagger.core.v3:swagger-annotations-jakarta, but with different versions

So in gradle I had to resolve the conflict to force io.swagger.core.v3:swagger-annotations-jakarta:2.2.8.

Accustom answered 14/3, 2023 at 11:52 Comment(0)
T
10

In my case, even though I have springdoc-openapi-starter-webmvc-ui i also had to add this dependency

mvn

<dependency>
    <groupId>io.swagger.core.v3</groupId>
    <artifactId>swagger-annotations</artifactId>
    <version>2.2.16</version>
</dependency>
Thorson answered 27/9, 2023 at 11:57 Comment(0)
A
8

If you are upgrading from spring 2 to 3 you have to use:

implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.3'// swagger ui / openapi 3.0

instead of: implementation 'org.springdoc:springdoc-openapi-ui:1.5.8'

If the swagger-ui gives you an error with /v3/api-docs/, maybe is because a dependency conflict, so I was able to solve it by forcing a dependency:

Error:

Caused by: java.lang.NoSuchMethodError: 'io.swagger.v3.oas.annotations.media.Schema$AdditionalPropertiesValue io.swagger.v3.oas.annotations.media.Schema.additionalProperties()'
        at io.swagger.v3.core.util.AnnotationsUtils.getSchemaFromAnnotation(AnnotationsUtils.java:552) ~[swagger-core-jakarta-2.2.8.jar:2.2.8]
        at io.swagger.v3.core.util.AnnotationsUtils.getSchema(AnnotationsUtils.java:1170) ~[swagger-core-jakarta-2.2.8.jar:2.2.8]
        at org.springdoc.core.service.GenericParameterService.setSchema(GenericParameterService.java:323) ~[springdoc-openapi-starter-common-2.0.3.jar:2.0.3]
        at org.springdoc.core.service.GenericParameterService.buildParameterFromDoc(GenericParameterService.java:299) ~[springdoc-openapi-starter-common-2.0.3.jar:2.0.3]
        at org.springdoc.core.service.AbstractRequestService.build(AbstractRequestService.java:321) ~[springdoc-openapi-starter-common-2.0.3.jar:2.0.3]
        at org.springdoc.api.AbstractOpenApiResource.calculatePath(AbstractOpenApiResource.java:472) ~[springdoc-openapi-starter-common-2.0.3.jar:2.0.3]
        at org.springdoc.api.AbstractOpenApiResource.calculatePath(AbstractOpenApiResource.java:652) ~[springdoc-openapi-starter-common-2.0.3.jar:2.0.3]
        at org.springdoc.webmvc.api.OpenApiResource.lambda$calculatePath$11(OpenApiResource.java:219) ~[springdoc-openapi-starter-webmvc-api-2.0.3.jar:2.0.3]

Dependency resolution with gradle:

configurations.all {
resolutionStrategy {
    eachDependency { details ->
        if (details.requested.group == 'io.swagger.core.v3') {
            details.useVersion("2.2.8")
            details.because('Swagger ui and Kafka Avro serializer incoptable dependency io.swagger.core.v3:swagger-annotations')
        }
Accustom answered 14/3, 2023 at 12:0 Comment(1)
You are right, I have avro dependency and faced similar issue, by forcing above swagger version, issue resolved for me.Haberman
H
4

Another solution could be to exclude the swagger-annotations dependency from springdoc-openapi and include a newer version manually

//swagger
// exclude swagger annotation and use newer version due conflicts with avro serializer
implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.2.0"){
    exclude group: "io.swagger.core.v3", module:"swagger-annotations"
}
// https://mvnrepository.com/artifact/io.swagger.core.v3/swagger-annotations
implementation 'io.swagger.core.v3:swagger-annotations:2.2.15'
Hyperaesthesia answered 19/9, 2023 at 14:26 Comment(0)
H
2

Please add these two dependency in pom.xml file. It worked for me.

<!-- https://mvnrepository.com/artifact/org.springdoc/springdoc-openapi-starter-webmvc-ui -->
<dependency>
    <groupId>org.springdoc</groupId>
    <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
    <version>2.0.3</version>
</dependency>

<dependency>
    <groupId>io.swagger.core.v3</groupId>
    <artifactId>swagger-annotations</artifactId>
    <version>2.2.16</version>
</dependency>
Hilton answered 24/11, 2023 at 5:48 Comment(0)
C
0

For the above error just ensure that all your dependencies are compatible by using the command mvn dependency:tree In my case io.swagger.core.v3:swagger-models and io.swagger.core.v3:swagger-annotations dependencies version are not compatible with springdoc-openapi-starter-webmvc-ui dependency so after changing the version error got resolved

Curare answered 19/7, 2023 at 9:43 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Lorileelorilyn

© 2022 - 2025 — McMap. All rights reserved.