Skip to content
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
4 changes: 2 additions & 2 deletions lib/jsonschema.lua
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ generate_validator = function(ctx, schema)
end
ctx:stmt( ' end') -- if prop

if type(subschema) == "table" and subschema.default and
if type(subschema) == "table" and subschema.default ~= nil and
(type(subschema.default) == "number" or
type(subschema.default) == "string" or
type(subschema.default) == "boolean" or
Expand Down Expand Up @@ -964,7 +964,7 @@ generate_validator = function(ctx, schema)
end
end
ctx:stmt(') then')
ctx:stmt(' return false, "matches non of the enum values"')
ctx:stmt(' return false, "matches none of the enum values"')
ctx:stmt('end')
end

Expand Down
17 changes: 17 additions & 0 deletions t/default.lua
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,20 @@ local rule = {

local validator = jsonschema.generate_validator(rule)
assert(rule.id == "root:/", "fail: schema id is removed")

----------------------------------------------------- test case 6
local rule = {
type = "object",
properties = {
foo = {type = "boolean", default = false}
}
}

local validator = jsonschema.generate_validator(rule)
local t = {}
local ok, err = validator(t)
if not ok then
ngx.say("fail: inject default false value: ", err)
return
end
assert(t.foo == false, "fail: inject default false value")