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
12 changes: 11 additions & 1 deletion lib/jsonschema/store.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ local function urlunescape(fragment)
return fragment:gsub('%%(%x%x)', percent_unescape):gsub('~[01]', tilde_unescape)
end

-- attempt to translate a URI fragemnt part to a valid table index:
-- attempt to translate a URI fragment part to a valid table index:
-- * if the part can be converted to number, that number+1 is returned to
-- compensate with Lua 1-based indices
-- * otherwise, the part is returned URL-escaped
Expand Down Expand Up @@ -192,6 +192,16 @@ function store_mt:insert(schema)
local map = {}

local function walk(s, p)
-- handle '$id' keyword
if s['$id'] then
local u = url.parse(s['$id'])
if u.schema ~= nil or u.fragment == nil then
error("Only location independent id is supported. Unsupported $id: " .. s['$id'])
end

map[u.fragment] = self:ref(s).schema
end

local id = s.id
if id and s ~= schema and is_schema(p) then
-- there is an id, but it is not over: we have 2 different cases (!)
Expand Down
13 changes: 11 additions & 2 deletions t/draft7.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ local blacklist = {
['contains keyword validation'] = {
['not array is valid'] = true
},
-- not support: an external resolver is required
['remote ref, containing refs itself'] = true,
['Recursive references between schemas'] = true,
['Location-independent identifier with absolute URI'] = true,
['Location-independent identifier with base URI change in subschema'] = true,
}

local supported = {
Expand Down Expand Up @@ -88,9 +93,10 @@ local supported = {
'spec/JSON-Schema-Test-Suite/tests/draft7/const.json',
'spec/JSON-Schema-Test-Suite/tests/draft7/contains.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/ref.json',
-- 'spec/JSON-Schema-Test-Suite/tests/draft7/definitions.json',

-- not support: todo
Expand All @@ -114,9 +120,12 @@ for _, descriptor in ipairs(supported) do
for _, suite in decode_descriptor(descriptor) do
local skipped = blacklist[suite.description] or {}
if skipped ~= true then
local validator = jsonschema.generate_validator(suite.schema, {
local ok, validator = pcall(jsonschema.generate_validator, suite.schema, {
name = suite.description,
})
if not ok then
error("failed to generate validator for case " .. suite.description .. ", err: " .. validator)
end
for _, case in ipairs(suite.tests) do
if skipped[case.description] then
print("skip suite case: [" .. suite.description .. "] -> [" .. case.description .. "]")
Expand Down