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"))
}
)
複数に似たものを取得できる唯一の方法は、次を使用すること@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>