File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -626,7 +626,7 @@ generate_validator = function(ctx, schema)
626626 end
627627 ctx :stmt ( ' end' ) -- if prop
628628
629- if type (subschema ) == " table" and subschema .default and
629+ if type (subschema ) == " table" and subschema .default ~= nil and
630630 (type (subschema .default ) == " number" or
631631 type (subschema .default ) == " string" or
632632 type (subschema .default ) == " boolean" or
@@ -964,7 +964,7 @@ generate_validator = function(ctx, schema)
964964 end
965965 end
966966 ctx :stmt (' ) then' )
967- ctx :stmt (' return false, "matches non of the enum values"' )
967+ ctx :stmt (' return false, "matches none of the enum values"' )
968968 ctx :stmt (' end' )
969969 end
970970
Original file line number Diff line number Diff line change @@ -133,3 +133,20 @@ local rule = {
133133
134134local validator = jsonschema .generate_validator (rule )
135135assert (rule .id == " root:/" , " fail: schema id is removed" )
136+
137+ ---- ------------------------------------------------- test case 6
138+ local rule = {
139+ type = " object" ,
140+ properties = {
141+ foo = {type = " boolean" , default = false }
142+ }
143+ }
144+
145+ local validator = jsonschema .generate_validator (rule )
146+ local t = {}
147+ local ok , err = validator (t )
148+ if not ok then
149+ ngx .say (" fail: inject default false value: " , err )
150+ return
151+ end
152+ assert (t .foo == false , " fail: inject default false value" )
You can’t perform that action at this time.
0 commit comments