如何解决如何在示例代码部分显示错误代码说明?
我该怎么做?
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")))
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。