Software /
code /
prosody
Annotate
util/jsonschema.lua @ 13267:7ae000fc8c07 0.12
mod_muc_mam: Improve wording of enable setting
Suggested by jstein in the chat
This option label is used by XMPP clients to explain what the option does.
a) The user should know where the data is archived.
b) The user needs a statement that can be enabled/disabled by the variable. A question would have the wrong logic here.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 15 Oct 2023 14:43:11 +0200 |
parent | 12760:ce1a0f9bf25a |
child | 12975:d10957394a3c |
rev | line source |
---|---|
12579
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
1 -- This file is generated from teal-src/util/jsonschema.lua |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
2 |
12760
ce1a0f9bf25a
util.jsonschema: Use same integer/float logic on Lua 5.2 and 5.3
Kim Alvefur <zash@zash.se>
parents:
12759
diff
changeset
|
3 local m_type = function(n) |
ce1a0f9bf25a
util.jsonschema: Use same integer/float logic on Lua 5.2 and 5.3
Kim Alvefur <zash@zash.se>
parents:
12759
diff
changeset
|
4 return type(n) == "number" and n % 1 == 0 and n <= 9007199254740992 and n >= -9007199254740992 and "integer" or "float"; |
12500
88e1b94105ae
util.jsonschema: Lua <5.3 compat here too
Kim Alvefur <zash@zash.se>
parents:
12132
diff
changeset
|
5 end; |
11460
a8b4e04bc044
util.jsonschema: Rename types for improved readability
Kim Alvefur <zash@zash.se>
parents:
11448
diff
changeset
|
6 local json = require("util.json") |
a8b4e04bc044
util.jsonschema: Rename types for improved readability
Kim Alvefur <zash@zash.se>
parents:
11448
diff
changeset
|
7 local null = json.null; |
11434
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
8 |
12132
4ff0d33dfb2b
util.jsonschema: Add support for $ref pointers
Kim Alvefur <zash@zash.se>
parents:
11460
diff
changeset
|
9 local pointer = require("util.jsonpointer") |
4ff0d33dfb2b
util.jsonschema: Add support for $ref pointers
Kim Alvefur <zash@zash.se>
parents:
11460
diff
changeset
|
10 |
11460
a8b4e04bc044
util.jsonschema: Rename types for improved readability
Kim Alvefur <zash@zash.se>
parents:
11448
diff
changeset
|
11 local json_type_name = json.json_type_name |
a8b4e04bc044
util.jsonschema: Rename types for improved readability
Kim Alvefur <zash@zash.se>
parents:
11448
diff
changeset
|
12 |
a8b4e04bc044
util.jsonschema: Rename types for improved readability
Kim Alvefur <zash@zash.se>
parents:
11448
diff
changeset
|
13 local schema_t = {} |
a8b4e04bc044
util.jsonschema: Rename types for improved readability
Kim Alvefur <zash@zash.se>
parents:
11448
diff
changeset
|
14 |
12579
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
15 local json_schema_object = { xml_t = {} } |
11434
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
16 |
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
17 local function simple_validate(schema, data) |
12579
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
18 if schema == nil then |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
19 return true |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
20 elseif schema == "object" and type(data) == "table" then |
11434
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
21 return type(data) == "table" and (next(data) == nil or type((next(data, nil))) == "string") |
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
22 elseif schema == "array" and type(data) == "table" then |
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
23 return type(data) == "table" and (next(data) == nil or type((next(data, nil))) == "number") |
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
24 elseif schema == "integer" then |
12500
88e1b94105ae
util.jsonschema: Lua <5.3 compat here too
Kim Alvefur <zash@zash.se>
parents:
12132
diff
changeset
|
25 return m_type(data) == schema |
11460
a8b4e04bc044
util.jsonschema: Rename types for improved readability
Kim Alvefur <zash@zash.se>
parents:
11448
diff
changeset
|
26 elseif schema == "null" then |
a8b4e04bc044
util.jsonschema: Rename types for improved readability
Kim Alvefur <zash@zash.se>
parents:
11448
diff
changeset
|
27 return data == null |
12579
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
28 elseif type(schema) == "table" then |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
29 for _, one in ipairs(schema) do |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
30 if simple_validate(one, data) then |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
31 return true |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
32 end |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
33 end |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
34 return false |
11434
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
35 else |
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
36 return type(data) == schema |
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
37 end |
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
38 end |
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
39 |
12579
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
40 local complex_validate |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
41 |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
42 local function validate(schema, data, root) |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
43 if type(schema) == "boolean" then |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
44 return schema |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
45 else |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
46 return complex_validate(schema, data, root) |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
47 end |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
48 end |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
49 |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
50 function complex_validate(schema, data, root) |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
51 |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
52 if root == nil then |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
53 root = schema |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
54 end |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
55 |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
56 if schema["$ref"] and schema["$ref"]:sub(1, 1) == "#" then |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
57 local referenced = pointer.resolve(root, schema["$ref"]:sub(2)) |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
58 if referenced ~= nil and referenced ~= root and referenced ~= schema then |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
59 if not validate(referenced, data, root) then |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
60 return false |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
61 end |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
62 end |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
63 end |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
64 |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
65 if not simple_validate(schema.type, data) then |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
66 return false |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
67 end |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
68 |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
69 if schema.type == "object" then |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
70 if type(data) == "table" then |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
71 |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
72 for k in pairs(data) do |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
73 if not (type(k) == "string") then |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
74 return false |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
75 end |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
76 end |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
77 end |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
78 end |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
79 |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
80 if schema.type == "array" then |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
81 if type(data) == "table" then |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
82 |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
83 for i in pairs(data) do |
12759
ec54fe0003d5
util.jsonschema: Fix Lua 5.2 integer compat
Kim Alvefur <zash@zash.se>
parents:
12579
diff
changeset
|
84 if not (m_type(i) == "integer") then |
12579
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
85 return false |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
86 end |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
87 end |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
88 end |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
89 end |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
90 |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
91 if schema["enum"] ~= nil then |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
92 local match = false |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
93 for _, v in ipairs(schema["enum"]) do |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
94 if v == data then |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
95 |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
96 match = true |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
97 break |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
98 end |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
99 end |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
100 if not match then |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
101 return false |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
102 end |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
103 end |
11434
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
104 |
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
105 if type(data) == "string" then |
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
106 if schema.maxLength and #data > schema.maxLength then |
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
107 return false |
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
108 end |
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
109 if schema.minLength and #data < schema.minLength then |
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
110 return false |
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
111 end |
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
112 end |
12579
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
113 |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
114 if type(data) == "number" then |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
115 if schema.multipleOf and (data == 0 or data % schema.multipleOf ~= 0) then |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
116 return false |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
117 end |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
118 |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
119 if schema.maximum and not (data <= schema.maximum) then |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
120 return false |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
121 end |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
122 |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
123 if schema.exclusiveMaximum and not (data < schema.exclusiveMaximum) then |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
124 return false |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
125 end |
11434
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
126 |
12579
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
127 if schema.minimum and not (data >= schema.minimum) then |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
128 return false |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
129 end |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
130 |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
131 if schema.exclusiveMinimum and not (data > schema.exclusiveMinimum) then |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
132 return false |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
133 end |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
134 end |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
135 |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
136 if schema.allOf then |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
137 for _, sub in ipairs(schema.allOf) do |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
138 if not validate(sub, data, root) then |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
139 return false |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
140 end |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
141 end |
11434
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
142 end |
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
143 |
12579
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
144 if schema.oneOf then |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
145 local valid = 0 |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
146 for _, sub in ipairs(schema.oneOf) do |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
147 if validate(sub, data, root) then |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
148 valid = valid + 1 |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
149 end |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
150 end |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
151 if valid ~= 1 then |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
152 return false |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
153 end |
11434
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
154 end |
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
155 |
12579
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
156 if schema.anyOf then |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
157 local match = false |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
158 for _, sub in ipairs(schema.anyOf) do |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
159 if validate(sub, data, root) then |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
160 match = true |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
161 break |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
162 end |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
163 end |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
164 if not match then |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
165 return false |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
166 end |
11434
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
167 end |
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
168 |
12579
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
169 if schema["not"] then |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
170 if validate(schema["not"], data, root) then |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
171 return false |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
172 end |
11434
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
173 end |
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
174 |
12579
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
175 if schema["if"] ~= nil then |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
176 if validate(schema["if"], data, root) then |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
177 if schema["then"] then |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
178 return validate(schema["then"], data, root) |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
179 end |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
180 else |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
181 if schema["else"] then |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
182 return validate(schema["else"], data, root) |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
183 end |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
184 end |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
185 end |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
186 |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
187 if schema.const ~= nil and schema.const ~= data then |
11434
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
188 return false |
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
189 end |
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
190 |
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
191 if type(data) == "table" then |
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
192 |
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
193 if schema.maxItems and #data > schema.maxItems then |
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
194 return false |
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
195 end |
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
196 |
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
197 if schema.minItems and #data < schema.minItems then |
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
198 return false |
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
199 end |
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
200 |
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
201 if schema.required then |
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
202 for _, k in ipairs(schema.required) do |
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
203 if data[k] == nil then |
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
204 return false |
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
205 end |
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
206 end |
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
207 end |
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
208 |
12579
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
209 if schema.propertyNames ~= nil then |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
210 for k in pairs(data) do |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
211 if not validate(schema.propertyNames, k, root) then |
11445
c73744fa3bdf
util.jsonschema: Restructure handling of "properties" and "additionalProperties"
Kim Alvefur <zash@zash.se>
parents:
11444
diff
changeset
|
212 return false |
11434
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
213 end |
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
214 end |
12579
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
215 end |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
216 |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
217 if schema.properties then |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
218 for k, sub in pairs(schema.properties) do |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
219 if data[k] ~= nil and not validate(sub, data[k], root) then |
11446
58c534bac798
util.jsonschema: Implement "propertyNames"
Kim Alvefur <zash@zash.se>
parents:
11445
diff
changeset
|
220 return false |
58c534bac798
util.jsonschema: Implement "propertyNames"
Kim Alvefur <zash@zash.se>
parents:
11445
diff
changeset
|
221 end |
12579
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
222 end |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
223 end |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
224 |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
225 if schema.additionalProperties ~= nil then |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
226 for k, v in pairs(data) do |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
227 if schema.properties == nil or schema.properties[k] == nil then |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
228 if not validate(schema.additionalProperties, v, root) then |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
229 return false |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
230 end |
11434
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
231 end |
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
232 end |
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
233 end |
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
234 |
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
235 if schema.uniqueItems then |
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
236 |
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
237 local values = {} |
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
238 for _, v in pairs(data) do |
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
239 if values[v] then |
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
240 return false |
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
241 end |
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
242 values[v] = true |
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
243 end |
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
244 end |
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
245 |
11443
a526abef61e6
util.jsonschema: Implement the "prefixItems" keyword
Kim Alvefur <zash@zash.se>
parents:
11442
diff
changeset
|
246 local p = 0 |
12579
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
247 if schema.prefixItems ~= nil then |
11443
a526abef61e6
util.jsonschema: Implement the "prefixItems" keyword
Kim Alvefur <zash@zash.se>
parents:
11442
diff
changeset
|
248 for i, s in ipairs(schema.prefixItems) do |
12579
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
249 if data[i] == nil then |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
250 break |
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
251 elseif validate(s, data[i], root) then |
11443
a526abef61e6
util.jsonschema: Implement the "prefixItems" keyword
Kim Alvefur <zash@zash.se>
parents:
11442
diff
changeset
|
252 p = i |
a526abef61e6
util.jsonschema: Implement the "prefixItems" keyword
Kim Alvefur <zash@zash.se>
parents:
11442
diff
changeset
|
253 else |
a526abef61e6
util.jsonschema: Implement the "prefixItems" keyword
Kim Alvefur <zash@zash.se>
parents:
11442
diff
changeset
|
254 return false |
a526abef61e6
util.jsonschema: Implement the "prefixItems" keyword
Kim Alvefur <zash@zash.se>
parents:
11442
diff
changeset
|
255 end |
a526abef61e6
util.jsonschema: Implement the "prefixItems" keyword
Kim Alvefur <zash@zash.se>
parents:
11442
diff
changeset
|
256 end |
a526abef61e6
util.jsonschema: Implement the "prefixItems" keyword
Kim Alvefur <zash@zash.se>
parents:
11442
diff
changeset
|
257 end |
a526abef61e6
util.jsonschema: Implement the "prefixItems" keyword
Kim Alvefur <zash@zash.se>
parents:
11442
diff
changeset
|
258 |
12579
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
259 if schema.items ~= nil then |
11443
a526abef61e6
util.jsonschema: Implement the "prefixItems" keyword
Kim Alvefur <zash@zash.se>
parents:
11442
diff
changeset
|
260 for i = p + 1, #data do |
12132
4ff0d33dfb2b
util.jsonschema: Add support for $ref pointers
Kim Alvefur <zash@zash.se>
parents:
11460
diff
changeset
|
261 if not validate(schema.items, data[i], root) then |
11440
d5288c99bb5a
util.jsonschema: Correct "items" keyword
Kim Alvefur <zash@zash.se>
parents:
11434
diff
changeset
|
262 return false |
11434
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
263 end |
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
264 end |
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
265 end |
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
266 |
12579
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
267 if schema.contains ~= nil then |
11442
95f0d77175ca
util.jsonschema: Implement the "contains" keyword
Kim Alvefur <zash@zash.se>
parents:
11441
diff
changeset
|
268 local found = false |
95f0d77175ca
util.jsonschema: Implement the "contains" keyword
Kim Alvefur <zash@zash.se>
parents:
11441
diff
changeset
|
269 for i = 1, #data do |
12132
4ff0d33dfb2b
util.jsonschema: Add support for $ref pointers
Kim Alvefur <zash@zash.se>
parents:
11460
diff
changeset
|
270 if validate(schema.contains, data[i], root) then |
11442
95f0d77175ca
util.jsonschema: Implement the "contains" keyword
Kim Alvefur <zash@zash.se>
parents:
11441
diff
changeset
|
271 found = true |
95f0d77175ca
util.jsonschema: Implement the "contains" keyword
Kim Alvefur <zash@zash.se>
parents:
11441
diff
changeset
|
272 break |
95f0d77175ca
util.jsonschema: Implement the "contains" keyword
Kim Alvefur <zash@zash.se>
parents:
11441
diff
changeset
|
273 end |
95f0d77175ca
util.jsonschema: Implement the "contains" keyword
Kim Alvefur <zash@zash.se>
parents:
11441
diff
changeset
|
274 end |
95f0d77175ca
util.jsonschema: Implement the "contains" keyword
Kim Alvefur <zash@zash.se>
parents:
11441
diff
changeset
|
275 if not found then |
95f0d77175ca
util.jsonschema: Implement the "contains" keyword
Kim Alvefur <zash@zash.se>
parents:
11441
diff
changeset
|
276 return false |
95f0d77175ca
util.jsonschema: Implement the "contains" keyword
Kim Alvefur <zash@zash.se>
parents:
11441
diff
changeset
|
277 end |
95f0d77175ca
util.jsonschema: Implement the "contains" keyword
Kim Alvefur <zash@zash.se>
parents:
11441
diff
changeset
|
278 end |
11434
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
279 end |
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
280 |
12579
ca6a43fe0231
util.jsonschema: Fix validation to not assume presence of "type" field
Kim Alvefur <zash@zash.se>
parents:
12500
diff
changeset
|
281 return true |
11434
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
282 end |
66d4067bdfb2
util.jsonschema: Library for JSON Schema validation
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
283 |
11460
a8b4e04bc044
util.jsonschema: Rename types for improved readability
Kim Alvefur <zash@zash.se>
parents:
11448
diff
changeset
|
284 json_schema_object.validate = validate; |
a8b4e04bc044
util.jsonschema: Rename types for improved readability
Kim Alvefur <zash@zash.se>
parents:
11448
diff
changeset
|
285 |
a8b4e04bc044
util.jsonschema: Rename types for improved readability
Kim Alvefur <zash@zash.se>
parents:
11448
diff
changeset
|
286 return json_schema_object |