英文:
400 Bad Request when getting v3/api-docs
问题
I am using springdoc-openapi-starter-webmvc-ui to render my API schema (Spring Boot 3).
我正在使用springdoc-openapi-starter-webmvc-ui
来渲染我的API架构(Spring Boot 3)。
I annotated my controller class:
我为我的控制器类添加了注解:
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:
当我的应用程序在运行时,我可以访问http://localhost:8080/swagger-ui/index.html
,但不幸的是,它显示Failed to load API definition.
并显示错误:
Any ideas what's wrong with my code?
对于我的代码有什么问题有什么想法?
英文:
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?
答案1
得分: 0
我已成功解决了这个问题。原来是我的一个依赖项使用了旧版本的swagger,所以我不得不将其排除:
<exclusion>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-annotations</artifactId>
</exclusion>
<exclusion>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-core</artifactId>
</exclusion>
英文:
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>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论