Skip to content

Commit

Permalink
feat: add id to global_rules schema (#9517)
Browse files Browse the repository at this point in the history
  • Loading branch information
howiieyu authored May 25, 2023
1 parent a992cd8 commit 216e54d
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
2 changes: 1 addition & 1 deletion apisix/schema_def.lua
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,7 @@ _M.global_rule = {
create_time = timestamp_def,
update_time = timestamp_def
},
required = {"plugins"},
required = {"id", "plugins"},
}


Expand Down
57 changes: 57 additions & 0 deletions t/core/schema_def.t
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,60 @@ __DATA__
}
--- response_body
passed
=== TEST 2: Missing required fields of global_rule.
--- config
location /t {
content_by_lua_block {
local schema_def = require("apisix.schema_def")
local core = require("apisix.core")
local cases = {
{},
{ id = "ADfwefq12D9s" },
{ id = 1 },
{
plugins = {
foo = "bar",
},
},
}
for _, c in ipairs(cases) do
local ok, err = core.schema.check(schema_def.global_rule, c)
assert(not ok)
assert(err ~= nil)
ngx.say("ok: ", ok, " err: ", err)
end
}
}
--- request
GET /t
--- response_body eval
qr/ok: false err: property "(id|plugins)" is required/
=== TEST 3: Sanity check with minimal valid configuration.
--- config
location /t {
content_by_lua_block {
local schema_def = require("apisix.schema_def")
local core = require("apisix.core")
local case = {
id = 1,
plugins = {},
}
local ok, err = core.schema.check(schema_def.global_rule, case)
assert(ok)
assert(err == nil)
ngx.say("passed")
}
}
--- request
GET /t
--- response_body
passed

0 comments on commit 216e54d

Please sign in to comment.