Software /
code /
prosody
Comparison
util/jsonschema.lua @ 11460:a8b4e04bc044
util.jsonschema: Rename types for improved readability
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 18 Mar 2021 23:57:03 +0100 |
parent | 11448:1d84b54ba0d7 |
child | 12132:4ff0d33dfb2b |
comparison
equal
deleted
inserted
replaced
11459:86904555bffc | 11460:a8b4e04bc044 |
---|---|
1 local schema_t = {xml_t = {}} | 1 local json = require("util.json") |
2 | 2 local null = json.null; |
3 local type_e = schema_t.type_e | 3 |
4 local json_type_name = json.json_type_name | |
5 | |
6 local schema_t = {} | |
7 | |
8 local json_schema_object = {xml_t = {}} | |
4 | 9 |
5 local type_validators = {} | 10 local type_validators = {} |
6 | 11 |
7 local function simple_validate(schema, data) | 12 local function simple_validate(schema, data) |
8 if schema == "object" and type(data) == "table" then | 13 if schema == "object" and type(data) == "table" then |
9 return type(data) == "table" and (next(data) == nil or type((next(data, nil))) == "string") | 14 return type(data) == "table" and (next(data) == nil or type((next(data, nil))) == "string") |
10 elseif schema == "array" and type(data) == "table" then | 15 elseif schema == "array" and type(data) == "table" then |
11 return type(data) == "table" and (next(data) == nil or type((next(data, nil))) == "number") | 16 return type(data) == "table" and (next(data) == nil or type((next(data, nil))) == "number") |
12 elseif schema == "integer" then | 17 elseif schema == "integer" then |
13 return math.type(data) == schema | 18 return math.type(data) == schema |
19 elseif schema == "null" then | |
20 return data == null | |
14 else | 21 else |
15 return type(data) == schema | 22 return type(data) == schema |
16 end | 23 end |
17 end | 24 end |
18 | 25 |
251 return type_validators.table(schema, data) | 258 return type_validators.table(schema, data) |
252 end | 259 end |
253 return false | 260 return false |
254 end | 261 end |
255 | 262 |
256 return {validate = validate; schema_t = schema_t} | 263 json_schema_object.validate = validate; |
264 | |
265 return json_schema_object |