当前位置: 首页 > 知识库问答 >
问题:

ReDoc招摇Spring Boot -响应示例

林魁
2023-03-14

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

共有1个答案

盛建德
2023-03-14

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

produces = {"application/json"}
 类似资料:
  • pom.xml Spring Security配置 application-local.yml 我得到这个结果。 无法呈现此定义提供的定义未指定有效的版本字段。 请注明有效的或版本字段。支持的版本字段是swagger: 2.0和与openapi: 3.0. n匹配的版本字段(例如,openapi: 3.0.0)。

  • 我正在使用Swagger注释和SpringFox为我的REST API(使用Sprint Boot构建)生成Swagger规范。我正在用将返回的代码注释每个方法。例如: 然而,有些东西(我假设SpringFox)正在向每个API调用添加一个200响应代码,而不管它是否已定义。我知道我可以通过在每个方法中添加注释来删除此项,但a)这似乎是@ApiResponse定义的不必要重复,b)某些方法可能返回

  • 我使用Springfox从Spring Boot REST控制器生成了Swagger API规范。 我注意到一个问题,示例值/模型无法显示响应。 作为调查,我在http://localhost:8080/v2/api-文档,并在https://editor.swagger.io/,它也无法显示示例值/模型。这似乎是由于模式没有正确引用模型对象(“Car”)造成的。 但是从Swagger的API文档

  • 如何覆盖微服务项目中的Jhipster swagger配置以更改后端的 /api路径并相应地更新网关Swagger UI?

  • API的返回(响应)结果为 JSON 结构,这是一个 getSalesAmount 的API请求返回: { "code": 1000, "msg": "OK", "data": { "action": "getSalesAmount", "sales_amount": [ { "time

  • 我有一个基于被动MVP架构的应用程序,使用Java 7中的Swing。我的Presenter类执行一些耗时的任务,而我的View/GUI只是在事件发生后调用Presenter的方法。演示者调用view的方法来更新GUI。 显然,我不希望长时间运行的任务发生在EDT上。 我的第一个想法是使用一个SwingWorker,但是由于它只有一个doInbackground方法,我想我必须为Presenter