我想用和招搖來記錄我的Spring BootRest API 。OpenAPI我遇到的問題是我必須ApiResponse為每個可能的回應代碼添加注釋并為每個 API 重復該注釋:
@Operation(summary = "Create new Address")
@ApiResponses(value = {
@ApiResponse(responseCode = "201", description = "New Address created", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = AddressResponse.class))
}),
@ApiResponse(responseCode = "400", description = "Invalid input supplied", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))
}),
@ApiResponse(responseCode = "401", description = "Unauthorized", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class)),
}),
@ApiResponse(responseCode = "404", description = "Not Found", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class)),
}),
@ApiResponse(responseCode = "409", description = "Conflict", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class)),
}),
@ApiResponse(responseCode = "422", description = "Unprocessable Entity", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class)),
}),
@ApiResponse(responseCode = "500", description = "Internal Server Error", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class)),
}),
})
有沒有辦法將ApiResponse“400、401、404、409、422、500 和default”的所有 s 組合在一起?像這樣的東西:
@Operation(summary = "Create new Address")
@ApiResponses(value = {
@ApiResponse(responseCode = "201", description = "New Address created", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = AddressResponse.class))
}),
@ApiResponse(responseCode = "400,401,404,409,422,500,default", description = "Error Happened", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))
}),
})
uj5u.com熱心網友回復:
簡短的回答,否。如openapi 規范中所述,物件的直接子responses物件是每個回應的 https 狀態。但是,您可以tags用于對操作進行分組(而不是回應)
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/485710.html
