【问题标题】:How do I add more information about APIs in Swagger?如何在 Swagger 中添加有关 API 的更多信息?
【发布时间】:2014-07-04 23:57:36
【问题描述】:

我在我的项目中加入了swagger-springmvc,并设法让 Swagger UI 正常工作,但现在关于 UI 中的 API 的信息非常少。我看到的只是通过反射提取的信息。

这是控制器方法的样子:

/**
 * Read all users matching given filter
 * @param String filter The text by which to filter the usernames
 * @return User[] Array of users matching given filter
 * @throws Exception
 */
@RequestMapping(value = "/users/{filter}", method = RequestMethod.GET)
public
@ResponseBody
Collection<User> getUsers(@PathVariable("filter") String filter) throws Exception {
    return domain.getUsersFilteredBy(filter);
}

在每个方法的右侧,Swagger 记录了方法的名称,在这种情况下:

get Users

但我期待看到这个:

Read all users matching given filter

在 helloreverb.com 上的示例中,我看到了每种方法的描述。我怎样才能像这样大摇大摆地将我的控制器方法的描述添加到 UI 中?

【问题讨论】:

    标签: java javadoc swagger api-doc


    【解决方案1】:
    @ApiOperation(value = "Read all users matching given filter",  notes = "Will get all the users for the given filter")
    

    【讨论】:

      【解决方案2】:

      使用包 io.swagger.v3.oas.annotations 中的@Operation;

      @GetMapping
      @Operation(summary = "My Summary", description = "My Description")
      public Object getSomeObject(){..}
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-06-07
        • 1970-01-01
        • 1970-01-01
        • 2015-05-31
        • 2020-11-04
        • 2019-07-10
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多