Software / code / prosody
Comparison
util/jsonschema.lua @ 11443:a526abef61e6
util.jsonschema: Implement the "prefixItems" keyword
This may have been what got me confused about "items" being an array.
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Tue, 09 Mar 2021 02:36:08 +0100 |
| parent | 11442:95f0d77175ca |
| child | 11444:b3a903032611 |
comparison
equal
deleted
inserted
replaced
| 11442:95f0d77175ca | 11443:a526abef61e6 |
|---|---|
| 195 values[v] = true | 195 values[v] = true |
| 196 end | 196 end |
| 197 return true | 197 return true |
| 198 end | 198 end |
| 199 | 199 |
| 200 local p = 0 | |
| 201 if schema.prefixItems then | |
| 202 for i, s in ipairs(schema.prefixItems) do | |
| 203 if validate(s, data[i]) then | |
| 204 p = i | |
| 205 else | |
| 206 return false | |
| 207 end | |
| 208 end | |
| 209 end | |
| 210 | |
| 200 if schema.items then | 211 if schema.items then |
| 201 for i = 1, #data do | 212 for i = p + 1, #data do |
| 202 if not validate(schema.items, data[i]) then | 213 if not validate(schema.items, data[i]) then |
| 203 return false | 214 return false |
| 204 end | 215 end |
| 205 end | 216 end |
| 206 end | 217 end |