Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(endpoints): propagate next page size param #9029 #9648

Closed
wants to merge 10 commits into from
10 changes: 8 additions & 2 deletions kong/api/endpoints.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fffonion I changed this validation in one of the last commits... I believe I need to update this Pull Request

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jacksjm I tried to rebase but maybe i lost some of your commits. Could you rebase your PR upon master (you can use this PR as start and force push to yours)? Make sure not to use "merge" but "rebase", since we only merge PR with a rebase, if the PR contains merge commits, it may lead to conflicts as order changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nvm, looks like i can do a squash : ) closing this now

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,
Expand Down
9 changes: 9 additions & 0 deletions spec/02-integration/04-admin_api/10-services_routes_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down