Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add id to global_rules schema #9517

Merged
merged 1 commit into from
May 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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