枚举参数

时间:2019-03-18 12:39:28

标签: java spring swagger swagger-2.0

尝试通过Java代码生成Swagger API,我具有以下YAML:

swagger: "2.0"
      ...
      - in: "body"
        name: "sortName"
        required: false
        schema:
          type: "string"
      ...

基于以下Java代码:

@ApiOperation(
    httpMethod = "GET",
    value = "Selecting a set of default templates",
    response = GalleryTemplateDTO.class,
    responseContainer = "List"
)
@RequestMapping(path = "/search", method = RequestMethod.GET)
public List<GalleryTemplateDTO> search(
...
    @ApiParam(
        name = "sortName",
        allowableValues = "ASC, DESC"
    )
    @RequestParam(value = "sortName", required = false)
        Sort.Direction sortName,
...
)

Sort.Direction是第三方枚举,HTTP方法是GET,没有主体。因此,我认为YAML应该是这样的:

  ...
  - name: "sortName"
    in: "query"
    required: false
    type: "string"
    enum:
    - "ASC"
    - "DESC"
  ...

如果使用String代替Java方法签名中的枚举,则实际上会生成这种YAML。

是否可以在不更改方法参数类型的情况下拥有正确的YAML?

0 个答案:

没有答案