json-schema 2.0.2 → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.textile +1 -1
- data/lib/json-schema/attributes/format.rb +1 -1
- data/test/test_jsonschema_draft1.rb +168 -170
- data/test/test_jsonschema_draft2.rb +188 -190
- data/test/test_jsonschema_draft3.rb +35 -4
- data/test/test_jsonschema_draft4.rb +2 -4
- metadata +1 -1
@@ -12,7 +12,7 @@ class JSONSchemaDraft2Test < Test::Unit::TestCase
|
|
12
12
|
data = {
|
13
13
|
"a" => nil
|
14
14
|
}
|
15
|
-
|
15
|
+
|
16
16
|
# Test integers
|
17
17
|
schema["properties"]["a"]["type"] = "integer"
|
18
18
|
data["a"] = 5
|
@@ -20,14 +20,14 @@ class JSONSchemaDraft2Test < Test::Unit::TestCase
|
|
20
20
|
|
21
21
|
data["a"] = 5.2
|
22
22
|
assert(!JSON::Validator.validate(schema,data,:version => :draft2))
|
23
|
-
|
23
|
+
|
24
24
|
data['a'] = 'string'
|
25
25
|
assert(!JSON::Validator.validate(schema,data,:version => :draft2))
|
26
|
-
|
26
|
+
|
27
27
|
data['a'] = true
|
28
28
|
assert(!JSON::Validator.validate(schema,data,:version => :draft2))
|
29
|
-
|
30
|
-
|
29
|
+
|
30
|
+
|
31
31
|
# Test numbers
|
32
32
|
schema["properties"]["a"]["type"] = "number"
|
33
33
|
data["a"] = 5
|
@@ -35,14 +35,14 @@ class JSONSchemaDraft2Test < Test::Unit::TestCase
|
|
35
35
|
|
36
36
|
data["a"] = 5.2
|
37
37
|
assert(JSON::Validator.validate(schema,data,:version => :draft2))
|
38
|
-
|
38
|
+
|
39
39
|
data['a'] = 'string'
|
40
40
|
assert(!JSON::Validator.validate(schema,data,:version => :draft2))
|
41
|
-
|
41
|
+
|
42
42
|
data['a'] = true
|
43
43
|
assert(!JSON::Validator.validate(schema,data,:version => :draft2))
|
44
|
-
|
45
|
-
|
44
|
+
|
45
|
+
|
46
46
|
# Test strings
|
47
47
|
schema["properties"]["a"]["type"] = "string"
|
48
48
|
data["a"] = 5
|
@@ -50,14 +50,14 @@ class JSONSchemaDraft2Test < Test::Unit::TestCase
|
|
50
50
|
|
51
51
|
data["a"] = 5.2
|
52
52
|
assert(!JSON::Validator.validate(schema,data,:version => :draft2))
|
53
|
-
|
53
|
+
|
54
54
|
data['a'] = 'string'
|
55
55
|
assert(JSON::Validator.validate(schema,data,:version => :draft2))
|
56
|
-
|
56
|
+
|
57
57
|
data['a'] = true
|
58
58
|
assert(!JSON::Validator.validate(schema,data,:version => :draft2))
|
59
|
-
|
60
|
-
|
59
|
+
|
60
|
+
|
61
61
|
# Test booleans
|
62
62
|
schema["properties"]["a"]["type"] = "boolean"
|
63
63
|
data["a"] = 5
|
@@ -65,17 +65,17 @@ class JSONSchemaDraft2Test < Test::Unit::TestCase
|
|
65
65
|
|
66
66
|
data["a"] = 5.2
|
67
67
|
assert(!JSON::Validator.validate(schema,data,:version => :draft2))
|
68
|
-
|
68
|
+
|
69
69
|
data['a'] = 'string'
|
70
70
|
assert(!JSON::Validator.validate(schema,data,:version => :draft2))
|
71
|
-
|
71
|
+
|
72
72
|
data['a'] = true
|
73
73
|
assert(JSON::Validator.validate(schema,data,:version => :draft2))
|
74
|
-
|
74
|
+
|
75
75
|
data['a'] = false
|
76
76
|
assert(JSON::Validator.validate(schema,data,:version => :draft2))
|
77
|
-
|
78
|
-
|
77
|
+
|
78
|
+
|
79
79
|
# Test object
|
80
80
|
schema["properties"]["a"]["type"] = "object"
|
81
81
|
data["a"] = {}
|
@@ -83,14 +83,14 @@ class JSONSchemaDraft2Test < Test::Unit::TestCase
|
|
83
83
|
|
84
84
|
data["a"] = 5.2
|
85
85
|
assert(!JSON::Validator.validate(schema,data,:version => :draft2))
|
86
|
-
|
86
|
+
|
87
87
|
data['a'] = 'string'
|
88
88
|
assert(!JSON::Validator.validate(schema,data,:version => :draft2))
|
89
|
-
|
89
|
+
|
90
90
|
data['a'] = true
|
91
91
|
assert(!JSON::Validator.validate(schema,data,:version => :draft2))
|
92
|
-
|
93
|
-
|
92
|
+
|
93
|
+
|
94
94
|
# Test array
|
95
95
|
schema["properties"]["a"]["type"] = "array"
|
96
96
|
data["a"] = []
|
@@ -98,14 +98,14 @@ class JSONSchemaDraft2Test < Test::Unit::TestCase
|
|
98
98
|
|
99
99
|
data["a"] = 5.2
|
100
100
|
assert(!JSON::Validator.validate(schema,data,:version => :draft2))
|
101
|
-
|
101
|
+
|
102
102
|
data['a'] = 'string'
|
103
103
|
assert(!JSON::Validator.validate(schema,data,:version => :draft2))
|
104
|
-
|
104
|
+
|
105
105
|
data['a'] = true
|
106
106
|
assert(!JSON::Validator.validate(schema,data,:version => :draft2))
|
107
|
-
|
108
|
-
|
107
|
+
|
108
|
+
|
109
109
|
# Test null
|
110
110
|
schema["properties"]["a"]["type"] = "null"
|
111
111
|
data["a"] = nil
|
@@ -113,14 +113,14 @@ class JSONSchemaDraft2Test < Test::Unit::TestCase
|
|
113
113
|
|
114
114
|
data["a"] = 5.2
|
115
115
|
assert(!JSON::Validator.validate(schema,data,:version => :draft2))
|
116
|
-
|
116
|
+
|
117
117
|
data['a'] = 'string'
|
118
118
|
assert(!JSON::Validator.validate(schema,data,:version => :draft2))
|
119
|
-
|
119
|
+
|
120
120
|
data['a'] = true
|
121
121
|
assert(!JSON::Validator.validate(schema,data,:version => :draft2))
|
122
|
-
|
123
|
-
|
122
|
+
|
123
|
+
|
124
124
|
# Test any
|
125
125
|
schema["properties"]["a"]["type"] = "any"
|
126
126
|
data["a"] = 5
|
@@ -128,43 +128,43 @@ class JSONSchemaDraft2Test < Test::Unit::TestCase
|
|
128
128
|
|
129
129
|
data["a"] = 5.2
|
130
130
|
assert(JSON::Validator.validate(schema,data,:version => :draft2))
|
131
|
-
|
131
|
+
|
132
132
|
data['a'] = 'string'
|
133
133
|
assert(JSON::Validator.validate(schema,data,:version => :draft2))
|
134
|
-
|
134
|
+
|
135
135
|
data['a'] = true
|
136
136
|
assert(JSON::Validator.validate(schema,data,:version => :draft2))
|
137
|
-
|
138
|
-
|
137
|
+
|
138
|
+
|
139
139
|
# Test a union type
|
140
140
|
schema["properties"]["a"]["type"] = ["integer","string"]
|
141
141
|
data["a"] = 5
|
142
142
|
assert(JSON::Validator.validate(schema,data,:version => :draft2))
|
143
|
-
|
143
|
+
|
144
144
|
data["a"] = 'boo'
|
145
145
|
assert(JSON::Validator.validate(schema,data,:version => :draft2))
|
146
|
-
|
146
|
+
|
147
147
|
data["a"] = false
|
148
148
|
assert(!JSON::Validator.validate(schema,data,:version => :draft2))
|
149
|
-
|
149
|
+
|
150
150
|
# Test a union type with schemas
|
151
151
|
schema["properties"]["a"]["type"] = [{ "type" => "string" }, {"type" => "object", "properties" => {"b" => {"type" => "integer"}}}]
|
152
|
-
|
152
|
+
|
153
153
|
data["a"] = "test"
|
154
154
|
assert(JSON::Validator.validate(schema,data,:version => :draft2))
|
155
|
-
|
155
|
+
|
156
156
|
data["a"] = 5
|
157
157
|
assert(!JSON::Validator.validate(schema,data,:version => :draft2))
|
158
|
-
|
158
|
+
|
159
159
|
data["a"] = {"b" => 5}
|
160
160
|
assert(JSON::Validator.validate(schema,data,:version => :draft2))
|
161
|
-
|
161
|
+
|
162
162
|
data["a"] = {"b" => "taco"}
|
163
163
|
assert(!JSON::Validator.validate(schema,data,:version => :draft2))
|
164
164
|
end
|
165
|
-
|
166
|
-
|
167
|
-
|
165
|
+
|
166
|
+
|
167
|
+
|
168
168
|
def test_optional
|
169
169
|
# Set up the default datatype
|
170
170
|
schema = {
|
@@ -173,24 +173,24 @@ class JSONSchemaDraft2Test < Test::Unit::TestCase
|
|
173
173
|
}
|
174
174
|
}
|
175
175
|
data = {}
|
176
|
-
|
176
|
+
|
177
177
|
assert(!JSON::Validator.validate(schema,data,:version => :draft2))
|
178
178
|
data['a'] = "Hello"
|
179
179
|
assert(JSON::Validator.validate(schema,data,:version => :draft2))
|
180
|
-
|
180
|
+
|
181
181
|
schema = {
|
182
182
|
"properties" => {
|
183
183
|
"a" => {"type" => "integer", "optional" => "true"}
|
184
184
|
}
|
185
185
|
}
|
186
|
-
|
186
|
+
|
187
187
|
data = {}
|
188
188
|
assert(JSON::Validator.validate(schema,data,:version => :draft2))
|
189
|
-
|
189
|
+
|
190
190
|
end
|
191
|
-
|
192
|
-
|
193
|
-
|
191
|
+
|
192
|
+
|
193
|
+
|
194
194
|
def test_minimum
|
195
195
|
# Set up the default datatype
|
196
196
|
schema = {
|
@@ -198,49 +198,49 @@ class JSONSchemaDraft2Test < Test::Unit::TestCase
|
|
198
198
|
"a" => {"minimum" => 5}
|
199
199
|
}
|
200
200
|
}
|
201
|
-
|
201
|
+
|
202
202
|
data = {
|
203
203
|
"a" => nil
|
204
204
|
}
|
205
|
-
|
206
|
-
|
205
|
+
|
206
|
+
|
207
207
|
# Test an integer
|
208
208
|
data["a"] = 5
|
209
209
|
assert(JSON::Validator.validate(schema,data,:version => :draft2))
|
210
|
-
|
210
|
+
|
211
211
|
data["a"] = 4
|
212
212
|
assert(!JSON::Validator.validate(schema,data,:version => :draft2))
|
213
|
-
|
213
|
+
|
214
214
|
# Test a float
|
215
215
|
data["a"] = 5.0
|
216
216
|
assert(JSON::Validator.validate(schema,data,:version => :draft2))
|
217
|
-
|
217
|
+
|
218
218
|
data["a"] = 4.9
|
219
219
|
assert(!JSON::Validator.validate(schema,data,:version => :draft2))
|
220
|
-
|
220
|
+
|
221
221
|
# Test a non-number
|
222
222
|
data["a"] = "a string"
|
223
223
|
assert(JSON::Validator.validate(schema,data,:version => :draft2))
|
224
|
-
|
224
|
+
|
225
225
|
# Test exclusiveMinimum
|
226
226
|
schema["properties"]["a"]["minimumCanEqual"] = false
|
227
|
-
|
227
|
+
|
228
228
|
data["a"] = 6
|
229
229
|
assert(JSON::Validator.validate(schema,data,:version => :draft2))
|
230
|
-
|
230
|
+
|
231
231
|
data["a"] = 5
|
232
232
|
assert(!JSON::Validator.validate(schema,data,:version => :draft2))
|
233
|
-
|
233
|
+
|
234
234
|
# Test with float
|
235
235
|
data["a"] = 5.00000001
|
236
236
|
assert(JSON::Validator.validate(schema,data,:version => :draft2))
|
237
|
-
|
237
|
+
|
238
238
|
data["a"] = 5.0
|
239
239
|
assert(!JSON::Validator.validate(schema,data,:version => :draft2))
|
240
240
|
end
|
241
|
-
|
242
|
-
|
243
|
-
|
241
|
+
|
242
|
+
|
243
|
+
|
244
244
|
def test_maximum
|
245
245
|
# Set up the default datatype
|
246
246
|
schema = {
|
@@ -248,48 +248,48 @@ class JSONSchemaDraft2Test < Test::Unit::TestCase
|
|
248
248
|
"a" => {"maximum" => 5}
|
249
249
|
}
|
250
250
|
}
|
251
|
-
|
251
|
+
|
252
252
|
data = {
|
253
253
|
"a" => nil
|
254
254
|
}
|
255
|
-
|
256
|
-
|
255
|
+
|
256
|
+
|
257
257
|
# Test an integer
|
258
258
|
data["a"] = 5
|
259
259
|
assert(JSON::Validator.validate(schema,data,:version => :draft2))
|
260
|
-
|
260
|
+
|
261
261
|
data["a"] = 6
|
262
262
|
assert(!JSON::Validator.validate(schema,data,:version => :draft2))
|
263
|
-
|
263
|
+
|
264
264
|
# Test a float
|
265
265
|
data["a"] = 5.0
|
266
266
|
assert(JSON::Validator.validate(schema,data,:version => :draft2))
|
267
|
-
|
267
|
+
|
268
268
|
data["a"] = 5.1
|
269
269
|
assert(!JSON::Validator.validate(schema,data,:version => :draft2))
|
270
|
-
|
270
|
+
|
271
271
|
# Test a non-number
|
272
272
|
data["a"] = "a string"
|
273
273
|
assert(JSON::Validator.validate(schema,data,:version => :draft2))
|
274
|
-
|
274
|
+
|
275
275
|
# Test exclusiveMinimum
|
276
276
|
schema["properties"]["a"]["maximumCanEqual"] = false
|
277
|
-
|
277
|
+
|
278
278
|
data["a"] = 4
|
279
279
|
assert(JSON::Validator.validate(schema,data,:version => :draft2))
|
280
|
-
|
280
|
+
|
281
281
|
data["a"] = 5
|
282
282
|
assert(!JSON::Validator.validate(schema,data,:version => :draft2))
|
283
|
-
|
283
|
+
|
284
284
|
# Test with float
|
285
285
|
data["a"] = 4.9999999
|
286
286
|
assert(JSON::Validator.validate(schema,data,:version => :draft2))
|
287
|
-
|
287
|
+
|
288
288
|
data["a"] = 5.0
|
289
289
|
assert(!JSON::Validator.validate(schema,data,:version => :draft2))
|
290
290
|
end
|
291
|
-
|
292
|
-
|
291
|
+
|
292
|
+
|
293
293
|
def test_min_items
|
294
294
|
# Set up the default datatype
|
295
295
|
schema = {
|
@@ -297,25 +297,25 @@ class JSONSchemaDraft2Test < Test::Unit::TestCase
|
|
297
297
|
"a" => {"minItems" => 1}
|
298
298
|
}
|
299
299
|
}
|
300
|
-
|
300
|
+
|
301
301
|
data = {
|
302
302
|
"a" => nil
|
303
303
|
}
|
304
|
-
|
304
|
+
|
305
305
|
# Test with an array
|
306
306
|
data["a"] = ["boo"]
|
307
307
|
assert(JSON::Validator.validate(schema,data,:version => :draft2))
|
308
|
-
|
308
|
+
|
309
309
|
data["a"] = []
|
310
310
|
assert(!JSON::Validator.validate(schema,data,:version => :draft2))
|
311
|
-
|
311
|
+
|
312
312
|
# Test with a non-array
|
313
313
|
data["a"] = "boo"
|
314
314
|
assert(JSON::Validator.validate(schema,data,:version => :draft2))
|
315
315
|
end
|
316
|
-
|
317
|
-
|
318
|
-
|
316
|
+
|
317
|
+
|
318
|
+
|
319
319
|
def test_max_items
|
320
320
|
# Set up the default datatype
|
321
321
|
schema = {
|
@@ -323,25 +323,25 @@ class JSONSchemaDraft2Test < Test::Unit::TestCase
|
|
323
323
|
"a" => {"maxItems" => 1}
|
324
324
|
}
|
325
325
|
}
|
326
|
-
|
326
|
+
|
327
327
|
data = {
|
328
328
|
"a" => nil
|
329
329
|
}
|
330
|
-
|
330
|
+
|
331
331
|
# Test with an array
|
332
332
|
data["a"] = ["boo"]
|
333
333
|
assert(JSON::Validator.validate(schema,data,:version => :draft2))
|
334
|
-
|
334
|
+
|
335
335
|
data["a"] = ["boo","taco"]
|
336
336
|
assert(!JSON::Validator.validate(schema,data,:version => :draft2))
|
337
|
-
|
337
|
+
|
338
338
|
# Test with a non-array
|
339
339
|
data["a"] = "boo"
|
340
340
|
assert(JSON::Validator.validate(schema,data,:version => :draft2))
|
341
341
|
end
|
342
|
-
|
343
|
-
|
344
|
-
|
342
|
+
|
343
|
+
|
344
|
+
|
345
345
|
def test_unique_items
|
346
346
|
# Set up the default datatype
|
347
347
|
schema = {
|
@@ -349,70 +349,70 @@ class JSONSchemaDraft2Test < Test::Unit::TestCase
|
|
349
349
|
"a" => {"uniqueItems" => true}
|
350
350
|
}
|
351
351
|
}
|
352
|
-
|
352
|
+
|
353
353
|
data = {
|
354
354
|
"a" => nil
|
355
355
|
}
|
356
|
-
|
356
|
+
|
357
357
|
# Test with nulls
|
358
358
|
data["a"] = [nil,5]
|
359
359
|
assert(JSON::Validator.validate(schema,data,:version => :draft2))
|
360
|
-
|
360
|
+
|
361
361
|
data["a"] = [nil,nil]
|
362
362
|
assert(!JSON::Validator.validate(schema,data,:version => :draft2))
|
363
|
-
|
363
|
+
|
364
364
|
# Test with booleans
|
365
365
|
data["a"] = [true,4]
|
366
366
|
assert(JSON::Validator.validate(schema,data,:version => :draft2))
|
367
|
-
|
367
|
+
|
368
368
|
data["a"] = [true,false]
|
369
369
|
assert(JSON::Validator.validate(schema,data,:version => :draft2))
|
370
|
-
|
370
|
+
|
371
371
|
data["a"] = [true,true]
|
372
372
|
assert(!JSON::Validator.validate(schema,data,:version => :draft2))
|
373
|
-
|
373
|
+
|
374
374
|
# Test with numbers
|
375
375
|
data["a"] = [4,true]
|
376
376
|
assert(JSON::Validator.validate(schema,data,:version => :draft2))
|
377
|
-
|
377
|
+
|
378
378
|
data["a"] = [4,4.1]
|
379
379
|
assert(JSON::Validator.validate(schema,data,:version => :draft2))
|
380
|
-
|
380
|
+
|
381
381
|
data["a"] = [4,4]
|
382
382
|
assert(!JSON::Validator.validate(schema,data,:version => :draft2))
|
383
|
-
|
383
|
+
|
384
384
|
# Test with strings
|
385
385
|
data["a"] = ['a',true]
|
386
386
|
assert(JSON::Validator.validate(schema,data,:version => :draft2))
|
387
|
-
|
387
|
+
|
388
388
|
data["a"] = ['a','ab']
|
389
389
|
assert(JSON::Validator.validate(schema,data,:version => :draft2))
|
390
|
-
|
390
|
+
|
391
391
|
data["a"] = ['a','a']
|
392
392
|
assert(!JSON::Validator.validate(schema,data,:version => :draft2))
|
393
|
-
|
393
|
+
|
394
394
|
# Test with arrays
|
395
395
|
data["a"] = [[1],true]
|
396
396
|
assert(JSON::Validator.validate(schema,data,:version => :draft2))
|
397
|
-
|
397
|
+
|
398
398
|
data["a"] = [[1,2],[1,3]]
|
399
399
|
assert(JSON::Validator.validate(schema,data,:version => :draft2))
|
400
|
-
|
400
|
+
|
401
401
|
data["a"] = [[1,2,3],[1,2,3]]
|
402
402
|
assert(!JSON::Validator.validate(schema,data,:version => :draft2))
|
403
|
-
|
403
|
+
|
404
404
|
# Test with objects
|
405
405
|
data["a"] = [{"a" => 1},true]
|
406
406
|
assert(JSON::Validator.validate(schema,data,:version => :draft2))
|
407
|
-
|
407
|
+
|
408
408
|
data["a"] = [{"a" => 1},{"a" => 2}]
|
409
409
|
assert(JSON::Validator.validate(schema,data,:version => :draft2))
|
410
|
-
|
410
|
+
|
411
411
|
data["a"] = [{"a" => 1, "b" => 2}, {"a" => 1, "b" => 2}]
|
412
412
|
assert(!JSON::Validator.validate(schema,data,:version => :draft2))
|
413
413
|
end
|
414
|
-
|
415
|
-
|
414
|
+
|
415
|
+
|
416
416
|
def test_pattern
|
417
417
|
# Set up the default datatype
|
418
418
|
schema = {
|
@@ -420,24 +420,24 @@ class JSONSchemaDraft2Test < Test::Unit::TestCase
|
|
420
420
|
"a" => {"pattern" => "\\d+ taco"}
|
421
421
|
}
|
422
422
|
}
|
423
|
-
|
423
|
+
|
424
424
|
data = {
|
425
425
|
"a" => nil
|
426
426
|
}
|
427
|
-
|
427
|
+
|
428
428
|
# Test strings
|
429
429
|
data["a"] = "156 taco bell"
|
430
430
|
assert(JSON::Validator.validate(schema,data,:version => :draft2))
|
431
|
-
|
431
|
+
|
432
432
|
# Test a non-string
|
433
433
|
data["a"] = 5
|
434
434
|
assert(JSON::Validator.validate(schema,data,:version => :draft2))
|
435
|
-
|
435
|
+
|
436
436
|
data["a"] = "taco"
|
437
437
|
assert(!JSON::Validator.validate(schema,data,:version => :draft2))
|
438
438
|
end
|
439
|
-
|
440
|
-
|
439
|
+
|
440
|
+
|
441
441
|
def test_min_length
|
442
442
|
# Set up the default datatype
|
443
443
|
schema = {
|
@@ -445,24 +445,24 @@ class JSONSchemaDraft2Test < Test::Unit::TestCase
|
|
445
445
|
"a" => {"minLength" => 1}
|
446
446
|
}
|
447
447
|
}
|
448
|
-
|
448
|
+
|
449
449
|
data = {
|
450
450
|
"a" => nil
|
451
451
|
}
|
452
|
-
|
452
|
+
|
453
453
|
# Try out strings
|
454
454
|
data["a"] = "t"
|
455
455
|
assert(JSON::Validator.validate(schema,data,:version => :draft2))
|
456
|
-
|
456
|
+
|
457
457
|
data["a"] = ""
|
458
458
|
assert(!JSON::Validator.validate(schema,data,:version => :draft2))
|
459
|
-
|
459
|
+
|
460
460
|
# Try out non-string
|
461
461
|
data["a"] = 5
|
462
462
|
assert(JSON::Validator.validate(schema,data,:version => :draft2))
|
463
463
|
end
|
464
|
-
|
465
|
-
|
464
|
+
|
465
|
+
|
466
466
|
def test_max_length
|
467
467
|
# Set up the default datatype
|
468
468
|
schema = {
|
@@ -470,24 +470,24 @@ class JSONSchemaDraft2Test < Test::Unit::TestCase
|
|
470
470
|
"a" => {"maxLength" => 1}
|
471
471
|
}
|
472
472
|
}
|
473
|
-
|
473
|
+
|
474
474
|
data = {
|
475
475
|
"a" => nil
|
476
476
|
}
|
477
|
-
|
477
|
+
|
478
478
|
# Try out strings
|
479
479
|
data["a"] = "t"
|
480
480
|
assert(JSON::Validator.validate(schema,data,:version => :draft2))
|
481
|
-
|
481
|
+
|
482
482
|
data["a"] = "tt"
|
483
483
|
assert(!JSON::Validator.validate(schema,data,:version => :draft2))
|
484
|
-
|
484
|
+
|
485
485
|
# Try out non-string
|
486
486
|
data["a"] = 5
|
487
487
|
assert(JSON::Validator.validate(schema,data,:version => :draft2))
|
488
488
|
end
|
489
|
-
|
490
|
-
|
489
|
+
|
490
|
+
|
491
491
|
def test_enum
|
492
492
|
# Set up the default datatype
|
493
493
|
schema = {
|
@@ -495,34 +495,34 @@ class JSONSchemaDraft2Test < Test::Unit::TestCase
|
|
495
495
|
"a" => {"enum" => [1,'boo',[1,2,3],{"a" => "b"}], "optional" => true}
|
496
496
|
}
|
497
497
|
}
|
498
|
-
|
498
|
+
|
499
499
|
data = {
|
500
500
|
"a" => nil
|
501
501
|
}
|
502
|
-
|
502
|
+
|
503
503
|
# Make sure all of the above are valid...
|
504
504
|
data["a"] = 1
|
505
505
|
assert(JSON::Validator.validate(schema,data,:version => :draft2))
|
506
|
-
|
506
|
+
|
507
507
|
data["a"] = 'boo'
|
508
508
|
assert(JSON::Validator.validate(schema,data,:version => :draft2))
|
509
|
-
|
509
|
+
|
510
510
|
data["a"] = [1,2,3]
|
511
511
|
assert(JSON::Validator.validate(schema,data,:version => :draft2))
|
512
|
-
|
512
|
+
|
513
513
|
data["a"] = {"a" => "b"}
|
514
514
|
assert(JSON::Validator.validate(schema,data,:version => :draft2))
|
515
|
-
|
515
|
+
|
516
516
|
# Test something that doesn't exist
|
517
517
|
data["a"] = 'taco'
|
518
518
|
assert(!JSON::Validator.validate(schema,data,:version => :draft2))
|
519
|
-
|
519
|
+
|
520
520
|
# Try it without the key
|
521
521
|
data = {}
|
522
522
|
assert(JSON::Validator.validate(schema,data,:version => :draft2))
|
523
523
|
end
|
524
|
-
|
525
|
-
|
524
|
+
|
525
|
+
|
526
526
|
def test_divisible_by
|
527
527
|
# Set up the default datatype
|
528
528
|
schema = {
|
@@ -530,32 +530,32 @@ class JSONSchemaDraft2Test < Test::Unit::TestCase
|
|
530
530
|
"a" => {"divisibleBy" => 1.1}
|
531
531
|
}
|
532
532
|
}
|
533
|
-
|
533
|
+
|
534
534
|
data = {
|
535
535
|
"a" => nil
|
536
536
|
}
|
537
|
-
|
537
|
+
|
538
538
|
data["a"] = 3.3
|
539
539
|
assert(JSON::Validator.validate(schema,data,:version => :draft2))
|
540
|
-
|
540
|
+
|
541
541
|
data["a"] = 3.4
|
542
542
|
assert(!JSON::Validator.validate(schema,data,:version => :draft2))
|
543
|
-
|
543
|
+
|
544
544
|
schema["properties"]["a"]["divisibleBy"] = 2.0
|
545
|
-
|
545
|
+
|
546
546
|
data["a"] = 4.0
|
547
547
|
assert(JSON::Validator.validate(schema,data,:version => :draft2))
|
548
|
-
|
548
|
+
|
549
549
|
data["a"] = 'boo'
|
550
550
|
assert(JSON::Validator.validate(schema,data,:version => :draft2))
|
551
|
-
|
551
|
+
|
552
552
|
data["a"] = 5
|
553
553
|
schema["properties"]["a"]["divisibleBy"] = 0
|
554
554
|
assert(!JSON::Validator.validate(schema,data,:version => :draft2))
|
555
555
|
end
|
556
|
-
|
557
|
-
|
558
|
-
|
556
|
+
|
557
|
+
|
558
|
+
|
559
559
|
def test_disallow
|
560
560
|
# Set up the default datatype
|
561
561
|
schema = {
|
@@ -563,33 +563,33 @@ class JSONSchemaDraft2Test < Test::Unit::TestCase
|
|
563
563
|
"a" => {"disallow" => "integer"}
|
564
564
|
}
|
565
565
|
}
|
566
|
-
|
566
|
+
|
567
567
|
data = {
|
568
568
|
"a" => nil
|
569
569
|
}
|
570
|
-
|
571
|
-
|
570
|
+
|
571
|
+
|
572
572
|
data["a"] = 'string'
|
573
573
|
assert(JSON::Validator.validate(schema,data,:version => :draft2))
|
574
|
-
|
574
|
+
|
575
575
|
data["a"] = 5
|
576
576
|
assert(!JSON::Validator.validate(schema,data,:version => :draft2))
|
577
|
-
|
578
|
-
|
577
|
+
|
578
|
+
|
579
579
|
schema["properties"]["a"]["disallow"] = ["integer","string"]
|
580
580
|
data["a"] = 'string'
|
581
581
|
assert(!JSON::Validator.validate(schema,data,:version => :draft2))
|
582
|
-
|
582
|
+
|
583
583
|
data["a"] = 5
|
584
584
|
assert(!JSON::Validator.validate(schema,data,:version => :draft2))
|
585
|
-
|
585
|
+
|
586
586
|
data["a"] = false
|
587
587
|
assert(JSON::Validator.validate(schema,data,:version => :draft2))
|
588
588
|
|
589
589
|
end
|
590
|
-
|
591
|
-
|
592
|
-
|
590
|
+
|
591
|
+
|
592
|
+
|
593
593
|
def test_additional_properties
|
594
594
|
# Test no additional properties allowed
|
595
595
|
schema = {
|
@@ -598,15 +598,15 @@ class JSONSchemaDraft2Test < Test::Unit::TestCase
|
|
598
598
|
},
|
599
599
|
"additionalProperties" => false
|
600
600
|
}
|
601
|
-
|
601
|
+
|
602
602
|
data = {
|
603
603
|
"a" => 10
|
604
604
|
}
|
605
|
-
|
605
|
+
|
606
606
|
assert(JSON::Validator.validate(schema,data,:version => :draft2))
|
607
607
|
data["b"] = 5
|
608
608
|
assert(!JSON::Validator.validate(schema,data,:version => :draft2))
|
609
|
-
|
609
|
+
|
610
610
|
# Test additional properties match a schema
|
611
611
|
schema["additionalProperties"] = { "type" => "string" }
|
612
612
|
data["b"] = "taco"
|
@@ -614,41 +614,41 @@ class JSONSchemaDraft2Test < Test::Unit::TestCase
|
|
614
614
|
data["b"] = 5
|
615
615
|
assert(!JSON::Validator.validate(schema,data,:version => :draft2))
|
616
616
|
end
|
617
|
-
|
618
|
-
|
617
|
+
|
618
|
+
|
619
619
|
def test_items
|
620
620
|
schema = {
|
621
621
|
"items" => { "type" => "integer" }
|
622
622
|
}
|
623
|
-
|
623
|
+
|
624
624
|
data = [1,2,4]
|
625
625
|
assert(JSON::Validator.validate(schema,data,:version => :draft2))
|
626
626
|
data = [1,2,"string"]
|
627
627
|
assert(!JSON::Validator.validate(schema,data,:version => :draft2))
|
628
|
-
|
628
|
+
|
629
629
|
schema = {
|
630
630
|
"items" => [
|
631
631
|
{"type" => "integer"},
|
632
632
|
{"type" => "string"}
|
633
633
|
]
|
634
634
|
}
|
635
|
-
|
635
|
+
|
636
636
|
data = [1,"string"]
|
637
637
|
assert(JSON::Validator.validate(schema,data,:version => :draft2))
|
638
638
|
data = [1,"string",3]
|
639
639
|
assert(JSON::Validator.validate(schema,data,:version => :draft2))
|
640
640
|
data = ["string",1]
|
641
641
|
assert(!JSON::Validator.validate(schema,data,:version => :draft2))
|
642
|
-
|
642
|
+
|
643
643
|
end
|
644
|
-
|
645
|
-
|
644
|
+
|
645
|
+
|
646
646
|
def test_format_ipv4
|
647
647
|
schema = {
|
648
648
|
"type" => "object",
|
649
649
|
"properties" => { "a" => {"type" => "string", "format" => "ip-address"}}
|
650
650
|
}
|
651
|
-
|
651
|
+
|
652
652
|
data = {"a" => "1.1.1.1"}
|
653
653
|
assert(JSON::Validator.validate(schema,data,:version => :draft2))
|
654
654
|
data = {"a" => "1.1.1"}
|
@@ -663,14 +663,14 @@ class JSONSchemaDraft2Test < Test::Unit::TestCase
|
|
663
663
|
assert(!JSON::Validator.validate(schema,data,:version => :draft2))
|
664
664
|
data = {"a" => "b1.1.1.1"}
|
665
665
|
end
|
666
|
-
|
667
|
-
|
666
|
+
|
667
|
+
|
668
668
|
def test_format_ipv6
|
669
669
|
schema = {
|
670
670
|
"type" => "object",
|
671
671
|
"properties" => { "a" => {"type" => "string", "format" => "ipv6"}}
|
672
672
|
}
|
673
|
-
|
673
|
+
|
674
674
|
data = {"a" => "1111:2222:8888:9999:aaaa:cccc:eeee:ffff"}
|
675
675
|
assert(JSON::Validator.validate(schema,data,:version => :draft2))
|
676
676
|
data = {"a" => "1111:0:8888:0:0:0:eeee:ffff"}
|
@@ -686,13 +686,13 @@ class JSONSchemaDraft2Test < Test::Unit::TestCase
|
|
686
686
|
data = {"a" => "1111:2222:8888:9999:aaaa:cccc:eeee:ffff:bbbb"}
|
687
687
|
assert(!JSON::Validator.validate(schema,data,:version => :draft2))
|
688
688
|
end
|
689
|
-
|
689
|
+
|
690
690
|
def test_format_time
|
691
691
|
schema = {
|
692
692
|
"type" => "object",
|
693
693
|
"properties" => { "a" => {"type" => "string", "format" => "time"}}
|
694
694
|
}
|
695
|
-
|
695
|
+
|
696
696
|
data = {"a" => "12:00:00"}
|
697
697
|
assert(JSON::Validator.validate(schema,data,:version => :draft2))
|
698
698
|
data = {"a" => "12:00"}
|
@@ -710,14 +710,14 @@ class JSONSchemaDraft2Test < Test::Unit::TestCase
|
|
710
710
|
data = {"a" => "12:00:00b"}
|
711
711
|
assert(!JSON::Validator.validate(schema,data,:version => :draft2))
|
712
712
|
end
|
713
|
-
|
714
|
-
|
713
|
+
|
714
|
+
|
715
715
|
def test_format_date
|
716
716
|
schema = {
|
717
717
|
"type" => "object",
|
718
718
|
"properties" => { "a" => {"type" => "string", "format" => "date"}}
|
719
719
|
}
|
720
|
-
|
720
|
+
|
721
721
|
data = {"a" => "2010-01-01"}
|
722
722
|
assert(JSON::Validator.validate(schema,data,:version => :draft2))
|
723
723
|
data = {"a" => "2010-01-32"}
|
@@ -731,13 +731,13 @@ class JSONSchemaDraft2Test < Test::Unit::TestCase
|
|
731
731
|
data = {"a" => "2010-01-01n"}
|
732
732
|
assert(!JSON::Validator.validate(schema,data,:version => :draft2))
|
733
733
|
end
|
734
|
-
|
734
|
+
|
735
735
|
def test_format_datetime
|
736
736
|
schema = {
|
737
737
|
"type" => "object",
|
738
738
|
"properties" => { "a" => {"type" => "string", "format" => "date-time"}}
|
739
739
|
}
|
740
|
-
|
740
|
+
|
741
741
|
data = {"a" => "2010-01-01T12:00:00Z"}
|
742
742
|
assert(JSON::Validator.validate(schema,data,:version => :draft2))
|
743
743
|
data = {"a" => "2010-01-32T12:00:00Z"}
|
@@ -750,19 +750,17 @@ class JSONSchemaDraft2Test < Test::Unit::TestCase
|
|
750
750
|
assert(!JSON::Validator.validate(schema,data,:version => :draft2))
|
751
751
|
data = {"a" => "2010-01-01T12:00:60Z"}
|
752
752
|
assert(!JSON::Validator.validate(schema,data,:version => :draft2))
|
753
|
-
data = {"a" => "2010-01-01T12:00:00"}
|
754
|
-
assert(!JSON::Validator.validate(schema,data,:version => :draft2))
|
755
753
|
data = {"a" => "2010-01-01T12:00:00z"}
|
756
754
|
assert(!JSON::Validator.validate(schema,data,:version => :draft2))
|
757
755
|
data = {"a" => "2010-01-0112:00:00Z"}
|
758
756
|
assert(!JSON::Validator.validate(schema,data,:version => :draft2))
|
759
757
|
end
|
760
|
-
|
761
|
-
|
758
|
+
|
759
|
+
|
762
760
|
def test_format_union
|
763
761
|
data1 = {"a" => "boo"}
|
764
762
|
data2 = {"a" => nil}
|
765
|
-
|
763
|
+
|
766
764
|
schema = {
|
767
765
|
"type" => "object",
|
768
766
|
"properties" => { "a" => {"type" => ["string","null"], "format" => "ip-address"}}
|
@@ -770,6 +768,6 @@ class JSONSchemaDraft2Test < Test::Unit::TestCase
|
|
770
768
|
assert(!JSON::Validator.validate(schema,data1,:version => :draft2))
|
771
769
|
assert(JSON::Validator.validate(schema,data2,:version => :draft2))
|
772
770
|
end
|
773
|
-
|
771
|
+
|
774
772
|
end
|
775
773
|
|