plugin(consumer-restriction): use draft7 way to rewrite the JSON Schema. (#2440)

fix: #2402
This commit is contained in:
JinChen 2020-10-19 09:55:08 +08:00 committed by GitHub
parent c9392627a8
commit 5fcbb4de9c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 23 deletions

View File

@ -19,27 +19,41 @@ local core = require("apisix.core")
local schema = {
type = "object",
properties = {
type = {
type = "string",
enum = {"consumer_name", "service_id"},
default = "consumer_name"
},
whitelist = {
type = "array",
items = {type = "string"},
minItems = 1
},
blacklist = {
type = "array",
items = {type = "string"},
minItems = 1
},
rejected_code = {type = "integer", minimum = 200, default = 403}
},
oneOf = {
{required = {"whitelist"}},
{required = {"blacklist"}}
{
title = "blacklist",
properties = {
type = {
type = "string",
enum = {"consumer_name", "service_id"},
default = "consumer_name"
},
blacklist = {
type = "array",
minItems = 1,
items = {type = "string"}
},
rejected_code = {type = "integer", minimum = 200, default = 403}
},
required = {"blacklist"},
},
{
title = "whitelist",
properties = {
type = {
type = "string",
enum = {"consumer_name", "service_id"},
default = "consumer_name"
},
whitelist = {
type = "array",
minItems = 1,
items = {type = "string"}
},
rejected_code = {type = "integer", minimum = 200, default = 403}
},
required = {"whitelist"},
}
}
}

View File

@ -30,8 +30,9 @@ __DATA__
location /t {
content_by_lua_block {
local plugin = require("apisix.plugins.consumer-restriction")
local conf = {
whitelist = {
local conf = {
title = "whitelist",
whitelist = {
"jack1",
"jack2"
}
@ -47,7 +48,7 @@ __DATA__
--- request
GET /t
--- response_body
{"rejected_code":403,"type":"consumer_name","whitelist":["jack1","jack2"]}
{"type":"consumer_name","title":"whitelist","rejected_code":403,"whitelist":["jack1","jack2"]}
--- no_error_log
[error]