我有如下代码
@ApiResponses(
{
@ApiResponse(
code = 500, message = "业务异常", response = ErrorResponse.class,
examples = @Example(value = {
@ExampleProperty(mediaType = MediaType.APPLICATION_JSON_VALUE, value = "{\"error\": {\"code\": \"BUSINESS_EXCEPTION\", \"message\": \"xxx\"}}"),
@ExampleProperty(mediaType = MediaType.APPLICATION_JSON_VALUE, value = "{\"error\": {\"code\": \"BUSINESS_EXCEPTION\", \"message\": \"---\", \"data\": [\"item1\", \"item2\"]}}")
})
)
}
)
但是 Swagger UI 却只展示了其中一个 example ,怎么让它展示出所有 examples 呢?
已解决此问题,解决方法是“使用DocumentationType.OAS_30,而不是DocumentationType.SWAGGER_2”。
How to define different responses for same HTTP status code in OpenAPI (Swagger)? - Stack Overflow