jsonschema
jsonschema copied to clipboard
in some cases, the verification result is wrong
wrong case:
local schema = {
type = "object",
oneOf = {
{
title = "work with consumer object",
properties = {
access_key = {type = "string", minLength = 1, maxLength = 256},
secret_key = {type = "string", minLength = 1, maxLength = 256},
algorithm = {
type = "string",
enum = {"hmac-sha1", "hmac-sha256", "hmac-sha512"},
default = "hmac-sha256"
},
clock_skew = {
type = "integer",
default = 300
},
signed_headers = {
type = "array",
items = {
type = "string",
minLength = 1,
maxLength = 20,
}
},
},
required = {"access_key", "secret_key"},
additionalProperties = false,
},
},
{
title = "work with route or service object",
properties = {},
additionalProperties = false,
}
}
local validator = jsonschema.generate_validator(schema)
local conf = {}
local ok = validator(conf)
if not ok then
ngx.say("value checking failure")
return
end
If I change the order of items of the schema object , it will be ok:
local schema = {
type = "object",
oneOf = {
{
title = "work with route or service object",
properties = {},
additionalProperties = false,
},
{
title = "work with consumer object",
properties = {
access_key = {type = "string", minLength = 1, maxLength = 256},
secret_key = {type = "string", minLength = 1, maxLength = 256},
algorithm = {
type = "string",
enum = {"hmac-sha1", "hmac-sha256", "hmac-sha512"},
default = "hmac-sha256"
},
clock_skew = {
type = "integer",
default = 300
},
signed_headers = {
type = "array",
items = {
type = "string",
minLength = 1,
maxLength = 20,
}
},
},
required = {"access_key", "secret_key"},
additionalProperties = false,
},
},
}
local validator = jsonschema.generate_validator(schema)
local conf = {}
local ok = validator(conf)
if not ok then
ngx.say("value checking failure")
return
end
In the wrong case, conf had been change to {"clock_skew": 300}.
I think this is the reason.
it seems to be a bug, let we fix it