无法解析引用,因为:无法解析指针:/definitions/Error 在文档中不存在
我点击了这个链接http://www.baeldung.com/swagger-2-documentation-for-spring-rest-api,但是当我为自定义响应消息添加 globalResponseMessage() 方法时出现上述错误。我不明白原因是什么。
请帮忙......TIA
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build()
.apiInfo(apiInfo())
.consumes(getContentType())
.produces(getContentType())
.useDefaultResponseMessages(false)
.globalResponseMessage(RequestMethod.GET, newArrayList(
new ResponseMessageBuilder()
.code(500).message("500 message")
.responseModel(new ModelRef("Error")).build(),
new ResponseMessageBuilder()
.code(403)
.message("Forbidden!!!!!")
.build()));
}
您有两种选择:
1) 将“Error”替换为“string”(小写)。
new ResponseMessageBuilder()
.code(500).message("500 message")
.responseModel(new ModelRef("string")).build(),
2) 将“Error”替换为您在响应正文中用于错误信息的类的名称(或定义一个Error
类)。例子:
new ResponseMessageBuilder()
.code(500).message("500 message")
.responseModel(new ModelRef("ErrorInfo")).build(),
在这个例子中,类ErrorInfo
应该位于 Web 应用程序的类路径中(可能位于多个 Web 应用程序共享的库中)。例子:
@XmlRootElement
public class ErrorInfo {
private String url;
@ApiModelProperty(notes = "HTTP Status Code")
private int statusCode;
@ApiModelProperty(notes = "HTTP Reason Phrase")
private String reasonPhrase;
@ApiModelProperty(notes = "Mensage to the user")
private String message;
@ApiModelProperty(notes = "Ticket created on IT help desk if applicable", required = false)
private String helpDeskTicket;
@ApiModelProperty(notes = "Debug information (e.g., stack trace), not visible if runtime environment is 'production'", required = false)
private String debugInfo;
public ErrorInfo() {
// required by Jackson deserialization.
}
// ... other constructors, get/set methods...
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)