Skip to content

Commit

Permalink
fix(admin) fix data format for empty upstreams array
Browse files Browse the repository at this point in the history
When no active upstreams are present, the 'data' response field
should be an empty list, not an object
  • Loading branch information
p0pr0ck5 authored and thibaultcha committed Jun 16, 2017
1 parent c8f8ef9 commit 10065be
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion kong/api/routes/upstreams.lua
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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?
Expand Down

0 comments on commit 10065be

Please sign in to comment.