Comparison

util/jsonschema.lua @ 11448:1d84b54ba0d7

util.jsonschema: Restructure "type" keyword handling More in line with the other tests
author Kim Alvefur <zash@zash.se>
date Tue, 09 Mar 2021 14:31:11 +0100
parent 11447:7ad137fe665b
child 11460:a8b4e04bc044
comparison
equal deleted inserted replaced
11447:7ad137fe665b 11448:1d84b54ba0d7
108 return validate(schema["else"], data) 108 return validate(schema["else"], data)
109 end 109 end
110 end 110 end
111 end 111 end
112 112
113 if not simple_validate(schema.type, data) then
114 return false
115 end
116
117 if schema.const ~= nil and schema.const ~= data then 113 if schema.const ~= nil and schema.const ~= data then
118 return false 114 return false
119 end 115 end
120 116
121 if schema["enum"] ~= nil then 117 if schema["enum"] ~= nil then
125 end 121 end
126 end 122 end
127 return false 123 return false
128 end 124 end
129 125
130 local validator = type_validators[schema.type] 126 if schema.type then
131 if not validator then 127 if not simple_validate(schema.type, data) then
132 return true 128 return false
133 end 129 end
134 130
135 return validator(schema, data) 131 local validator = type_validators[schema.type]
132 if validator then
133 return validator(schema, data)
134 end
135 end
136 return true
136 end 137 end
137 end 138 end
138 139
139 type_validators.table = function(schema, data) 140 type_validators.table = function(schema, data)
140 if type(data) == "table" then 141 if type(data) == "table" then