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
23 changes: 23 additions & 0 deletions lib/jsonschema.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,29 @@ generate_validator = function(ctx, schema)
ctx:stmt('end')
end

if schema['if'] then
ctx:stmt( 'do')
local validator = ctx:validator({ 'if' }, schema['if'])
ctx:stmt(sformat( ' local matched = %s(%s)', validator, ctx:param(1)))
if schema['then'] then
ctx:stmt( ' if matched then')
validator = ctx:validator({ 'then' }, schema['then'])
ctx:stmt(sformat(' if not %s(%s) then', validator, ctx:param(1)))
ctx:stmt( ' return false, "then clause did not match"')
ctx:stmt( ' end')
ctx:stmt( ' end')
end
if schema['else'] then
ctx:stmt( ' if not matched then')
validator = ctx:validator({ 'else' }, schema['else'])
ctx:stmt(sformat(' if not %s(%s) then', validator, ctx:param(1)))
ctx:stmt( ' return false, "else clause did not match"')
ctx:stmt( ' end')
ctx:stmt( ' end')
end
ctx:stmt( 'end')
end

if schema['not'] then
local validator = ctx:validator({ 'not' }, schema['not'])
ctx:stmt(sformat('if %s(%s) then', validator, ctx:param(1)))
Expand Down
4 changes: 1 addition & 3 deletions t/draft7.lua
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,13 @@ local supported = {
'spec/JSON-Schema-Test-Suite/tests/draft7/format.json',
'spec/JSON-Schema-Test-Suite/tests/draft7/const.json',
'spec/JSON-Schema-Test-Suite/tests/draft7/contains.json',
'spec/JSON-Schema-Test-Suite/tests/draft7/if-then-else.json',

-- ref
'spec/JSON-Schema-Test-Suite/tests/draft7/ref.json',
-- not support: an external resolver is required
-- 'spec/JSON-Schema-Test-Suite/tests/draft7/refRemote.json',
-- 'spec/JSON-Schema-Test-Suite/tests/draft7/definitions.json',

-- not support: todo
-- 'spec/JSON-Schema-Test-Suite/tests/draft7/if-then-else.json',
}
-- supported = {
-- 'spec/JSON-Schema-Test-Suite/tests/draft7/dependencies.json',
Expand Down