【问题标题】:ReDoc + SWAGGER + Spring Boot - response samplesReDoc + SWAGGER + Spring Boot - 响应示例
【发布时间】:2020-03-02 15:55:24
【问题描述】:

目前我正在编写我的 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;
    }
}

【问题讨论】:

  • 您介意分享一下您是如何实现这一目标的代码示例吗?我一直在尝试将 redoc 集成到我的开放 api 项目中,但没有运气......
  • @Xander 请作为问题提出,将链接发给我,我将与您分享示例:)

标签: spring-boot swagger springfox redoc


【解决方案1】:

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

produces = {"application/json"}

【讨论】:

    猜你喜欢
    • 2022-12-22
    • 2019-08-06
    • 2017-11-17
    • 2019-05-18
    • 2019-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多