Spring Pageable界面的Swagger文档 [英] Swagger documentation for Spring Pageable interface

查看:675
本文介绍了Spring Pageable界面的Swagger文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用Spring Boot开发了一个微服务. REST API的文档是使用Swagger编写的.一些REST资源利用Spring概念免费提供分页.下面是一个示例:

I have developed a microservice using Spring Boot. The documentation for the REST API is made with Swagger. Some REST resources make use of Spring concepts to provide pagination for free. Below is an example:

@RequestMapping(value = "/buckets", method = GET)
public PagedResources list(Pageable pageable, PagedResourcesAssembler assembler) {
    return bucketService.listBuckets(pageable, assembler);
}

如果我打开Swagger页面,则该资源可以使用以下表格:

If I open the Swagger page, the following form is available for the resource:

我遇到的问题是,可以使用内容类型 application/json 检测到pageable参数,例如,我不知道如何传递值来更改页面大小.所有的值似乎都被忽略了.

The issue I have is that the pageable parameter is detected with content-type application/json and I don't know how to pass a value to change the page size for example. All values seem to be ignored.

是否可以将查询参数作为JSON对象传递?还是可以配置Swagger为Pageable接口包含的getter生成独立的查询参数字段?

Is it possible to pass the query parameters as JSON object? or is it possible to configure Swagger to generate independent query parameter fields for getters contained by the Pageable interface?

请注意,我将Springfox与Gradle结合使用:

Please note that I am using Springfox with Gradle:

compile 'io.springfox:springfox-spring-web:2.3.1'
compile 'io.springfox:springfox-swagger2:2.3.1'
compile 'io.springfox:springfox-swagger-ui:2.3.1'

推荐答案

这是Spring-Fox的已知问题.参见问题#755 .根据zdila的评论,此时 2 的替代方法是添加@ApiImplicitParams,但这并不理想,但它确实有效.

This is a known issue with Spring-Fox. See Issue #755. Based on zdila's comment 2 at this time alternative is to add @ApiImplicitParams which is not ideal but it does work.

@ApiImplicitParams({
    @ApiImplicitParam(name = "page", dataType = "integer", paramType = "query",
            value = "Results page you want to retrieve (0..N)"),
    @ApiImplicitParam(name = "size", dataType = "integer", paramType = "query",
            value = "Number of records per page."),
    @ApiImplicitParam(name = "sort", allowMultiple = true, dataType = "string", paramType = "query",
            value = "Sorting criteria in the format: property(,asc|desc). " +
                    "Default sort order is ascending. " +
                    "Multiple sort criteria are supported.")
})

[

1 2 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆