json-schema-pvdgm 2.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.md +19 -0
  3. data/README.textile +354 -0
  4. data/lib/json-schema.rb +25 -0
  5. data/lib/json-schema/attributes/additionalitems.rb +23 -0
  6. data/lib/json-schema/attributes/additionalproperties.rb +67 -0
  7. data/lib/json-schema/attributes/allof.rb +37 -0
  8. data/lib/json-schema/attributes/anyof.rb +41 -0
  9. data/lib/json-schema/attributes/dependencies.rb +30 -0
  10. data/lib/json-schema/attributes/dependencies_v4.rb +20 -0
  11. data/lib/json-schema/attributes/disallow.rb +11 -0
  12. data/lib/json-schema/attributes/divisibleby.rb +16 -0
  13. data/lib/json-schema/attributes/enum.rb +24 -0
  14. data/lib/json-schema/attributes/extends.rb +49 -0
  15. data/lib/json-schema/attributes/format.rb +123 -0
  16. data/lib/json-schema/attributes/items.rb +25 -0
  17. data/lib/json-schema/attributes/maxdecimal.rb +15 -0
  18. data/lib/json-schema/attributes/maximum.rb +15 -0
  19. data/lib/json-schema/attributes/maximum_inclusive.rb +15 -0
  20. data/lib/json-schema/attributes/maxitems.rb +12 -0
  21. data/lib/json-schema/attributes/maxlength.rb +14 -0
  22. data/lib/json-schema/attributes/maxproperties.rb +12 -0
  23. data/lib/json-schema/attributes/minimum.rb +15 -0
  24. data/lib/json-schema/attributes/minimum_inclusive.rb +15 -0
  25. data/lib/json-schema/attributes/minitems.rb +12 -0
  26. data/lib/json-schema/attributes/minlength.rb +14 -0
  27. data/lib/json-schema/attributes/minproperties.rb +12 -0
  28. data/lib/json-schema/attributes/multipleof.rb +16 -0
  29. data/lib/json-schema/attributes/not.rb +28 -0
  30. data/lib/json-schema/attributes/oneof.rb +32 -0
  31. data/lib/json-schema/attributes/pattern.rb +15 -0
  32. data/lib/json-schema/attributes/patternproperties.rb +23 -0
  33. data/lib/json-schema/attributes/properties.rb +58 -0
  34. data/lib/json-schema/attributes/properties_optional.rb +23 -0
  35. data/lib/json-schema/attributes/properties_v4.rb +57 -0
  36. data/lib/json-schema/attributes/ref.rb +70 -0
  37. data/lib/json-schema/attributes/required.rb +23 -0
  38. data/lib/json-schema/attributes/type.rb +102 -0
  39. data/lib/json-schema/attributes/type_v4.rb +54 -0
  40. data/lib/json-schema/attributes/uniqueitems.rb +16 -0
  41. data/lib/json-schema/model_validator.rb +85 -0
  42. data/lib/json-schema/schema.rb +73 -0
  43. data/lib/json-schema/uri/file.rb +36 -0
  44. data/lib/json-schema/uri/uuid.rb +285 -0
  45. data/lib/json-schema/util/array_set.rb +14 -0
  46. data/lib/json-schema/util/hash.rb +8 -0
  47. data/lib/json-schema/validator.rb +672 -0
  48. data/lib/json-schema/validators/draft1.rb +32 -0
  49. data/lib/json-schema/validators/draft2.rb +33 -0
  50. data/lib/json-schema/validators/draft3.rb +38 -0
  51. data/lib/json-schema/validators/draft4.rb +45 -0
  52. data/resources/draft-01.json +155 -0
  53. data/resources/draft-02.json +166 -0
  54. data/resources/draft-03.json +174 -0
  55. data/resources/draft-04.json +150 -0
  56. data/test/data/all_of_ref_data.json +3 -0
  57. data/test/data/any_of_ref_data.json +7 -0
  58. data/test/data/bad_data_1.json +3 -0
  59. data/test/data/good_data_1.json +3 -0
  60. data/test/data/one_of_ref_links_data.json +5 -0
  61. data/test/schemas/all_of_ref_base_schema.json +6 -0
  62. data/test/schemas/all_of_ref_schema.json +7 -0
  63. data/test/schemas/any_of_ref_jane_schema.json +4 -0
  64. data/test/schemas/any_of_ref_jimmy_schema.json +4 -0
  65. data/test/schemas/any_of_ref_john_schema.json +4 -0
  66. data/test/schemas/any_of_ref_schema.json +15 -0
  67. data/test/schemas/extends_and_additionalProperties-1-filename.schema.json +34 -0
  68. data/test/schemas/extends_and_additionalProperties-1-ref.schema.json +34 -0
  69. data/test/schemas/extends_and_additionalProperties-2-filename.schema.json +33 -0
  70. data/test/schemas/extends_and_additionalProperties-2-ref.schema.json +33 -0
  71. data/test/schemas/good_schema_1.json +10 -0
  72. data/test/schemas/good_schema_2.json +10 -0
  73. data/test/schemas/good_schema_extends1.json +10 -0
  74. data/test/schemas/good_schema_extends2.json +13 -0
  75. data/test/schemas/inner.schema.json +21 -0
  76. data/test/schemas/one_of_ref_links_schema.json +16 -0
  77. data/test/schemas/self_link_schema.json +17 -0
  78. data/test/schemas/up_link_schema.json +17 -0
  79. data/test/test_all_of_ref_schema.rb +11 -0
  80. data/test/test_any_of_ref_schema.rb +11 -0
  81. data/test/test_bad_schema_ref.rb +33 -0
  82. data/test/test_extended_schema.rb +68 -0
  83. data/test/test_extends_and_additionalProperties.rb +50 -0
  84. data/test/test_files_v3.rb +52 -0
  85. data/test/test_fragment_resolution.rb +31 -0
  86. data/test/test_full_validation.rb +209 -0
  87. data/test/test_jsonschema_draft1.rb +701 -0
  88. data/test/test_jsonschema_draft2.rb +773 -0
  89. data/test/test_jsonschema_draft3.rb +1236 -0
  90. data/test/test_jsonschema_draft4.rb +1356 -0
  91. data/test/test_model_validator.rb +52 -0
  92. data/test/test_one_of.rb +42 -0
  93. data/test/test_ruby_schema.rb +38 -0
  94. data/test/test_schema_type_attribute.rb +21 -0
  95. data/test/test_schema_validation.rb +85 -0
  96. metadata +180 -0
@@ -0,0 +1,52 @@
1
+ require 'test/unit'
2
+ require 'active_support'
3
+ require 'active_support/core_ext/object/blank'
4
+ require File.dirname(__FILE__) + '/../lib/json-schema'
5
+
6
+ class ModelValidatorTest < Test::Unit::TestCase
7
+
8
+ def test_process_required_if
9
+ v = JSON::ModelValidator.new({})
10
+ responses = OpenStruct.new({ a: 'thing' })
11
+
12
+ error = v.send(:process_required_if, responses, 'b', 'r.a == "something"')
13
+ assert(error.nil?, "should be no errors")
14
+
15
+ error = v.send(:process_required_if, responses, 'b', 'r.a == "thing"')
16
+ assert(error == { property: :b, failure: :required }, "should have been an error")
17
+
18
+ responses.b = 'is set'
19
+ error = v.send(:process_required_if, responses, 'b', 'r.a == "thing"')
20
+ assert(error.nil?, "should be no errors")
21
+ end
22
+
23
+ def test_process_none_of_the_above
24
+ v = JSON::ModelValidator.new({})
25
+ responses = OpenStruct.new({ })
26
+
27
+ error = v.send(:process_none_of_the_above, responses, 'a', '7')
28
+ assert(error.nil?, "should be no errors")
29
+
30
+ responses.a = 'thing'
31
+ error = v.send(:process_none_of_the_above, responses, 'a', '7')
32
+ assert(error.nil?, "should be no errors")
33
+
34
+ responses.a = []
35
+ error = v.send(:process_none_of_the_above, responses, 'a', '7')
36
+ assert(error.nil?, "should be no errors")
37
+
38
+ responses.a = [ '1' ]
39
+ error = v.send(:process_none_of_the_above, responses, 'a', '7')
40
+ assert(error.nil?, "should be no errors")
41
+
42
+ responses.a = [ '7' ]
43
+ error = v.send(:process_none_of_the_above, responses, 'a', '7')
44
+ assert(error.nil?, "should be no errors")
45
+
46
+ responses.a = [ '1', '7' ]
47
+ error = v.send(:process_none_of_the_above, responses, 'a', '7')
48
+ assert(error == { property: :a, failure: :noneOfTheAbove }, "should have been an error")
49
+
50
+ end
51
+
52
+ end
@@ -0,0 +1,42 @@
1
+ require 'test/unit'
2
+ require File.dirname(__FILE__) + '/../lib/json-schema'
3
+
4
+ class OneOfTest < Test::Unit::TestCase
5
+ def test_one_of_links_schema
6
+ schema = File.join(File.dirname(__FILE__),"schemas/one_of_ref_links_schema.json")
7
+ data = File.join(File.dirname(__FILE__),"data/one_of_ref_links_data.json")
8
+ errors = JSON::Validator.fully_validate(schema,data, :errors_as_objects => true)
9
+ assert(errors.empty?, errors.map{|e| e[:message] }.join("\n"))
10
+ end
11
+
12
+
13
+ def test_one_of_with_string_patterns
14
+ schema = {
15
+ "$schema" => "http://json-schema.org/draft-04/schema#",
16
+ "oneOf" => [
17
+ {
18
+ "properties" => {"a" => {"type" => "string", "pattern" => "foo"}},
19
+ },
20
+ {
21
+ "properties" => {"a" => {"type" => "string", "pattern" => "bar"}},
22
+ },
23
+ {
24
+ "properties" => {"a" => {"type" => "string", "pattern" => "baz"}},
25
+ }
26
+ ]
27
+ }
28
+
29
+ data = {"a" => "foo"}
30
+ assert(JSON::Validator.validate(schema,data))
31
+
32
+ data = {"a" => "foobar"}
33
+ assert(!JSON::Validator.validate(schema,data))
34
+
35
+ data = {"a" => "baz"}
36
+ assert(JSON::Validator.validate(schema,data))
37
+
38
+ data = {"a" => 5}
39
+ assert(!JSON::Validator.validate(schema,data))
40
+ end
41
+
42
+ end
@@ -0,0 +1,38 @@
1
+ require 'test/unit'
2
+ require File.dirname(__FILE__) + '/../lib/json-schema'
3
+
4
+ class RubySchemaTest < Test::Unit::TestCase
5
+ def test_string_keys
6
+ schema = {
7
+ "type" => 'object',
8
+ "required" => ["a"],
9
+ "properties" => {
10
+ "a" => {"type" => "integer", "default" => 42},
11
+ "b" => {"type" => "integer"}
12
+ }
13
+ }
14
+
15
+ data = {
16
+ "a" => 5
17
+ }
18
+
19
+ assert(JSON::Validator.validate(schema, data))
20
+ end
21
+
22
+ def test_symbol_keys
23
+ schema = {
24
+ type: 'object',
25
+ required: ["a"],
26
+ properties: {
27
+ a: {type: "integer", default: 42},
28
+ b: {type: "integer"}
29
+ }
30
+ }
31
+
32
+ data = {
33
+ a: 5
34
+ }
35
+
36
+ assert(JSON::Validator.validate(schema, data))
37
+ end
38
+ end
@@ -0,0 +1,21 @@
1
+ require 'test/unit'
2
+ require File.dirname(__FILE__) + '/../lib/json-schema'
3
+
4
+ class TestSchemaTypeAttribute < Test::Unit::TestCase
5
+ def test_type_of_data
6
+ assert_equal(type_of_data(String.new), 'string')
7
+ assert_equal(type_of_data(Numeric.new), 'number')
8
+ assert_equal(type_of_data(1), 'integer')
9
+ assert_equal(type_of_data(true), 'boolean')
10
+ assert_equal(type_of_data(false), 'boolean')
11
+ assert_equal(type_of_data(Hash.new), 'object')
12
+ assert_equal(type_of_data(nil), 'null')
13
+ assert_equal(type_of_data(Object.new), 'any')
14
+ end
15
+
16
+ private
17
+
18
+ def type_of_data(data)
19
+ JSON::Schema::TypeAttribute.type_of_data(data)
20
+ end
21
+ end
@@ -0,0 +1,85 @@
1
+ require 'test/unit'
2
+ require File.dirname(__FILE__) + '/../lib/json-schema'
3
+
4
+ class JSONSchemaValidation < Test::Unit::TestCase
5
+ def valid_schema_v3
6
+ {
7
+ "$schema" => "http://json-schema.org/draft-03/schema#",
8
+ "type" => "object",
9
+ "properties" => {
10
+ "b" => {
11
+ "required" => true
12
+ }
13
+ }
14
+ }
15
+ end
16
+
17
+ def invalid_schema_v3
18
+ {
19
+ "$schema" => "http://json-schema.org/draft-03/schema#",
20
+ "type" => "object",
21
+ "properties" => {
22
+ "b" => {
23
+ "required" => "true"
24
+ }
25
+ }
26
+ }
27
+ end
28
+
29
+ def valid_schema_v4
30
+ {
31
+ "$schema" => "http://json-schema.org/draft-04/schema#",
32
+ "type" => "object",
33
+ "required" => ["b"],
34
+ "properties" => {
35
+ }
36
+ }
37
+ end
38
+
39
+ def invalid_schema_v4
40
+ {
41
+ "$schema" => "http://json-schema.org/draft-04/schema#",
42
+ "type" => "object",
43
+ "required" => "b",
44
+ "properties" => {
45
+ }
46
+ }
47
+ end
48
+
49
+ def test_draft03_validation
50
+ data = {"b" => {"a" => 5}}
51
+ assert(JSON::Validator.validate(valid_schema_v3,data,:validate_schema => true, :version => :draft3))
52
+ assert(!JSON::Validator.validate(invalid_schema_v3,data,:validate_schema => true, :version => :draft3))
53
+ end
54
+
55
+ def test_validate_just_schema_draft03
56
+ errors = JSON::Validator.fully_validate_schema(valid_schema_v3, :version => :draft3)
57
+ assert_equal [], errors
58
+
59
+ errors = JSON::Validator.fully_validate_schema(invalid_schema_v3, :version => :draft3)
60
+ assert_equal 1, errors.size
61
+ assert_match /the property .*required.*did not match/i, errors.first
62
+ end
63
+
64
+
65
+ def test_draft04_validation
66
+ data = {"b" => {"a" => 5}}
67
+ assert(JSON::Validator.validate(valid_schema_v4,data,:validate_schema => true, :version => :draft4))
68
+ assert(!JSON::Validator.validate(invalid_schema_v4,data,:validate_schema => true, :version => :draft4))
69
+ end
70
+
71
+ def test_validate_just_schema_draft04
72
+ errors = JSON::Validator.fully_validate_schema(valid_schema_v4, :version => :draft4)
73
+ assert_equal [], errors
74
+
75
+ errors = JSON::Validator.fully_validate_schema(invalid_schema_v4, :version => :draft4)
76
+ assert_equal 1, errors.size
77
+ assert_match /the property .*required.*did not match/i, errors.first
78
+ end
79
+
80
+ def test_validate_schema_3_without_version_option
81
+ data = {"b" => {"a" => 5}}
82
+ assert(JSON::Validator.validate(valid_schema_v3,data,:validate_schema => true))
83
+ assert(!JSON::Validator.validate(invalid_schema_v3,data,:validate_schema => true))
84
+ end
85
+ end
metadata ADDED
@@ -0,0 +1,180 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: json-schema-pvdgm
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.3.1
5
+ platform: ruby
6
+ authors:
7
+ - Kenny Hoxworth
8
+ - Dave Sieh
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-07-22 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description:
15
+ email: hoxworth@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files:
19
+ - README.textile
20
+ - LICENSE.md
21
+ files:
22
+ - LICENSE.md
23
+ - README.textile
24
+ - lib/json-schema.rb
25
+ - lib/json-schema/attributes/additionalitems.rb
26
+ - lib/json-schema/attributes/additionalproperties.rb
27
+ - lib/json-schema/attributes/allof.rb
28
+ - lib/json-schema/attributes/anyof.rb
29
+ - lib/json-schema/attributes/dependencies.rb
30
+ - lib/json-schema/attributes/dependencies_v4.rb
31
+ - lib/json-schema/attributes/disallow.rb
32
+ - lib/json-schema/attributes/divisibleby.rb
33
+ - lib/json-schema/attributes/enum.rb
34
+ - lib/json-schema/attributes/extends.rb
35
+ - lib/json-schema/attributes/format.rb
36
+ - lib/json-schema/attributes/items.rb
37
+ - lib/json-schema/attributes/maxdecimal.rb
38
+ - lib/json-schema/attributes/maximum.rb
39
+ - lib/json-schema/attributes/maximum_inclusive.rb
40
+ - lib/json-schema/attributes/maxitems.rb
41
+ - lib/json-schema/attributes/maxlength.rb
42
+ - lib/json-schema/attributes/maxproperties.rb
43
+ - lib/json-schema/attributes/minimum.rb
44
+ - lib/json-schema/attributes/minimum_inclusive.rb
45
+ - lib/json-schema/attributes/minitems.rb
46
+ - lib/json-schema/attributes/minlength.rb
47
+ - lib/json-schema/attributes/minproperties.rb
48
+ - lib/json-schema/attributes/multipleof.rb
49
+ - lib/json-schema/attributes/not.rb
50
+ - lib/json-schema/attributes/oneof.rb
51
+ - lib/json-schema/attributes/pattern.rb
52
+ - lib/json-schema/attributes/patternproperties.rb
53
+ - lib/json-schema/attributes/properties.rb
54
+ - lib/json-schema/attributes/properties_optional.rb
55
+ - lib/json-schema/attributes/properties_v4.rb
56
+ - lib/json-schema/attributes/ref.rb
57
+ - lib/json-schema/attributes/required.rb
58
+ - lib/json-schema/attributes/type.rb
59
+ - lib/json-schema/attributes/type_v4.rb
60
+ - lib/json-schema/attributes/uniqueitems.rb
61
+ - lib/json-schema/model_validator.rb
62
+ - lib/json-schema/schema.rb
63
+ - lib/json-schema/uri/file.rb
64
+ - lib/json-schema/uri/uuid.rb
65
+ - lib/json-schema/util/array_set.rb
66
+ - lib/json-schema/util/hash.rb
67
+ - lib/json-schema/validator.rb
68
+ - lib/json-schema/validators/draft1.rb
69
+ - lib/json-schema/validators/draft2.rb
70
+ - lib/json-schema/validators/draft3.rb
71
+ - lib/json-schema/validators/draft4.rb
72
+ - resources/draft-01.json
73
+ - resources/draft-02.json
74
+ - resources/draft-03.json
75
+ - resources/draft-04.json
76
+ - test/data/all_of_ref_data.json
77
+ - test/data/any_of_ref_data.json
78
+ - test/data/bad_data_1.json
79
+ - test/data/good_data_1.json
80
+ - test/data/one_of_ref_links_data.json
81
+ - test/schemas/all_of_ref_base_schema.json
82
+ - test/schemas/all_of_ref_schema.json
83
+ - test/schemas/any_of_ref_jane_schema.json
84
+ - test/schemas/any_of_ref_jimmy_schema.json
85
+ - test/schemas/any_of_ref_john_schema.json
86
+ - test/schemas/any_of_ref_schema.json
87
+ - test/schemas/extends_and_additionalProperties-1-filename.schema.json
88
+ - test/schemas/extends_and_additionalProperties-1-ref.schema.json
89
+ - test/schemas/extends_and_additionalProperties-2-filename.schema.json
90
+ - test/schemas/extends_and_additionalProperties-2-ref.schema.json
91
+ - test/schemas/good_schema_1.json
92
+ - test/schemas/good_schema_2.json
93
+ - test/schemas/good_schema_extends1.json
94
+ - test/schemas/good_schema_extends2.json
95
+ - test/schemas/inner.schema.json
96
+ - test/schemas/one_of_ref_links_schema.json
97
+ - test/schemas/self_link_schema.json
98
+ - test/schemas/up_link_schema.json
99
+ - test/test_all_of_ref_schema.rb
100
+ - test/test_any_of_ref_schema.rb
101
+ - test/test_bad_schema_ref.rb
102
+ - test/test_extended_schema.rb
103
+ - test/test_extends_and_additionalProperties.rb
104
+ - test/test_files_v3.rb
105
+ - test/test_fragment_resolution.rb
106
+ - test/test_full_validation.rb
107
+ - test/test_jsonschema_draft1.rb
108
+ - test/test_jsonschema_draft2.rb
109
+ - test/test_jsonschema_draft3.rb
110
+ - test/test_jsonschema_draft4.rb
111
+ - test/test_model_validator.rb
112
+ - test/test_one_of.rb
113
+ - test/test_ruby_schema.rb
114
+ - test/test_schema_type_attribute.rb
115
+ - test/test_schema_validation.rb
116
+ homepage: http://github.com/hoxworth/json-schema/tree/master
117
+ licenses:
118
+ - MIT
119
+ metadata: {}
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - '>='
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubyforge_project:
136
+ rubygems_version: 2.2.2
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: Ruby JSON Schema Validator
140
+ test_files:
141
+ - test/test_all_of_ref_schema.rb
142
+ - test/test_any_of_ref_schema.rb
143
+ - test/test_bad_schema_ref.rb
144
+ - test/test_extended_schema.rb
145
+ - test/test_extends_and_additionalProperties.rb
146
+ - test/test_files_v3.rb
147
+ - test/test_fragment_resolution.rb
148
+ - test/test_full_validation.rb
149
+ - test/test_jsonschema_draft1.rb
150
+ - test/test_jsonschema_draft2.rb
151
+ - test/test_jsonschema_draft3.rb
152
+ - test/test_jsonschema_draft4.rb
153
+ - test/test_model_validator.rb
154
+ - test/test_one_of.rb
155
+ - test/test_ruby_schema.rb
156
+ - test/test_schema_type_attribute.rb
157
+ - test/test_schema_validation.rb
158
+ - test/data/all_of_ref_data.json
159
+ - test/data/any_of_ref_data.json
160
+ - test/data/bad_data_1.json
161
+ - test/data/good_data_1.json
162
+ - test/data/one_of_ref_links_data.json
163
+ - test/schemas/all_of_ref_base_schema.json
164
+ - test/schemas/all_of_ref_schema.json
165
+ - test/schemas/any_of_ref_jane_schema.json
166
+ - test/schemas/any_of_ref_jimmy_schema.json
167
+ - test/schemas/any_of_ref_john_schema.json
168
+ - test/schemas/any_of_ref_schema.json
169
+ - test/schemas/extends_and_additionalProperties-1-filename.schema.json
170
+ - test/schemas/extends_and_additionalProperties-1-ref.schema.json
171
+ - test/schemas/extends_and_additionalProperties-2-filename.schema.json
172
+ - test/schemas/extends_and_additionalProperties-2-ref.schema.json
173
+ - test/schemas/good_schema_1.json
174
+ - test/schemas/good_schema_2.json
175
+ - test/schemas/good_schema_extends1.json
176
+ - test/schemas/good_schema_extends2.json
177
+ - test/schemas/inner.schema.json
178
+ - test/schemas/one_of_ref_links_schema.json
179
+ - test/schemas/self_link_schema.json
180
+ - test/schemas/up_link_schema.json