【问题标题】:Spring swagger @ApiParam annotation hides a methodSpring swagger @ApiParam 注解隐藏了一个方法
【发布时间】:2021-09-14 14:16:02
【问题描述】:

我面临的问题是,如果我用 swagger 的 @ApiParam 注释标记方法签名中的任何参数,那么我在地址 /swagger-ui.html 上看不到此方法

例子:

@GetMapping
@ApiOperation(value = "Get magazines by type")
public List<Magazine> getMagazines(@RequestParam @NotNull String type) {
    List<Magazine> response = service.getMagazines(type);
    return response;
    }

在这种情况下,如果我去 localhost:8080/swagger-ui.html 我会在控制器中看到这个方法

但是如果该方法有@ApiParam注解,它就不会在swagger上显示

@GetMapping
@ApiOperation(value = "Get magazines by type")
public List<Magazine> getMagazines(@ApiParam(defaultValue = "TEST") @RequestParam @NotNull String type) {
    List<Magazine> response = service.getMagazines(type);
    return response;
}

任何想法为什么会发生?

【问题讨论】:

    标签: java spring swagger


    【解决方案1】:

    Swagger 规范有很多实现。我正在使用以下一个

    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-boot-starter</artifactId>
        <version>3.0.0</version>
    </dependency>
    
    
      @GetMapping
      @ApiOperation(value = "Get magazines by type") 
      public List<Magazine>getMagazines(@ApiParam(defaultValue = "TEST")  @RequestParam String type) {
        List<Magazine> response = service.getMagazines(type);
        return response;
      }
    

    我没有遇到您提到的任何问题。您正在使用的实现可能存在问题。

    【讨论】:

      猜你喜欢
      • 2017-05-17
      • 2014-12-26
      • 1970-01-01
      • 2017-07-09
      • 1970-01-01
      • 2018-04-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多