From 10065be3d9474f9d40b2728c64b4430de2bd929c Mon Sep 17 00:00:00 2001 From: Robert Paprocki Date: Tue, 13 Jun 2017 22:42:34 -0700 Subject: [PATCH] fix(admin) fix data format for empty upstreams array When no active upstreams are present, the 'data' response field should be an empty list, not an object --- kong/api/routes/upstreams.lua | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/kong/api/routes/upstreams.lua b/kong/api/routes/upstreams.lua index 331c12a5736..02a8341aa56 100644 --- a/kong/api/routes/upstreams.lua +++ b/kong/api/routes/upstreams.lua @@ -1,6 +1,7 @@ local crud = require "kong.api.crud_helpers" local app_helpers = require "lapis.application" local responses = require "kong.tools.responses" +local cjson = require "cjson" -- clean the target history for a given upstream @@ -141,7 +142,7 @@ return { table.sort(target_history, function(a, b) return a.order > b.order end) local seen = {} - local active = {} + local active = setmetatable({}, cjson.empty_array_mt) local active_n = 0 for _, entry in ipairs(target_history) do @@ -163,6 +164,14 @@ return { end end + -- FIXME: remove and stick to previous `empty_array_mt` metatable + -- assignment once https://github.com/openresty/lua-cjson/pull/16 + -- is included in the OpenResty release we use. + if #active == 0 then + active = cjson.empty_array + end + + -- for now lets not worry about rolling our own pagination -- we also end up returning a "backwards" list of targets because -- of how we sorted- do we care?