Skip to content

Commit

Permalink
fix: don't remove the schema's original id (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
spacewander committed Nov 27, 2020
1 parent 26c21e8 commit 05706c7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/jsonschema.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1149,8 +1149,12 @@ return {
parse_ipv6 = custom and custom.parse_ipv6 or parse_ipv6
}
local name = custom and custom.name
local has_original_id
if type(schema) == "table" and schema.id then
has_original_id = true
end
local ctx = generate_main_validator_ctx(schema, custom):as_func(name, validatorlib, customlib)
if type(schema) == "table" then
if type(schema) == "table" and not has_original_id then
schema.id = nil
end
return ctx
Expand Down
12 changes: 12 additions & 0 deletions t/default.lua
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,15 @@ if ngx.now() - start_time > 0.1 then
ngx.exit(-1)
end
ngx.say("passed: check uniqueItems array with few table items")

----------------------------------------------------- test case 5
local rule = {
id = "root:/",
type = "object",
properties = {
base = {type = "string", default = "xxxxxxxx"}
}
}

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

0 comments on commit 05706c7

Please sign in to comment.