Software /
code /
prosody
Comparison
teal-src/util/jsonschema.tl @ 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 |
parent | 11444:b3a903032611 |
child | 11446:58c534bac798 |
comparison
equal
deleted
inserted
replaced
11444:b3a903032611 | 11445:c73744fa3bdf |
---|---|
235 end | 235 end |
236 end | 236 end |
237 end | 237 end |
238 | 238 |
239 if schema.properties then | 239 if schema.properties then |
240 for k, s in pairs(schema.properties) do | 240 local additional : schema_t | boolean = schema.additionalProperties or true |
241 if data[k] ~= nil then | |
242 if not validate(s, data[k]) then | |
243 return false | |
244 end | |
245 end | |
246 end | |
247 end | |
248 | |
249 if schema.additionalProperties then | |
250 for k, v in pairs(data) do | 241 for k, v in pairs(data) do |
251 if k is string then | 242 local s = schema.properties[k as string] or additional as schema_t |
252 if not (schema.properties and schema.properties[k]) then | 243 if not validate(s, v) then |
253 if not validate(schema.additionalProperties, v) then | 244 return false |
254 return false | 245 end |
255 end | 246 end |
256 end | 247 elseif schema.additionalProperties then |
257 end | 248 for k, v in pairs(data) do |
258 end | 249 if not validate(schema.additionalProperties, v) then |
259 elseif schema.properties then | 250 return false |
260 for k in pairs(data) do | |
261 if k is string then | |
262 if schema.properties[k] == nil then | |
263 return false | |
264 end | |
265 end | 251 end |
266 end | 252 end |
267 end | 253 end |
268 | 254 |
269 if schema.uniqueItems then | 255 if schema.uniqueItems then |