【问题标题】:How to customize model in Springfox's Swagger 2 for a string request body?如何在 Springfox Swagger2 中为字符串请求正文自定义模型?
【发布时间】:2020-05-13 10:31:54
【问题描述】:

我想为我使用 Springfox 的 Swagger (Spring REST API) 制作的 API 文档自定义模型。

这是我的代码示例:

   @ApiOperation("Creating a kafka topic")
   @ApiImplicitParams(
           @ApiImplicitParam(name = "requestBody", value = "The body of request", required = true,
                   example = "{\"server\": \"localhost:9092\",\"topic\": \"test\", \"parmas\":{...}}")
   )
   public ResponseEntity<String> createTopic(@RequestBody String requestBody) {
       TopicCreationRequest request = gson.fromJson(requestBody, TopicCreationRequest.class);

       ...

       return ResponseEntity.ok().body(response.toString());
   }

有可能吗?

【问题讨论】:

  • 为什么不创建请求体的POJO呢?虽然看起来像你呢? TopicCreationRequest?为什么不使用它作为 Param 而不是 String?

标签: spring-boot swagger-ui swagger-2.0 springfox


【解决方案1】:

感谢 Thomas__ 我切换了 POJO 并且它工作了

【讨论】:

    猜你喜欢
    • 2017-07-09
    • 2017-11-06
    • 1970-01-01
    • 2017-07-10
    • 1970-01-01
    • 2019-01-27
    • 1970-01-01
    • 1970-01-01
    • 2013-02-12
    相关资源
    最近更新 更多