diff --git a/kong/api/endpoints.lua b/kong/api/endpoints.lua index 0f0ff868382f..43f10d01d689 100644 --- a/kong/api/endpoints.lua +++ b/kong/api/endpoints.lua @@ -304,22 +304,28 @@ end local function get_collection_endpoint(schema, foreign_schema, foreign_field_name, method) return not foreign_schema and function(self, db, helpers) local next_page_tags = "" + local next_page_size = "" local args = self.args.uri if args.tags then next_page_tags = "&tags=" .. escape_uri(type(args.tags) == "table" and args.tags[1] or args.tags) end + if type(args.size) == "number" then + next_page_size = "&size=" .. args.size + end + local data, _, err_t, offset = page_collection(self, db, schema, method) if err_t then return handle_error(err_t) end - local next_page = offset and fmt("/%s?offset=%s%s", + local next_page = offset and fmt("/%s?offset=%s%s%s", schema.admin_api_name or schema.name, escape_uri(offset), - next_page_tags) or null + next_page_tags, + next_page_size) or null return ok { data = data, diff --git a/spec/02-integration/04-admin_api/10-services_routes_spec.lua b/spec/02-integration/04-admin_api/10-services_routes_spec.lua index e55e98004a19..e0c71bb60204 100644 --- a/spec/02-integration/04-admin_api/10-services_routes_spec.lua +++ b/spec/02-integration/04-admin_api/10-services_routes_spec.lua @@ -191,6 +191,15 @@ for _, strategy in helpers.each_strategy() do pages[i] = json end end) + + it("propagate in next a page size", function() + local res = client:get("/services", + { query = { size = 3 }}) + local body = assert.res_status(200, res) + local json = cjson.decode(body) + + assert.equals("/services?offset=" .. ngx.escape_uri(json.offset) .. "&size=3", json.next) + end) end) describe("with no data", function()