Skip to content

Commit

Permalink
fix: body-transformer - failed to transform response body - XML to JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
WrightKD committed Oct 23, 2024
1 parent 11c9d29 commit e2f33c5
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions apisix/plugins/body-transformer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -78,23 +78,32 @@ end


local function remove_namespace(tbl)
for k, v in pairs(tbl) do
if type(v) == "table" and next(v) == nil then

local function update_namespace(ns)
local v = ns
if type(ns) == "table" and next(ns) == nil then
v = ""
tbl[k] = v
elseif type(ns) == "table" then
v = remove_namespace(ns)
end
if type(k) == "string" then
local newk = k:match(".*:(.*)")
if newk then
tbl[newk] = v
tbl[k] = nil
end
if type(v) == "table" then
remove_namespace(v)
return v
end

local function remove_namespace_wrapper(old_table, new_table)
for k, v in pairs(old_table) do
if type(k) == "string" then
local newk = k:match(".*:(.*)")
if newk then
new_table[newk] = update_namespace(v)
else
new_table[k] = update_namespace(v)
end
end
end
return new_table
end
return tbl

return remove_namespace_wrapper(tbl, {})
end


Expand Down

0 comments on commit e2f33c5

Please sign in to comment.