如何使用 Swagger 记录 List<CustomObject> 类型的 Spring MVC 请求参数

Ada*_*lik 5 java spring spring-mvc swagger

Spring Boot 2.1.8、Spring Web 5.1.9、Springfox Swagger 2.8.0、Swagger Annotations/Models 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
    )
Run Code Online (Sandbox Code Playgroud)

ids 按照我的预期记录 - 我可以输入多个单独的值:

身份证

但是,_sort始终记录为单个字符串,无论我如何使用不同的@ApiParam. Converter<String, Sort>注册了一个自定义的 Spring bean。

种类

如何强制 Swagger 将_sort参数作为字符串列表处理,其中每个项目的格式必须为"propertyName:<asc|desc>"

Bhu*_*yal 2

使用@ApiImplicitParam您可以强制 Swagger _sort 参数作为字符串列表

@ApiImplicitParam(name = "_sort", allowMultiple = true, dataType = "string", format = "propertyName:<asc|desc>", paramType = "query",
            value = "Sort by property value")
Run Code Online (Sandbox Code Playgroud)