首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ReDoc + SWAGGER +弹簧启动响应示例

ReDoc + SWAGGER +弹簧启动响应示例
EN

Stack Overflow用户
提问于 2020-03-02 23:55:25
回答 1查看 2K关注 0票数 1

目前我正在编写我的应用程序接口文档,我决定用ReDoc实现它。我的应用编程接口是使用SWAGGER构建的,用于我正在使用的Boot..and文档。一切都很好,但是我无法注释我的控制器以在ReDoc文档中显示右侧的“响应示例”部分。我尝试在DTO中添加示例,如下所示:

代码语言:javascript
复制
@JsonIgnoreProperties(ignoreUnknown = true)
    public class DocumentResponse {

        @ApiModelProperty(notes = "XML reuslt", name = "xmlResult", example = "asdasd", dataType = "java.lang.String")
        private String xmlResult;

这是我的控制器的样子:

代码语言:javascript
复制
@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;
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-03-03 17:33:51

最后通过将其添加到控制器@PostMapping来解决此问题

代码语言:javascript
复制
produces = {"application/json"}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60492452

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档