Skip to content

Commit

Permalink
fix(admin) do not mutate plugins schema in /plugins/schema/:name
Browse files Browse the repository at this point in the history
Make `remove_functions` produce a copy instead of modifying the plugin
schema table in-place.

Fix Kong#3222
From Kong#3348
  • Loading branch information
hishamhm authored and kikito committed Apr 10, 2018
1 parent 6a03d01 commit 94c614a
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions kong/api/routes/plugins.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ local singletons = require "kong.singletons"
-- Remove functions from a schema definition so that
-- cjson can encode the schema.
local function remove_functions(schema)
local copy = {}
for k, v in pairs(schema) do
if type(v) == "function" then
schema[k] = "function"
end
if type(v) == "table" then
remove_functions(schema[k])
end
copy[k] = (type(v) == "function" and "function")
or (type(v) == "table" and remove_functions(schema[k]))
or v
end
return copy
end

return {
Expand Down Expand Up @@ -50,9 +49,9 @@ return {
return helpers.responses.send_HTTP_NOT_FOUND("No plugin named '" .. self.params.name .. "'")
end

remove_functions(plugin_schema)
local copy = remove_functions(plugin_schema)

return helpers.responses.send_HTTP_OK(plugin_schema)
return helpers.responses.send_HTTP_OK(copy)
end
},

Expand Down

0 comments on commit 94c614a

Please sign in to comment.