Search code examples
spring-bootswagger-uiopenapispringdocspringdoc-openapi-ui

400 Bad Request when getting v3/api-docs


I am using springdoc-openapi-starter-webmvc-ui to render my API schema (Spring Boot 3).

<dependency>
    <groupId>org.springdoc</groupId>
    <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
    <version>2.0.2</version>
</dependency>
<dependency>
    <groupId>org.springdoc</groupId>
    <artifactId>springdoc-openapi-starter-webmvc-api</artifactId>
    <version>2.0.2</version>
</dependency>

I annotated my controller class:

@OpenAPIDefinition(
    info = @Info(
        title = "Test Application",
        description = "Description"
    )
)
@RestController
@RequestMapping("/api")
@RequiredArgsConstructor
@Slf4j
public class TestController {

    @Operation(summary = "Test endpoint")
    @ApiResponses(value = {
        @ApiResponse(responseCode = "204", description = "OK", content = @Content),
        @ApiResponse(responseCode = "400", description = "Invalid request", content = @Content),
        @ApiResponse(responseCode = "500", description = "Internal server error", content = @Content)})
    @PostMapping("/test")
    public ResponseEntity<Object> test(@RequestBody @Valid @ParameterObject TestRequest testRequest, BindingResult bindingResult) {
        ...
    }
}

When my application is running I can access http://localhost:8080/swagger-ui/index.html, but unfortunately it shows Failed to load API definition. with error:

Fetch error
response status is 400 /v3/api-docs

Any ideas what's wrong with my code?


Solution

  • I've managed to resolve the problem. It turned out that one of my dependency used an old version of swagger, so I had to exclude it:

    <exclusion>
        <groupId>io.swagger.core.v3</groupId>
        <artifactId>swagger-annotations</artifactId>
    </exclusion>
    <exclusion>
        <groupId>io.swagger.core.v3</groupId>
        <artifactId>swagger-core</artifactId>
    </exclusion>