comparison util/jsonschema.lua @ 11445:c73744fa3bdf

util.jsonschema: Restructure handling of "properties" and "additionalProperties" This is a bit cleaner, I think
author Kim Alvefur <zash@zash.se>
date Tue, 09 Mar 2021 02:41:47 +0100
parents b3a903032611
children 58c534bac798
comparison
equal deleted inserted replaced
11444:b3a903032611 11445:c73744fa3bdf
154 end 154 end
155 end 155 end
156 end 156 end
157 157
158 if schema.properties then 158 if schema.properties then
159 for k, s in pairs(schema.properties) do 159 local additional = schema.additionalProperties or true
160 if data[k] ~= nil then
161 if not validate(s, data[k]) then
162 return false
163 end
164 end
165 end
166 end
167
168 if schema.additionalProperties then
169 for k, v in pairs(data) do 160 for k, v in pairs(data) do
170 if type(k) == "string" then 161 local s = schema.properties[k] or additional
171 if not (schema.properties and schema.properties[k]) then 162 if not validate(s, v) then
172 if not validate(schema.additionalProperties, v) then 163 return false
173 return false 164 end
174 end 165 end
175 end 166 elseif schema.additionalProperties then
176 end 167 for k, v in pairs(data) do
177 end 168 if not validate(schema.additionalProperties, v) then
178 elseif schema.properties then 169 return false
179 for k in pairs(data) do
180 if type(k) == "string" then
181 if schema.properties[k] == nil then
182 return false
183 end
184 end 170 end
185 end 171 end
186 end 172 end
187 173
188 if schema.uniqueItems then 174 if schema.uniqueItems then