json-schema 2.2.5 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +8 -8
  2. data/README.textile +1 -1
  3. data/lib/json-schema.rb +1 -0
  4. data/lib/json-schema/attribute.rb +43 -0
  5. data/lib/json-schema/attributes/additionalitems.rb +3 -1
  6. data/lib/json-schema/attributes/additionalproperties.rb +1 -0
  7. data/lib/json-schema/attributes/allof.rb +6 -4
  8. data/lib/json-schema/attributes/anyof.rb +7 -5
  9. data/lib/json-schema/attributes/dependencies.rb +3 -1
  10. data/lib/json-schema/attributes/dependencies_v4.rb +3 -1
  11. data/lib/json-schema/attributes/disallow.rb +3 -1
  12. data/lib/json-schema/attributes/divisibleby.rb +3 -1
  13. data/lib/json-schema/attributes/enum.rb +3 -1
  14. data/lib/json-schema/attributes/extends.rb +1 -0
  15. data/lib/json-schema/attributes/format.rb +6 -112
  16. data/lib/json-schema/attributes/formats/custom.rb +22 -0
  17. data/lib/json-schema/attributes/formats/date.rb +25 -0
  18. data/lib/json-schema/attributes/formats/date_time.rb +35 -0
  19. data/lib/json-schema/attributes/formats/ip4.rb +22 -0
  20. data/lib/json-schema/attributes/formats/ip6.rb +30 -0
  21. data/lib/json-schema/attributes/formats/time.rb +22 -0
  22. data/lib/json-schema/attributes/formats/uri.rb +18 -0
  23. data/lib/json-schema/attributes/items.rb +3 -1
  24. data/lib/json-schema/attributes/maxdecimal.rb +3 -1
  25. data/lib/json-schema/attributes/maximum.rb +3 -1
  26. data/lib/json-schema/attributes/maximum_inclusive.rb +2 -0
  27. data/lib/json-schema/attributes/maxitems.rb +2 -0
  28. data/lib/json-schema/attributes/maxlength.rb +3 -1
  29. data/lib/json-schema/attributes/maxproperties.rb +3 -1
  30. data/lib/json-schema/attributes/minimum.rb +3 -1
  31. data/lib/json-schema/attributes/minimum_inclusive.rb +3 -1
  32. data/lib/json-schema/attributes/minitems.rb +4 -2
  33. data/lib/json-schema/attributes/minlength.rb +3 -1
  34. data/lib/json-schema/attributes/minproperties.rb +3 -1
  35. data/lib/json-schema/attributes/multipleof.rb +3 -1
  36. data/lib/json-schema/attributes/not.rb +3 -1
  37. data/lib/json-schema/attributes/oneof.rb +2 -0
  38. data/lib/json-schema/attributes/pattern.rb +3 -1
  39. data/lib/json-schema/attributes/patternproperties.rb +3 -1
  40. data/lib/json-schema/attributes/properties.rb +4 -2
  41. data/lib/json-schema/attributes/properties_optional.rb +3 -1
  42. data/lib/json-schema/attributes/properties_v4.rb +2 -0
  43. data/lib/json-schema/attributes/ref.rb +3 -0
  44. data/lib/json-schema/attributes/required.rb +2 -0
  45. data/lib/json-schema/attributes/type.rb +6 -20
  46. data/lib/json-schema/attributes/type_v4.rb +3 -21
  47. data/lib/json-schema/attributes/uniqueitems.rb +3 -1
  48. data/lib/json-schema/errors/custom_format_error.rb +6 -0
  49. data/lib/json-schema/errors/json_parse_error.rb +6 -0
  50. data/lib/json-schema/errors/schema_error.rb +6 -0
  51. data/lib/json-schema/errors/validation_error.rb +46 -0
  52. data/lib/json-schema/schema.rb +1 -5
  53. data/lib/json-schema/schema/validator.rb +31 -0
  54. data/lib/json-schema/validator.rb +61 -126
  55. data/lib/json-schema/validators/draft1.rb +14 -1
  56. data/lib/json-schema/validators/draft2.rb +14 -1
  57. data/lib/json-schema/validators/draft3.rb +14 -2
  58. data/lib/json-schema/validators/draft4.rb +12 -1
  59. data/test/test_all_of_ref_schema.rb +29 -2
  60. data/test/test_any_of_ref_schema.rb +26 -0
  61. data/test/test_bad_schema_ref.rb +2 -2
  62. data/test/test_common_test_suite.rb +53 -0
  63. data/test/test_custom_format.rb +117 -0
  64. data/test/test_jsonschema_draft1.rb +12 -0
  65. data/test/test_jsonschema_draft2.rb +12 -0
  66. data/test/test_jsonschema_draft3.rb +31 -0
  67. data/test/test_jsonschema_draft4.rb +14 -48
  68. data/test/test_minitems.rb +18 -0
  69. metadata +21 -4
  70. data/test/test_suite.rb +0 -71
@@ -0,0 +1,18 @@
1
+ require 'test/unit'
2
+ require File.dirname(__FILE__) + '/../lib/json-schema'
3
+
4
+ class MinItemsTest < Test::Unit::TestCase
5
+ def test_minitems_nils
6
+ schema = {
7
+ "type" => "array",
8
+ "minItems" => 1,
9
+ "items" => { "type" => "object" }
10
+ }
11
+ data = [nil]
12
+
13
+ errors = JSON::Validator.fully_validate(schema, [nil])
14
+ assert_equal(errors.length, 1)
15
+ assert(errors[0] !~ /minimum/)
16
+ assert(errors[0] =~ /NilClass/)
17
+ end
18
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json-schema
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.5
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kenny Hoxworth
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-05 00:00:00.000000000 Z
11
+ date: 2014-10-26 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: hoxworth@gmail.com
@@ -18,6 +18,7 @@ extra_rdoc_files:
18
18
  - README.textile
19
19
  - LICENSE.md
20
20
  files:
21
+ - lib/json-schema/attribute.rb
21
22
  - lib/json-schema/attributes/additionalitems.rb
22
23
  - lib/json-schema/attributes/additionalproperties.rb
23
24
  - lib/json-schema/attributes/allof.rb
@@ -29,6 +30,13 @@ files:
29
30
  - lib/json-schema/attributes/enum.rb
30
31
  - lib/json-schema/attributes/extends.rb
31
32
  - lib/json-schema/attributes/format.rb
33
+ - lib/json-schema/attributes/formats/custom.rb
34
+ - lib/json-schema/attributes/formats/date.rb
35
+ - lib/json-schema/attributes/formats/date_time.rb
36
+ - lib/json-schema/attributes/formats/ip4.rb
37
+ - lib/json-schema/attributes/formats/ip6.rb
38
+ - lib/json-schema/attributes/formats/time.rb
39
+ - lib/json-schema/attributes/formats/uri.rb
32
40
  - lib/json-schema/attributes/items.rb
33
41
  - lib/json-schema/attributes/maxdecimal.rb
34
42
  - lib/json-schema/attributes/maximum.rb
@@ -54,6 +62,11 @@ files:
54
62
  - lib/json-schema/attributes/type.rb
55
63
  - lib/json-schema/attributes/type_v4.rb
56
64
  - lib/json-schema/attributes/uniqueitems.rb
65
+ - lib/json-schema/errors/custom_format_error.rb
66
+ - lib/json-schema/errors/json_parse_error.rb
67
+ - lib/json-schema/errors/schema_error.rb
68
+ - lib/json-schema/errors/validation_error.rb
69
+ - lib/json-schema/schema/validator.rb
57
70
  - lib/json-schema/schema.rb
58
71
  - lib/json-schema/uri/file.rb
59
72
  - lib/json-schema/uri/uuid.rb
@@ -74,6 +87,8 @@ files:
74
87
  - test/test_all_of_ref_schema.rb
75
88
  - test/test_any_of_ref_schema.rb
76
89
  - test/test_bad_schema_ref.rb
90
+ - test/test_common_test_suite.rb
91
+ - test/test_custom_format.rb
77
92
  - test/test_extended_schema.rb
78
93
  - test/test_extends_and_additionalProperties.rb
79
94
  - test/test_files_v3.rb
@@ -84,11 +99,11 @@ files:
84
99
  - test/test_jsonschema_draft3.rb
85
100
  - test/test_jsonschema_draft4.rb
86
101
  - test/test_list_option.rb
102
+ - test/test_minitems.rb
87
103
  - test/test_one_of.rb
88
104
  - test/test_ruby_schema.rb
89
105
  - test/test_schema_type_attribute.rb
90
106
  - test/test_schema_validation.rb
91
- - test/test_suite.rb
92
107
  - test/data/all_of_ref_data.json
93
108
  - test/data/any_of_ref_data.json
94
109
  - test/data/bad_data_1.json
@@ -140,6 +155,8 @@ test_files:
140
155
  - test/test_all_of_ref_schema.rb
141
156
  - test/test_any_of_ref_schema.rb
142
157
  - test/test_bad_schema_ref.rb
158
+ - test/test_common_test_suite.rb
159
+ - test/test_custom_format.rb
143
160
  - test/test_extended_schema.rb
144
161
  - test/test_extends_and_additionalProperties.rb
145
162
  - test/test_files_v3.rb
@@ -150,11 +167,11 @@ test_files:
150
167
  - test/test_jsonschema_draft3.rb
151
168
  - test/test_jsonschema_draft4.rb
152
169
  - test/test_list_option.rb
170
+ - test/test_minitems.rb
153
171
  - test/test_one_of.rb
154
172
  - test/test_ruby_schema.rb
155
173
  - test/test_schema_type_attribute.rb
156
174
  - test/test_schema_validation.rb
157
- - test/test_suite.rb
158
175
  - test/data/all_of_ref_data.json
159
176
  - test/data/any_of_ref_data.json
160
177
  - test/data/bad_data_1.json
data/test/test_suite.rb DELETED
@@ -1,71 +0,0 @@
1
- require 'test/unit'
2
- require File.dirname(__FILE__) + '/../lib/json-schema'
3
-
4
- class SuiteTest < Test::Unit::TestCase
5
- def test_draft_4
6
- print "\n\nDRAFT-04 SUITE TESTS\n"
7
- print "--------------------\n"
8
- tests = 0
9
- passes = 0
10
- Dir.glob(File.dirname(__FILE__) + "/suite/tests/draft4/*.json").each do |file_path|
11
- data = JSON.parse(File.read(file_path))
12
- data.each do |test_desc|
13
- puts "Suite Test: #{test_desc["description"]}"
14
- test_desc["tests"].each do |test|
15
- tests = tests + 1
16
- print " - #{test["description"]}: "
17
- begin
18
- if JSON::Validator.validate(test_desc["schema"], test["data"], :version => :draft4) == test["valid"]
19
- puts green("pass")
20
- passes = passes + 1
21
- else
22
- puts "#{red("fail")} - expected #{test["valid"]}, got #{JSON::Validator.validate(test_desc["schema"], test["data"], :version => :draft4)}"
23
- end
24
- rescue
25
- puts "#{red("fail")} - exception thrown"
26
- end
27
- end
28
- end
29
- end
30
- end
31
-
32
- def test_draft_3
33
- print "\n\nDRAFT-03 SUITE TESTS\n"
34
- print "--------------------\n"
35
-
36
- tests = 0
37
- passes = 0
38
- Dir.glob(File.dirname(__FILE__) + "/suite/tests/draft3/*.json").each do |file_path|
39
- data = JSON.parse(File.read(file_path))
40
- data.each do |test_desc|
41
- puts "Suite Test: #{test_desc["description"]}"
42
- test_desc["tests"].each do |test|
43
- tests = tests + 1
44
- print " - #{test["description"]}: "
45
- begin
46
- if JSON::Validator.validate(test_desc["schema"], test["data"], :version => :draft3) == test["valid"]
47
- puts green("pass")
48
- passes = passes + 1
49
- else
50
- puts "#{red("fail")} - expected #{test["valid"]}, got #{JSON::Validator.validate(test_desc["schema"], test["data"], :version => :draft3)}"
51
- end
52
- rescue
53
- puts "#{red("fail")} - exception thrown"
54
- end
55
- end
56
- end
57
- end
58
- end
59
-
60
- def colorize(color_code,text)
61
- "\e[#{color_code}m#{text}\e[0m"
62
- end
63
-
64
- def red(text)
65
- colorize(31,text)
66
- end
67
-
68
- def green(text)
69
- colorize(32,text)
70
- end
71
- end