ReDoc + SWAGGER + Spring 启动 - 响应示例

ReDoc + SWAGGER + Spring Boot - response samples

目前我正在编写我的 API 文档,我决定使用 ReDoc 来实现它。 我的 API 使用 Spring Boot 构建..并且我正在使用 SWAGGER 的文档。一切都很好,但我无法注释我的控制器以在 ReDoc 文档的右侧显示 'response samples' 部分。我尝试在 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;
    }
}

最后通过将此添加到控制器解决@PostMapping:

produces = {"application/json"}