问题描述
我该怎么做?
PS:请注意,我将使用springdoc公开开放的API规范。
解决方法
一种实现方法是,您可以在@ApiResponse
您可以通过两种方式实现这一目标
1。。定义您的错误消息格式类别,或者您可以使用内置版本
public class ExceptionResponse {
private Instant time;
private int status;
private String error;
private String exception;
private String message;
}
然后定义您的自定义消息字符串,如下所示。
public static final String exampleInternalError = "{\r\n" + " \"status\": 500,\r\n" + "\"error\": Bad Request,\r\n"
+ " \"message\": \"Your custome message goes here\"\r\n" + "}";
相同用于将示例显示为
@ApiResponse(responseCode = "400",description = "Bad Request",content = @Content(schema = @Schema(implementation = ExceptionResponse .class),examples = @ExampleObject(description = "Bad Request",value = exampleInternalError)))
2。。如果您不想以上述格式使用,则只需使用
如下所述
@ApiResponse(responseCode = "400",content = @Content(schema = @Schema(implementation = String.class),value = "\"Your details about error code and error message goes here")))