From c2a925c49b515da128305de52cc01a5973d43c54 Mon Sep 17 00:00:00 2001 From: Jackson Machado Date: Fri, 7 Oct 2022 10:51:23 -0300 Subject: [PATCH 01/10] fix(get): propagate next page size param #9029 --- kong/api/endpoints.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/kong/api/endpoints.lua b/kong/api/endpoints.lua index 0f0ff868382f..3ec0d159d839 100644 --- a/kong/api/endpoints.lua +++ b/kong/api/endpoints.lua @@ -304,12 +304,17 @@ 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 args.size then + next_page_size = "&size=" .. escape_uri(type(args.size) == "number" and args.size[1] or args.size) + end + local data, _, err_t, offset = page_collection(self, db, schema, method) if err_t then return handle_error(err_t) @@ -319,7 +324,8 @@ local function get_collection_endpoint(schema, foreign_schema, foreign_field_nam 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, From b84e60f0f9dca0ed3d7147cf1ab38cb84c172f21 Mon Sep 17 00:00:00 2001 From: Jackson Machado Date: Mon, 10 Oct 2022 14:01:17 -0300 Subject: [PATCH 02/10] fix: change to use args.size only if is a number --- kong/api/endpoints.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kong/api/endpoints.lua b/kong/api/endpoints.lua index 3ec0d159d839..28b3ad6e5cae 100644 --- a/kong/api/endpoints.lua +++ b/kong/api/endpoints.lua @@ -311,8 +311,8 @@ local function get_collection_endpoint(schema, foreign_schema, foreign_field_nam next_page_tags = "&tags=" .. escape_uri(type(args.tags) == "table" and args.tags[1] or args.tags) end - if args.size then - next_page_size = "&size=" .. escape_uri(type(args.size) == "number" and args.size[1] or args.size) + if (type(args.size) == "number") then + next_page_size = "&size=" .. args.size end local data, _, err_t, offset = page_collection(self, db, schema, method) From a75bd09277452fe2ef39d937e8ecc0078d66a474 Mon Sep 17 00:00:00 2001 From: Jackson Machado Date: Tue, 11 Oct 2022 09:54:50 -0300 Subject: [PATCH 03/10] fix(style): remove (...) on if --- kong/api/endpoints.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kong/api/endpoints.lua b/kong/api/endpoints.lua index 28b3ad6e5cae..44e7cf0349f4 100644 --- a/kong/api/endpoints.lua +++ b/kong/api/endpoints.lua @@ -311,7 +311,7 @@ local function get_collection_endpoint(schema, foreign_schema, foreign_field_nam next_page_tags = "&tags=" .. escape_uri(type(args.tags) == "table" and args.tags[1] or args.tags) end - if (type(args.size) == "number") then + if type(args.size) == "number" then next_page_size = "&size=" .. args.size end From bb39f41a780e8d3204883ca86155d3e6667ee5c8 Mon Sep 17 00:00:00 2001 From: Jackson Machado Date: Wed, 26 Oct 2022 09:12:59 -0300 Subject: [PATCH 04/10] fix: includes %s on a fmt string --- kong/api/endpoints.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kong/api/endpoints.lua b/kong/api/endpoints.lua index 44e7cf0349f4..43f10d01d689 100644 --- a/kong/api/endpoints.lua +++ b/kong/api/endpoints.lua @@ -320,7 +320,7 @@ local function get_collection_endpoint(schema, foreign_schema, foreign_field_nam 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), From 4c8b70d8353c1da2b725da91901d7b75da26c535 Mon Sep 17 00:00:00 2001 From: Jackson Machado Date: Fri, 28 Oct 2022 11:57:05 -0300 Subject: [PATCH 05/10] chore: create unit test --- .../04-admin_api/10-services_routes_spec.lua | 8 ++++++++ 1 file changed, 8 insertions(+) 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..37f630e98d29 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,14 @@ 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() From f45576ad6e8f7a5441ba4531844ee17ae3d7fd92 Mon Sep 17 00:00:00 2001 From: Jackson Machado Date: Fri, 28 Oct 2022 21:56:02 -0300 Subject: [PATCH 06/10] fix: change to only valid nil value --- kong/api/endpoints.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kong/api/endpoints.lua b/kong/api/endpoints.lua index 43f10d01d689..0ca7dbe8ccc1 100644 --- a/kong/api/endpoints.lua +++ b/kong/api/endpoints.lua @@ -311,7 +311,7 @@ local function get_collection_endpoint(schema, foreign_schema, foreign_field_nam next_page_tags = "&tags=" .. escape_uri(type(args.tags) == "table" and args.tags[1] or args.tags) end - if type(args.size) == "number" then + if args.size then next_page_size = "&size=" .. args.size end From ec9bff02e45690127f1cbe09fe57d3314de57c1f Mon Sep 17 00:00:00 2001 From: Jackson Machado Date: Fri, 7 Oct 2022 10:51:23 -0300 Subject: [PATCH 07/10] fix(get): propagate next page size param #9029 --- kong/api/endpoints.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kong/api/endpoints.lua b/kong/api/endpoints.lua index 0ca7dbe8ccc1..f36ae82b6205 100644 --- a/kong/api/endpoints.lua +++ b/kong/api/endpoints.lua @@ -312,7 +312,7 @@ local function get_collection_endpoint(schema, foreign_schema, foreign_field_nam end if args.size then - next_page_size = "&size=" .. args.size + next_page_size = "&size=" .. escape_uri(type(args.size) == "number" and args.size[1] or args.size) end local data, _, err_t, offset = page_collection(self, db, schema, method) From 616e57a80290e07d2c088ddd2daf6410a5ec8782 Mon Sep 17 00:00:00 2001 From: Jackson Machado Date: Mon, 10 Oct 2022 14:01:17 -0300 Subject: [PATCH 08/10] fix: change to use args.size only if is a number --- kong/api/endpoints.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kong/api/endpoints.lua b/kong/api/endpoints.lua index f36ae82b6205..5aa8b2069b82 100644 --- a/kong/api/endpoints.lua +++ b/kong/api/endpoints.lua @@ -311,8 +311,8 @@ local function get_collection_endpoint(schema, foreign_schema, foreign_field_nam next_page_tags = "&tags=" .. escape_uri(type(args.tags) == "table" and args.tags[1] or args.tags) end - if args.size then - next_page_size = "&size=" .. escape_uri(type(args.size) == "number" and args.size[1] or args.size) + if (type(args.size) == "number") then + next_page_size = "&size=" .. args.size end local data, _, err_t, offset = page_collection(self, db, schema, method) From 1afcb22846379e50a59663c8ee7a8b3f9eaeeae4 Mon Sep 17 00:00:00 2001 From: Jackson Machado Date: Tue, 11 Oct 2022 09:54:50 -0300 Subject: [PATCH 09/10] fix(style): remove (...) on if --- kong/api/endpoints.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kong/api/endpoints.lua b/kong/api/endpoints.lua index 5aa8b2069b82..43f10d01d689 100644 --- a/kong/api/endpoints.lua +++ b/kong/api/endpoints.lua @@ -311,7 +311,7 @@ local function get_collection_endpoint(schema, foreign_schema, foreign_field_nam next_page_tags = "&tags=" .. escape_uri(type(args.tags) == "table" and args.tags[1] or args.tags) end - if (type(args.size) == "number") then + if type(args.size) == "number" then next_page_size = "&size=" .. args.size end From 2dc64876509a50fc8b9612692752312847453515 Mon Sep 17 00:00:00 2001 From: Jackson Machado Date: Mon, 31 Oct 2022 10:48:14 -0300 Subject: [PATCH 10/10] fix: change test style --- spec/02-integration/04-admin_api/10-services_routes_spec.lua | 1 + 1 file changed, 1 insertion(+) 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 37f630e98d29..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,7 @@ 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 }})