目前我正在编写我的 API 文档,我决定用 ReDoc 来实现它。我的 API 使用 Spring Boot 构建。对于文档,我使用的是 SWAGGER。一切都很好,但我无法注释我的控制器以在 ReDoc 文档的右侧显示“响应样本”部分。我尝试在 DTO 中添加示例,例如:
@JsonIgnoreProperties(ignoreUnknown = true)
public class DocumentResponse {
@ApiModelProperty(notes = "XML reuslt", name = "xmlResult", example = "asdasd", dataType = "java.lang.String")
private String xmlResult;
这是我的控制器的样子:
@Api(tags = {"Document"})
@RestController
@CrossOrigin("")
@RequestMapping("/doc")
public class DocumentController {
@PostMapping(value = "/doc-create", consumes = {"application/json"})
@ApiOperation(value = "docCreate", notes = "Create Document", response = DocumentResponse.class)
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Document success!", response = DocumentResponse.class),
@ApiResponse(code = 201, message = "Document created!", response = DocumentResponse.class),
@ApiResponse(code = 401, message = "Unauthorized!", response = DocumentResponse.class),
@ApiResponse(code = 403, message = "Forbidden!", response = DocumentResponse.class),
@ApiResponse(code = 404, message = "Not found!", response = DocumentResponse.class)})
public @ResponseBody DocumentResponse docCreate(@RequestBody DocumentRequest request) {
return null;
}
}