Skip to content

Commit

Permalink
fix(api): avoid returning 405 on /schemas/vaults/:name
Browse files Browse the repository at this point in the history
This fixes an issue where calling the endpoint `POST /schemas/vaults/validate`
was conflicting with the endpoint `/schemas/vaults/:name` which only
has GET implemented, hence resulting in a 405.

By explicting defining a new endpoint `/schemas/vaults/validate`, Lapis
framework should take care of always choosing it over `/schemas/vaults/:name`.

KAG-3699
  • Loading branch information
gruceo authored and locao committed Feb 23, 2024
1 parent ab7232e commit 7e31f08
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
message: "**Admin API**: fixed an issue where calling the endpoint `POST /schemas/vaults/validate` was conflicting with the endpoint `/schemas/vaults/:name` which only has GET implemented, hence resulting in a 405."
type: bugfix
scope: Admin API
5 changes: 5 additions & 0 deletions kong/api/routes/kong.lua
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,11 @@ return {
return validate_schema("plugins", self.params)
end
},
["/schemas/vaults/validate"] = {
POST = function(self, db, helpers)
return validate_schema("vaults", self.params)
end
},
["/schemas/:db_entity_name/validate"] = {
POST = function(self, db, helpers)
local db_entity_name = self.params.db_entity_name
Expand Down
10 changes: 10 additions & 0 deletions spec/02-integration/04-admin_api/02-kong_routes_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,16 @@ describe("Admin API - Kong routes with strategy #" .. strategy, function()
local json = cjson.decode(body)
assert.same({ message = "No vault named 'not-present'" }, json)
end)

it("does not return 405 on /schemas/vaults/validate", function()
local res = assert(client:send {
method = "POST",
path = "/schemas/vaults/validate",
})
local body = assert.res_status(400, res)
local json = cjson.decode(body)
assert.same("schema violation (name: required field missing)", json.message)
end)
end)

describe("/schemas/:entity", function()
Expand Down

0 comments on commit 7e31f08

Please sign in to comment.