Skip to content

Commit

Permalink
Merge pull request Kong#1018 from Mashape/fix/api-filtering
Browse files Browse the repository at this point in the history
Fixing API filtering error with unknown fields
  • Loading branch information
subnetmarco committed Feb 25, 2016
2 parents 8b0964e + 99e82c2 commit 59f2791
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions kong/api/crud_helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ function _M.paginated_set(self, dao_collection)
self.params.size = nil
self.params.offset = nil

for k, _ in pairs(self.params) do
if not dao_collection._schema.fields[k] then
self.params[k] = nil
end
end

local data, err = dao_collection:find_by_keys(self.params, size, offset)
if err then
return app_helpers.yield_error(err)
Expand Down
8 changes: 8 additions & 0 deletions spec/integration/admin_api/consumers_routes_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,14 @@ describe("Admin API", function()
assert.falsy(body_page_3.next)
assert.not_same(body_page_2, body_page_3)
end)
it("should not throw an error when filtering with a random field", function()
local response, status = http_client.get(BASE_URL, {hello="world"})
assert.equal(200, status)
local body = json.decode(response)
assert.truthy(body.data)
assert.equal(10, table.getn(body.data))
assert.equal(10, body.total)
end)
end)

describe("/consumers/:consumer", function()
Expand Down

0 comments on commit 59f2791

Please sign in to comment.