Skip to content

Commit 05706c7

Browse files
authored
fix: don't remove the schema's original id (#44)
1 parent 26c21e8 commit 05706c7

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/jsonschema.lua

+5-1
Original file line numberDiff line numberDiff line change
@@ -1149,8 +1149,12 @@ return {
11491149
parse_ipv6 = custom and custom.parse_ipv6 or parse_ipv6
11501150
}
11511151
local name = custom and custom.name
1152+
local has_original_id
1153+
if type(schema) == "table" and schema.id then
1154+
has_original_id = true
1155+
end
11521156
local ctx = generate_main_validator_ctx(schema, custom):as_func(name, validatorlib, customlib)
1153-
if type(schema) == "table" then
1157+
if type(schema) == "table" and not has_original_id then
11541158
schema.id = nil
11551159
end
11561160
return ctx

t/default.lua

+12
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,15 @@ if ngx.now() - start_time > 0.1 then
121121
ngx.exit(-1)
122122
end
123123
ngx.say("passed: check uniqueItems array with few table items")
124+
125+
----------------------------------------------------- test case 5
126+
local rule = {
127+
id = "root:/",
128+
type = "object",
129+
properties = {
130+
base = {type = "string", default = "xxxxxxxx"}
131+
}
132+
}
133+
134+
local validator = jsonschema.generate_validator(rule)
135+
assert(rule.id == "root:/", "fail: schema id is removed")

0 commit comments

Comments
 (0)