如何在rest api中按字段(逗号分隔),排序,分页添加动态过滤器?

时间:2016-11-11 13:01:40

标签: rest swagger swagger-editor

下面是使用get方法的其余API的简单代码块。

现在我添加了限制参数,但我想添加分页每页结果 SortByFields SortBy *( asc或desc)过滤(按多个字段)

paths:
  /pets:
    get:
     description: Returns all pets
     produces:
     - application/json
     parameters:
     - name: limit
       in: query
       description: SET LIMIT OF THE RESULT
       type: integer
       format: int32
       required: false

我该怎么做?

1 个答案:

答案 0 :(得分:0)

OpenStack发布了specification

  

用于提供有关如何处理大型分页的指导   结果集和提供过滤和排序的最佳方法   项目的公共REST API中的功能。

如果使用swagger-editor,包含的示例twitter.yaml有一些基本的过滤和分页。

另见Pagination in a REST web application

Spring Data REST - Reference Documentation也在第6章分页和排序中很好地解释了这些概念。