Spring Boot 2.1.8,Spring Web 5.1.9,Springfox Swagger 2.8.0,Swagger注释/模型1.5.14
我的RestController
方法签名如下:
@ApiOperation("List statuses")
@GetMapping(produces = APPLICATION_JSON_VALUE)
public ListResult<Status> listStatuses(
@ApiParam("Filter given IDs")
@RequestParam(value = "id", required = false, defaultValue = "") List<String> ids,
@ApiParam(value = "Sort by property value", allowMultiple = true, format = "propertyName:<asc|desc>", type = "array")
@RequestParam(value = "_sort", required = false, defaultValue = "") List<Sort> sorts
)
ids
如我所料-我可以输入多个单独的值:
但是,无论我如何使用_sort
的不同选项,@ApiParam
始终被记录为单个字符串。有一个自定义的Spring Converter<String, Sort>
bean被注册。
如何强制Swagger将_sort
参数作为字符串列表来处理,其中每个项目的格式必须为"propertyName:<asc|desc>"
?
答案 0 :(得分:1)
使用 @ApiImplicitParam ,您可以将Swagger _sort参数强制为字符串列表
@ApiImplicitParam(name = "_sort", allowMultiple = true, dataType = "string", format = "propertyName:<asc|desc>", paramType = "query",
value = "Sort by property value")