在Swagger文档中隐藏控制器参数

时间:2018-10-23 04:10:05

标签: java jersey swagger

我正在使用swagger-jersey2-jaxrs生成swagger.json。这是我的Java代码:

@Path("/example")
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiImplicitParams({
        @ApiImplicitParam(name = "object", required = true, dataTypeClass = MyObject.class, paramType = "body")
})
@ApiOperation(value = "Return one entity", notes = "Returns one entity at random", response = CommonResponse.class)
public String getStuff(String requestString) {...}

结果是我得到了这个swagger.json文件:

"parameters": [
          {
            "in": "body",
            "name": "body", // SHOULD BE REMOVED
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "body",
            "name": "object", // I ONLY WANT THIS
            "required": true,
            "schema": {
              "$ref": "#/definitions/MyObject"
            }
          }
        ]

据我所知String requestString将默认生成参数名称=“ body”。如何删除?我只希望出现参数name =“ object”。

1 个答案:

答案 0 :(得分:1)

通过使用tintColor="green" 中的@ApiParam注释,您可以隐藏参数。为此,请将字段io.swagger.annotations设置为hidden

true