Swagger2 @ApiParam 指定类型

Swagger2 @ApiParam specifying type

我正在尝试更改生成的 swagger 合约的参数类型,但 @ApiParam#type 属性 似乎无法正常工作。

ResponseEntity<Void> delete(
        @ApiParam(
                value = "The id of the object",
                required = true,
                type = "java.lang.String") Integer id);

在 swagger-ui 中这样做没有效果,id 仍然显示为 Integer。

有人知道解决这个问题的方法吗?

我认为你应该使用 "string" 而不是 "java.lang.String"

注解不是@ApiParam,可以用@ApiImplicitParam,用dataType="string"

支持的类型如下:

  • 整数
  • 浮动
  • 双倍
  • 字符串
  • 字节
  • 布尔值
  • 日期
  • 日期时间

你必须使用@ApiImplicitParam

@ApiImplicitParam(dataType = "string", name = "id")
ResponseEntity<Void> delete(Integer id);