From 503eb491a03f9d1cc27922330a71afd1890551e3 Mon Sep 17 00:00:00 2001 From: Jackson Machado Date: Fri, 7 Oct 2022 10:51:23 -0300 Subject: [PATCH 01/13] 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 f975f2f07de..309aa58f336 100644 --- a/kong/api/endpoints.lua +++ b/kong/api/endpoints.lua @@ -303,12 +303,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) @@ -318,7 +323,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 4f4faf85fcb5cd936fe560646d9b450d3a361297 Mon Sep 17 00:00:00 2001 From: Jackson Machado Date: Mon, 10 Oct 2022 14:01:17 -0300 Subject: [PATCH 02/13] 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 309aa58f336..49eda8dc7e1 100644 --- a/kong/api/endpoints.lua +++ b/kong/api/endpoints.lua @@ -310,8 +310,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 ddce93683c2ec08e732ed3cc6dc0c3b4c45e7798 Mon Sep 17 00:00:00 2001 From: Jackson Machado Date: Tue, 11 Oct 2022 09:54:50 -0300 Subject: [PATCH 03/13] 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 49eda8dc7e1..7b73fe25e1e 100644 --- a/kong/api/endpoints.lua +++ b/kong/api/endpoints.lua @@ -310,7 +310,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 d5b93e1f152a7f761d2163a3974474bd4a4f4a2c Mon Sep 17 00:00:00 2001 From: Jackson Machado Date: Wed, 26 Oct 2022 09:12:59 -0300 Subject: [PATCH 04/13] 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 7b73fe25e1e..87fea286ef5 100644 --- a/kong/api/endpoints.lua +++ b/kong/api/endpoints.lua @@ -319,7 +319,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 ff06fbf445192cefca2d1bd8ef97a3c517f33680 Mon Sep 17 00:00:00 2001 From: Jackson Machado Date: Fri, 28 Oct 2022 11:57:05 -0300 Subject: [PATCH 05/13] 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 e55e98004a1..37f630e98d2 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 57e3fc000a21c49e9a5e843579c77132776d37f5 Mon Sep 17 00:00:00 2001 From: Jackson Machado Date: Fri, 28 Oct 2022 21:56:02 -0300 Subject: [PATCH 06/13] 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 43f10d01d68..0ca7dbe8ccc 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 475078922da24a67b66dfab2e2fca2a8d9301ec8 Mon Sep 17 00:00:00 2001 From: Jackson Machado Date: Fri, 7 Oct 2022 10:51:23 -0300 Subject: [PATCH 07/13] 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 0f0ff868382..3ec0d159d83 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 fa355bb90c0709433ebb9aecf426dd1682766048 Mon Sep 17 00:00:00 2001 From: Jackson Machado Date: Mon, 10 Oct 2022 14:01:17 -0300 Subject: [PATCH 08/13] 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 3ec0d159d83..28b3ad6e5ca 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 7dce8df48a2a08d1a6b65e9b6998695b8547f1cd Mon Sep 17 00:00:00 2001 From: Jackson Machado Date: Tue, 11 Oct 2022 09:54:50 -0300 Subject: [PATCH 09/13] 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 28b3ad6e5ca..44e7cf0349f 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 862a2dfc5b41cf79dcf8da4675a07f43d6f40dea Mon Sep 17 00:00:00 2001 From: Jackson Machado Date: Wed, 26 Oct 2022 09:12:59 -0300 Subject: [PATCH 10/13] 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 44e7cf0349f..43f10d01d68 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 5bc1959e3d9337a1a0b60f49093a227bd9b3a450 Mon Sep 17 00:00:00 2001 From: Jackson Machado Date: Fri, 28 Oct 2022 11:57:05 -0300 Subject: [PATCH 11/13] 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 e55e98004a1..37f630e98d2 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 313c389ac4c52a37727012dc17693e4d3413d121 Mon Sep 17 00:00:00 2001 From: Jackson Machado Date: Fri, 28 Oct 2022 21:56:02 -0300 Subject: [PATCH 12/13] 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 43f10d01d68..0ca7dbe8ccc 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 ed435cb58b9ecbe689ad44c882afac2680253d39 Mon Sep 17 00:00:00 2001 From: Jackson Machado Date: Mon, 31 Oct 2022 10:48:14 -0300 Subject: [PATCH 13/13] 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 37f630e98d2..e0c71bb6020 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 }})