Mercurial > prosody-hg
comparison util/jsonschema.lua @ 12501:042de4f0076e
Merge 0.12->trunk
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Mon, 09 May 2022 22:40:45 +0200 |
| parents | 88e1b94105ae |
| children | ca6a43fe0231 |
comparison
equal
deleted
inserted
replaced
| 12498:c3e47a5dd30d | 12501:042de4f0076e |
|---|---|
| 1 local m_type = math.type or function (n) | |
| 2 return n % 1 == 0 and n <= 9007199254740992 and n >= -9007199254740992 and "integer" or "float"; | |
| 3 end; | |
| 1 local json = require("util.json") | 4 local json = require("util.json") |
| 2 local null = json.null; | 5 local null = json.null; |
| 3 | 6 |
| 4 local pointer = require("util.jsonpointer") | 7 local pointer = require("util.jsonpointer") |
| 5 | 8 |
| 15 if schema == "object" and type(data) == "table" then | 18 if schema == "object" and type(data) == "table" then |
| 16 return type(data) == "table" and (next(data) == nil or type((next(data, nil))) == "string") | 19 return type(data) == "table" and (next(data) == nil or type((next(data, nil))) == "string") |
| 17 elseif schema == "array" and type(data) == "table" then | 20 elseif schema == "array" and type(data) == "table" then |
| 18 return type(data) == "table" and (next(data) == nil or type((next(data, nil))) == "number") | 21 return type(data) == "table" and (next(data) == nil or type((next(data, nil))) == "number") |
| 19 elseif schema == "integer" then | 22 elseif schema == "integer" then |
| 20 return math.type(data) == schema | 23 return m_type(data) == schema |
| 21 elseif schema == "null" then | 24 elseif schema == "null" then |
| 22 return data == null | 25 return data == null |
| 23 else | 26 else |
| 24 return type(data) == schema | 27 return type(data) == schema |
| 25 end | 28 end |
