如何使用 java 注释创建多个 404 响应(或更广泛地说,多个相同的 HTTP 代码响应)。
我试过了:
@ApiResponse(
responseCode = "404",
description = "Not Found 1"
)
@ApiResponse(
responseCode = "404",
description = "Not Found 2"
)
还有多个@Content
:
@ApiResponse(
responseCode = "404",
content = {
@Content(schema = @Schema(name = "404-1", description = "404-1")),
@Content(schema = @Schema(name = "404-2", description = "404-2"))
}
)
我可以获得类似于 multiple 的唯一方法是使用@ExampleObject[]
:
@ApiResponse(
responseCode = "404",
content = @Content(
mediaType = "application/json",
examples = {
@ExampleObject(name = "404-1", description = "Not Found 1 desc"),
@ExampleObject(name = "404-2", description = "Not Found 2 desc")
}
)
)
这并不理想,因为它需要人工交互才能查看所有这些,而且是不想要的;期望是:
- 200
- 404 Description 1
- 404 Description 2
- 404 Description 3
甚至更好:
- 200
- 404 Description 1
Description 2
Description 3
我正在使用 springdoc 和以下 dep:
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.4.3</version>
</dependency>