Software /
code /
prosody
Comparison
teal-src/util/jsonschema.tl @ 11446:58c534bac798
util.jsonschema: Implement "propertyNames"
This is a bit special in Lua as tables are not limited to string keys
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 09 Mar 2021 02:43:50 +0100 |
parent | 11445:c73744fa3bdf |
child | 11447:7ad137fe665b |
comparison
equal
deleted
inserted
replaced
11445:c73744fa3bdf | 11446:58c534bac798 |
---|---|
52 minProperties : number | 52 minProperties : number |
53 required : { string } | 53 required : { string } |
54 dependentRequired : { string : { string } } | 54 dependentRequired : { string : { string } } |
55 additionalProperties: schema_t | 55 additionalProperties: schema_t |
56 patternProperties: schema_t | 56 patternProperties: schema_t |
57 propertyNames : schema_t | |
57 | 58 |
58 -- xml | 59 -- xml |
59 record xml_t | 60 record xml_t |
60 name : string | 61 name : string |
61 namespace : string | 62 namespace : string |
237 end | 238 end |
238 | 239 |
239 if schema.properties then | 240 if schema.properties then |
240 local additional : schema_t | boolean = schema.additionalProperties or true | 241 local additional : schema_t | boolean = schema.additionalProperties or true |
241 for k, v in pairs(data) do | 242 for k, v in pairs(data) do |
243 if schema.propertyNames and not validate(schema.propertyNames, k) then | |
244 return false | |
245 end | |
242 local s = schema.properties[k as string] or additional as schema_t | 246 local s = schema.properties[k as string] or additional as schema_t |
243 if not validate(s, v) then | 247 if not validate(s, v) then |
244 return false | 248 return false |
245 end | 249 end |
246 end | 250 end |
247 elseif schema.additionalProperties then | 251 elseif schema.additionalProperties then |
248 for k, v in pairs(data) do | 252 for k, v in pairs(data) do |
253 if schema.propertyNames and not validate(schema.propertyNames, k) then | |
254 return false | |
255 end | |
249 if not validate(schema.additionalProperties, v) then | 256 if not validate(schema.additionalProperties, v) then |
250 return false | 257 return false |
251 end | 258 end |
252 end | 259 end |
253 end | 260 end |