Software /
code /
prosody
Comparison
util/jsonschema.lua @ 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 |
---|---|
156 end | 156 end |
157 | 157 |
158 if schema.properties then | 158 if schema.properties then |
159 local additional = schema.additionalProperties or true | 159 local additional = schema.additionalProperties or true |
160 for k, v in pairs(data) do | 160 for k, v in pairs(data) do |
161 if schema.propertyNames and not validate(schema.propertyNames, k) then | |
162 return false | |
163 end | |
161 local s = schema.properties[k] or additional | 164 local s = schema.properties[k] or additional |
162 if not validate(s, v) then | 165 if not validate(s, v) then |
163 return false | 166 return false |
164 end | 167 end |
165 end | 168 end |
166 elseif schema.additionalProperties then | 169 elseif schema.additionalProperties then |
167 for k, v in pairs(data) do | 170 for k, v in pairs(data) do |
171 if schema.propertyNames and not validate(schema.propertyNames, k) then | |
172 return false | |
173 end | |
168 if not validate(schema.additionalProperties, v) then | 174 if not validate(schema.additionalProperties, v) then |
169 return false | 175 return false |
170 end | 176 end |
171 end | 177 end |
172 end | 178 end |