schemacop 2.4.6 → 3.0.0.rc3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (174) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -0
  3. data/.releaser_config +0 -1
  4. data/.rubocop.yml +25 -1
  5. data/.travis.yml +3 -1
  6. data/CHANGELOG.md +33 -0
  7. data/README.md +53 -710
  8. data/README_V2.md +775 -0
  9. data/README_V3.md +1197 -0
  10. data/Rakefile +8 -12
  11. data/VERSION +1 -1
  12. data/lib/schemacop.rb +35 -36
  13. data/lib/schemacop/base_schema.rb +37 -0
  14. data/lib/schemacop/railtie.rb +10 -0
  15. data/lib/schemacop/schema.rb +1 -60
  16. data/lib/schemacop/schema2.rb +22 -0
  17. data/lib/schemacop/schema3.rb +21 -0
  18. data/lib/schemacop/scoped_env.rb +25 -13
  19. data/lib/schemacop/v2.rb +25 -0
  20. data/lib/schemacop/{caster.rb → v2/caster.rb} +16 -2
  21. data/lib/schemacop/{collector.rb → v2/collector.rb} +5 -2
  22. data/lib/schemacop/{dupper.rb → v2/dupper.rb} +1 -1
  23. data/lib/schemacop/{field_node.rb → v2/field_node.rb} +4 -3
  24. data/lib/schemacop/v2/node.rb +142 -0
  25. data/lib/schemacop/{node_resolver.rb → v2/node_resolver.rb} +1 -1
  26. data/lib/schemacop/v2/node_supporting_field.rb +70 -0
  27. data/lib/schemacop/{node_supporting_type.rb → v2/node_supporting_type.rb} +8 -5
  28. data/lib/schemacop/{node_with_block.rb → v2/node_with_block.rb} +3 -2
  29. data/lib/schemacop/v2/root_node.rb +0 -0
  30. data/lib/schemacop/v2/validator/array_validator.rb +32 -0
  31. data/lib/schemacop/{validator → v2/validator}/boolean_validator.rb +1 -1
  32. data/lib/schemacop/v2/validator/float_validator.rb +7 -0
  33. data/lib/schemacop/v2/validator/hash_validator.rb +37 -0
  34. data/lib/schemacop/v2/validator/integer_validator.rb +7 -0
  35. data/lib/schemacop/{validator → v2/validator}/nil_validator.rb +1 -1
  36. data/lib/schemacop/v2/validator/number_validator.rb +21 -0
  37. data/lib/schemacop/v2/validator/object_validator.rb +29 -0
  38. data/lib/schemacop/v2/validator/string_validator.rb +39 -0
  39. data/lib/schemacop/{validator → v2/validator}/symbol_validator.rb +1 -1
  40. data/lib/schemacop/v3.rb +45 -0
  41. data/lib/schemacop/v3/all_of_node.rb +27 -0
  42. data/lib/schemacop/v3/any_of_node.rb +28 -0
  43. data/lib/schemacop/v3/array_node.rb +218 -0
  44. data/lib/schemacop/v3/boolean_node.rb +16 -0
  45. data/lib/schemacop/v3/combination_node.rb +45 -0
  46. data/lib/schemacop/v3/context.rb +17 -0
  47. data/lib/schemacop/v3/dsl_scope.rb +46 -0
  48. data/lib/schemacop/v3/global_context.rb +114 -0
  49. data/lib/schemacop/v3/hash_node.rb +258 -0
  50. data/lib/schemacop/v3/integer_node.rb +13 -0
  51. data/lib/schemacop/v3/is_not_node.rb +32 -0
  52. data/lib/schemacop/v3/node.rb +219 -0
  53. data/lib/schemacop/v3/node_registry.rb +49 -0
  54. data/lib/schemacop/v3/number_node.rb +18 -0
  55. data/lib/schemacop/v3/numeric_node.rb +76 -0
  56. data/lib/schemacop/v3/object_node.rb +40 -0
  57. data/lib/schemacop/v3/one_of_node.rb +28 -0
  58. data/lib/schemacop/v3/reference_node.rb +49 -0
  59. data/lib/schemacop/v3/result.rb +58 -0
  60. data/lib/schemacop/v3/string_node.rb +124 -0
  61. data/lib/schemacop/v3/symbol_node.rb +13 -0
  62. data/schemacop.gemspec +24 -27
  63. data/test/lib/test_helper.rb +152 -0
  64. data/test/schemas/nested/group.rb +6 -0
  65. data/test/schemas/user.rb +7 -0
  66. data/test/unit/schemacop/v2/casting_test.rb +120 -0
  67. data/test/unit/schemacop/v2/collector_test.rb +47 -0
  68. data/test/unit/schemacop/v2/custom_check_test.rb +95 -0
  69. data/test/unit/schemacop/v2/custom_if_test.rb +97 -0
  70. data/test/unit/schemacop/v2/defaults_test.rb +95 -0
  71. data/test/unit/schemacop/v2/empty_test.rb +16 -0
  72. data/test/unit/schemacop/v2/nil_dis_allow_test.rb +43 -0
  73. data/test/unit/schemacop/v2/node_resolver_test.rb +28 -0
  74. data/test/unit/schemacop/v2/short_forms_test.rb +351 -0
  75. data/test/unit/schemacop/v2/types_test.rb +88 -0
  76. data/test/unit/schemacop/v2/validator_array_test.rb +99 -0
  77. data/test/unit/schemacop/v2/validator_boolean_test.rb +17 -0
  78. data/test/unit/schemacop/v2/validator_float_test.rb +59 -0
  79. data/test/unit/schemacop/v2/validator_hash_test.rb +95 -0
  80. data/test/unit/schemacop/v2/validator_integer_test.rb +48 -0
  81. data/test/unit/schemacop/v2/validator_nil_test.rb +15 -0
  82. data/test/unit/schemacop/v2/validator_number_test.rb +62 -0
  83. data/test/unit/schemacop/v2/validator_object_test.rb +141 -0
  84. data/test/unit/schemacop/v2/validator_string_test.rb +78 -0
  85. data/test/unit/schemacop/v2/validator_symbol_test.rb +18 -0
  86. data/test/unit/schemacop/v3/all_of_node_test.rb +198 -0
  87. data/test/unit/schemacop/v3/any_of_node_test.rb +218 -0
  88. data/test/unit/schemacop/v3/array_node_test.rb +815 -0
  89. data/test/unit/schemacop/v3/boolean_node_test.rb +126 -0
  90. data/test/unit/schemacop/v3/global_context_test.rb +164 -0
  91. data/test/unit/schemacop/v3/hash_node_test.rb +884 -0
  92. data/test/unit/schemacop/v3/integer_node_test.rb +323 -0
  93. data/test/unit/schemacop/v3/is_not_node_test.rb +173 -0
  94. data/test/unit/schemacop/v3/node_test.rb +148 -0
  95. data/test/unit/schemacop/v3/number_node_test.rb +292 -0
  96. data/test/unit/schemacop/v3/object_node_test.rb +170 -0
  97. data/test/unit/schemacop/v3/one_of_node_test.rb +187 -0
  98. data/test/unit/schemacop/v3/reference_node_test.rb +351 -0
  99. data/test/unit/schemacop/v3/string_node_test.rb +334 -0
  100. data/test/unit/schemacop/v3/symbol_node_test.rb +75 -0
  101. metadata +157 -150
  102. data/doc/Schemacop.html +0 -146
  103. data/doc/Schemacop/ArrayValidator.html +0 -329
  104. data/doc/Schemacop/BooleanValidator.html +0 -145
  105. data/doc/Schemacop/Caster.html +0 -379
  106. data/doc/Schemacop/Collector.html +0 -787
  107. data/doc/Schemacop/Dupper.html +0 -214
  108. data/doc/Schemacop/Exceptions.html +0 -115
  109. data/doc/Schemacop/Exceptions/InvalidSchemaError.html +0 -124
  110. data/doc/Schemacop/Exceptions/ValidationError.html +0 -124
  111. data/doc/Schemacop/FieldNode.html +0 -421
  112. data/doc/Schemacop/FloatValidator.html +0 -158
  113. data/doc/Schemacop/HashValidator.html +0 -293
  114. data/doc/Schemacop/IntegerValidator.html +0 -158
  115. data/doc/Schemacop/NilValidator.html +0 -145
  116. data/doc/Schemacop/Node.html +0 -1438
  117. data/doc/Schemacop/NodeResolver.html +0 -258
  118. data/doc/Schemacop/NodeSupportingField.html +0 -590
  119. data/doc/Schemacop/NodeSupportingType.html +0 -612
  120. data/doc/Schemacop/NodeWithBlock.html +0 -289
  121. data/doc/Schemacop/NumberValidator.html +0 -232
  122. data/doc/Schemacop/ObjectValidator.html +0 -298
  123. data/doc/Schemacop/RootNode.html +0 -171
  124. data/doc/Schemacop/Schema.html +0 -699
  125. data/doc/Schemacop/StringValidator.html +0 -295
  126. data/doc/Schemacop/SymbolValidator.html +0 -145
  127. data/doc/ScopedEnv.html +0 -351
  128. data/doc/_index.html +0 -379
  129. data/doc/class_list.html +0 -51
  130. data/doc/css/common.css +0 -1
  131. data/doc/css/full_list.css +0 -58
  132. data/doc/css/style.css +0 -496
  133. data/doc/file.README.html +0 -833
  134. data/doc/file_list.html +0 -56
  135. data/doc/frames.html +0 -17
  136. data/doc/index.html +0 -833
  137. data/doc/inheritance.graphml +0 -524
  138. data/doc/inheritance.pdf +0 -825
  139. data/doc/js/app.js +0 -303
  140. data/doc/js/full_list.js +0 -216
  141. data/doc/js/jquery.js +0 -4
  142. data/doc/method_list.html +0 -587
  143. data/doc/top-level-namespace.html +0 -112
  144. data/lib/schemacop/node.rb +0 -139
  145. data/lib/schemacop/node_supporting_field.rb +0 -58
  146. data/lib/schemacop/root_node.rb +0 -4
  147. data/lib/schemacop/validator/array_validator.rb +0 -30
  148. data/lib/schemacop/validator/float_validator.rb +0 -5
  149. data/lib/schemacop/validator/hash_validator.rb +0 -35
  150. data/lib/schemacop/validator/integer_validator.rb +0 -5
  151. data/lib/schemacop/validator/number_validator.rb +0 -19
  152. data/lib/schemacop/validator/object_validator.rb +0 -27
  153. data/lib/schemacop/validator/string_validator.rb +0 -37
  154. data/test/casting_test.rb +0 -100
  155. data/test/collector_test.rb +0 -45
  156. data/test/custom_check_test.rb +0 -93
  157. data/test/custom_if_test.rb +0 -95
  158. data/test/defaults_test.rb +0 -93
  159. data/test/empty_test.rb +0 -14
  160. data/test/nil_dis_allow_test.rb +0 -41
  161. data/test/node_resolver_test.rb +0 -26
  162. data/test/short_forms_test.rb +0 -349
  163. data/test/test_helper.rb +0 -13
  164. data/test/types_test.rb +0 -84
  165. data/test/validator_array_test.rb +0 -97
  166. data/test/validator_boolean_test.rb +0 -15
  167. data/test/validator_float_test.rb +0 -57
  168. data/test/validator_hash_test.rb +0 -93
  169. data/test/validator_integer_test.rb +0 -46
  170. data/test/validator_nil_test.rb +0 -13
  171. data/test/validator_number_test.rb +0 -60
  172. data/test/validator_object_test.rb +0 -139
  173. data/test/validator_string_test.rb +0 -76
  174. data/test/validator_symbol_test.rb +0 -16
@@ -0,0 +1,334 @@
1
+ require 'test_helper'
2
+
3
+ module Schemacop
4
+ module V3
5
+ class StringNodeTest < V3Test
6
+ EXP_INVALID_TYPE = 'Invalid type, expected "string".'.freeze
7
+
8
+ def test_basic
9
+ schema :string
10
+ assert_validation 'Hello World'
11
+ assert_validation ''
12
+ assert_json(type: :string)
13
+ end
14
+
15
+ def test_required
16
+ schema :string, required: true
17
+ assert_validation 'Hello World'
18
+ assert_validation ''
19
+ assert_validation nil do
20
+ error '/', 'Value must be given.'
21
+ end
22
+ end
23
+
24
+ def test_hash
25
+ schema { str! :name }
26
+ assert_validation name: 'Hello World'
27
+ assert_json(type: :object, properties: { name: { type: :string } }, required: %i[name], additionalProperties: false)
28
+ end
29
+
30
+ def test_type
31
+ schema :string
32
+
33
+ assert_json(type: :string)
34
+
35
+ assert_validation 42 do
36
+ error '/', EXP_INVALID_TYPE
37
+ end
38
+
39
+ schema { str! :name }
40
+
41
+ assert_json(type: :object, properties: { name: { type: :string } }, required: %i[name], additionalProperties: false)
42
+
43
+ assert_validation name: :foo do
44
+ error '/name', EXP_INVALID_TYPE
45
+ end
46
+
47
+ assert_validation name: 234 do
48
+ error '/name', EXP_INVALID_TYPE
49
+ end
50
+ end
51
+
52
+ def test_min_length
53
+ schema :string, min_length: 5
54
+
55
+ assert_json(type: :string, minLength: 5)
56
+
57
+ assert_validation '12345'
58
+ assert_validation '12345678'
59
+
60
+ assert_validation '1234' do
61
+ error '/', 'String is 4 characters long but must be at least 5.'
62
+ end
63
+
64
+ assert_validation '' do
65
+ error '/', 'String is 0 characters long but must be at least 5.'
66
+ end
67
+ end
68
+
69
+ def test_max_length
70
+ schema :string, max_length: 5
71
+
72
+ assert_json(type: :string, maxLength: 5)
73
+
74
+ assert_validation ''
75
+ assert_validation '12345'
76
+ assert_validation '1234'
77
+
78
+ assert_validation '123456' do
79
+ error '/', 'String is 6 characters long but must be at most 5.'
80
+ end
81
+ end
82
+
83
+ def test_pattern
84
+ schema :string, pattern: '^a_.*_z$'
85
+
86
+ assert_json(type: :string, pattern: '^a_.*_z$')
87
+
88
+ assert_validation 'a__z'
89
+ assert_validation 'a_ foo bar _z'
90
+ assert_validation '' do
91
+ error '/', 'String does not match pattern "^a_.*_z$".'
92
+ end
93
+ assert_validation 'a_ _zfoo' do
94
+ error '/', 'String does not match pattern "^a_.*_z$".'
95
+ end
96
+ end
97
+
98
+ def test_format_date
99
+ schema :string, format: :date
100
+
101
+ assert_json(type: :string, format: :date)
102
+
103
+ assert_validation '2020-01-13'
104
+ assert_validation '2020-02-29'
105
+ assert_validation '2021-02-29' # Leap years are not validated
106
+
107
+ assert_validation '2020-13-29' do
108
+ error '/', 'String does not match format "date".'
109
+ end
110
+
111
+ assert_validation 'foo 2020-01-29 bar' do
112
+ error '/', 'String does not match format "date".'
113
+ end
114
+ end
115
+
116
+ def test_format_date_time
117
+ schema :string, format: :date_time
118
+
119
+ assert_json(type: :string, format: :'date-time')
120
+
121
+ assert_validation '2018-11-13T20:20:39+00:00'
122
+ assert_validation '2018-11-13T20:20:39Z'
123
+
124
+ assert_validation '2020-13-29' do
125
+ error '/', 'String does not match format "date-time".'
126
+ end
127
+
128
+ assert_validation '2018-13-13T20:20:39+00:00' do
129
+ error '/', 'String does not match format "date-time".'
130
+ end
131
+
132
+ assert_validation '2018-11-13T20:20:39Y' do
133
+ error '/', 'String does not match format "date-time".'
134
+ end
135
+ end
136
+
137
+ def test_format_email
138
+ schema :string, format: :email
139
+
140
+ assert_json(type: :string, format: :email)
141
+
142
+ assert_validation 'john.doe@example.com'
143
+ assert_validation 'john.doe+foo-bar_baz@example.com'
144
+ assert_validation 'JOHN.DOE+FOO-BAR_BAZ@EXAMPLE.COM'
145
+
146
+ assert_validation 'someemail' do
147
+ error '/', 'String does not match format "email".'
148
+ end
149
+
150
+ assert_validation 'john doe@example.com' do
151
+ error '/', 'String does not match format "email".'
152
+ end
153
+
154
+ assert_validation '@john@example.com' do
155
+ error '/', 'String does not match format "email".'
156
+ end
157
+ end
158
+
159
+ def test_enum
160
+ schema :string, enum: ['foo', 'some string', 'some other string', 42]
161
+
162
+ assert_json(type: :string, enum: ['foo', 'some string', 'some other string', 42])
163
+
164
+ assert_validation 'foo'
165
+ assert_validation 'some string'
166
+ assert_validation 'some other string'
167
+
168
+ assert_validation 'fooo' do
169
+ error '/', 'Value not included in enum ["foo", "some string", "some other string", 42].'
170
+ end
171
+
172
+ assert_validation 'other value' do
173
+ error '/', 'Value not included in enum ["foo", "some string", "some other string", 42].'
174
+ end
175
+
176
+ # Integer value 42 is in the enum of allowed values, but it's not a string,
177
+ # so the validation still fails
178
+ assert_validation 42 do
179
+ error '/', 'Invalid type, expected "string".'
180
+ end
181
+ end
182
+
183
+ def test_boolean_casting
184
+ schema :string, format: :boolean
185
+
186
+ assert_json(type: :string, format: :boolean)
187
+
188
+ assert_cast 'true', true
189
+ assert_cast 'false', false
190
+ end
191
+
192
+ def test_time_casting
193
+ schema :string, format: :time
194
+ assert_json(type: :string, format: :time)
195
+ assert_cast '20:30:39+00:00', Time.strptime('20:30:39+00:00', '%H:%M:%S%z')
196
+ end
197
+
198
+ def test_date_casting
199
+ schema :string, format: :date
200
+ assert_json(type: :string, format: :date)
201
+ assert_cast '2018-11-13', Date.new(2018, 11, 13)
202
+ end
203
+
204
+ def test_date_time_casting
205
+ schema :string, format: :date_time
206
+ assert_json(type: :string, format: :'date-time')
207
+ assert_cast '2018-11-13T20:20:39+00:00', DateTime.new(2018, 11, 13, 20, 20, 39)
208
+ assert_cast '2018-11-13T20:20:39Z', DateTime.new(2018, 11, 13, 20, 20, 39)
209
+ assert_cast '2018-11-13T20:20:39+01:00', DateTime.new(2018, 11, 13, 20, 20, 39, '+1')
210
+ end
211
+
212
+ def test_email_casting
213
+ schema :string, format: :email
214
+ assert_json(type: :string, format: :email)
215
+ assert_cast 'support@example.com', 'support@example.com'
216
+ end
217
+
218
+ def test_default
219
+ schema :string, default: 'Hello'
220
+
221
+ assert_json(
222
+ type: :string,
223
+ default: 'Hello'
224
+ )
225
+
226
+ assert_validation(nil)
227
+ assert_validation('Foo')
228
+ assert_validation(5) do
229
+ error '/', 'Invalid type, expected "string".'
230
+ end
231
+
232
+ assert_cast('Foo', 'Foo')
233
+ assert_cast(nil, 'Hello')
234
+ end
235
+
236
+ # Helper function that checks for all the options if the option is
237
+ # an integer or something else, in which case it needs to raise
238
+ def validate_self_should_error(value_to_check)
239
+ assert_raises_with_message Exceptions::InvalidSchemaError,
240
+ 'Option "min_length" must be an "integer"' do
241
+ schema :string, min_length: value_to_check
242
+ end
243
+
244
+ assert_raises_with_message Exceptions::InvalidSchemaError,
245
+ 'Option "max_length" must be an "integer"' do
246
+ schema :string, max_length: value_to_check
247
+ end
248
+ end
249
+
250
+ def test_validate_self
251
+ assert_raises_with_message Exceptions::InvalidSchemaError,
252
+ 'Format "not-existing" is not supported.' do
253
+ schema :string, format: :not_existing
254
+ end
255
+
256
+ assert_raises_with_message Exceptions::InvalidSchemaError,
257
+ 'Option "min_length" can\'t be greater than "max_length".' do
258
+ schema :string, min_length: 5, max_length: 4
259
+ end
260
+
261
+ assert_raises_with_message Exceptions::InvalidSchemaError,
262
+ 'Option "pattern" must be a string.' do
263
+ schema :string, pattern: //
264
+ end
265
+
266
+ assert_raises_with_message Exceptions::InvalidSchemaError,
267
+ 'Option "pattern" can\'t be parsed: end pattern '\
268
+ 'with unmatched parenthesis: /(abcde/.' do
269
+ schema :string, pattern: '(abcde'
270
+ end
271
+
272
+ validate_self_should_error(1.0)
273
+ validate_self_should_error(4r)
274
+ validate_self_should_error(true)
275
+ validate_self_should_error(false)
276
+ validate_self_should_error(Object.new)
277
+ validate_self_should_error((4 + 6i))
278
+ validate_self_should_error('13')
279
+ validate_self_should_error('Lorem ipsum')
280
+ end
281
+
282
+ def test_enum_schema
283
+ schema :string, enum: [1, 2, 'foo', :bar, { qux: 42 }]
284
+
285
+ assert_json({
286
+ type: :string,
287
+ enum: [1, 2, 'foo', :bar, { qux: 42 }]
288
+ })
289
+
290
+ assert_validation(nil)
291
+ assert_validation('foo')
292
+
293
+ # Even we put those types in the enum, they need to fail the validations,
294
+ # as they are not strings
295
+ assert_validation(1) do
296
+ error '/', 'Invalid type, expected "string".'
297
+ end
298
+ assert_validation(:bar) do
299
+ error '/', 'Invalid type, expected "string".'
300
+ end
301
+ assert_validation({ qux: 42 }) do
302
+ error '/', 'Invalid type, expected "string".'
303
+ end
304
+
305
+ # These need to fail validation, as they are not in the enum list
306
+ assert_validation('bar') do
307
+ error '/', 'Value not included in enum [1, 2, "foo", :bar, {:qux=>42}].'
308
+ end
309
+ assert_validation('Lorem ipsum') do
310
+ error '/', 'Value not included in enum [1, 2, "foo", :bar, {:qux=>42}].'
311
+ end
312
+ end
313
+
314
+ def test_with_generic_keywords
315
+ schema :string, enum: [1, 'foo'],
316
+ title: 'String schema',
317
+ description: 'String schema holding generic keywords',
318
+ examples: [
319
+ 'foo'
320
+ ]
321
+
322
+ assert_json({
323
+ type: :string,
324
+ enum: [1, 'foo'],
325
+ title: 'String schema',
326
+ description: 'String schema holding generic keywords',
327
+ examples: [
328
+ 'foo'
329
+ ]
330
+ })
331
+ end
332
+ end
333
+ end
334
+ end
@@ -0,0 +1,75 @@
1
+ require 'test_helper'
2
+
3
+ module Schemacop
4
+ module V3
5
+ class SymbolNodeTest < V3Test
6
+ EXP_INVALID_TYPE = 'Invalid type, expected "Symbol".'.freeze
7
+
8
+ def test_basic
9
+ schema :symbol
10
+
11
+ assert_validation :foo
12
+ assert_validation :'n0238n)Q(hqr3hrw3'
13
+ assert_validation 42 do
14
+ error '/', EXP_INVALID_TYPE
15
+ end
16
+ assert_validation '42' do
17
+ error '/', EXP_INVALID_TYPE
18
+ end
19
+ assert_json({})
20
+ end
21
+
22
+ def test_required
23
+ schema :symbol, required: true
24
+ assert_validation :foo
25
+ assert_validation ''.to_sym
26
+ assert_validation nil do
27
+ error '/', 'Value must be given.'
28
+ end
29
+ end
30
+
31
+ def test_hash
32
+ schema { sym! :name }
33
+ assert_validation name: :foo
34
+ assert_json(type: :object, properties: { name: {} }, required: %i[name], additionalProperties: false)
35
+ end
36
+
37
+ def test_array
38
+ schema(:array) do
39
+ list :symbol
40
+ end
41
+
42
+ assert_validation %i[foo bar baz]
43
+ assert_json(type: :array, items: {})
44
+ end
45
+
46
+ def test_enum_schema
47
+ schema :symbol, enum: [1, 2, 'foo', :bar, { qux: 42 }]
48
+
49
+ # For symbol nodes, json representation is an empty hash, as we can't
50
+ # repsresent symbols in json
51
+ assert_json({})
52
+
53
+ assert_validation(nil)
54
+ assert_validation(:bar)
55
+
56
+ # Even we put those types in the enum, they need to fail the validations,
57
+ # as they are not symbols
58
+ assert_validation('foo') do
59
+ error '/', 'Invalid type, expected "Symbol".'
60
+ end
61
+ assert_validation(1) do
62
+ error '/', 'Invalid type, expected "Symbol".'
63
+ end
64
+ assert_validation({ qux: 42 }) do
65
+ error '/', 'Invalid type, expected "Symbol".'
66
+ end
67
+
68
+ # These need to fail validation, as they are not in the enum list
69
+ assert_validation(:foo) do
70
+ error '/', 'Value not included in enum [1, 2, "foo", :bar, {:qux=>42}].'
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: schemacop
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.6
4
+ version: 3.0.0.rc3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sitrox
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-29 00:00:00.000000000 Z
11
+ date: 2021-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -26,20 +26,6 @@ dependencies:
26
26
  version: '4.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '1.3'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '1.3'
41
- - !ruby/object:Gem::Dependency
42
- name: rake
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
31
  - - ">="
@@ -53,21 +39,7 @@ dependencies:
53
39
  - !ruby/object:Gem::Version
54
40
  version: '0'
55
41
  - !ruby/object:Gem::Dependency
56
- name: ci_reporter
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '2.0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '2.0'
69
- - !ruby/object:Gem::Dependency
70
- name: ci_reporter_minitest
42
+ name: rake
71
43
  requirement: !ruby/object:Gem::Requirement
72
44
  requirements:
73
45
  - - ">="
@@ -81,7 +53,7 @@ dependencies:
81
53
  - !ruby/object:Gem::Version
82
54
  version: '0'
83
55
  - !ruby/object:Gem::Dependency
84
- name: haml
56
+ name: minitest
85
57
  requirement: !ruby/object:Gem::Requirement
86
58
  requirements:
87
59
  - - ">="
@@ -95,7 +67,7 @@ dependencies:
95
67
  - !ruby/object:Gem::Version
96
68
  version: '0'
97
69
  - !ruby/object:Gem::Dependency
98
- name: colorize
70
+ name: minitest-reporters
99
71
  requirement: !ruby/object:Gem::Requirement
100
72
  requirements:
101
73
  - - ">="
@@ -109,7 +81,7 @@ dependencies:
109
81
  - !ruby/object:Gem::Version
110
82
  version: '0'
111
83
  - !ruby/object:Gem::Dependency
112
- name: yard
84
+ name: colorize
113
85
  requirement: !ruby/object:Gem::Requirement
114
86
  requirements:
115
87
  - - ">="
@@ -128,16 +100,16 @@ dependencies:
128
100
  requirements:
129
101
  - - '='
130
102
  - !ruby/object:Gem::Version
131
- version: 0.35.1
103
+ version: 0.92.0
132
104
  type: :development
133
105
  prerelease: false
134
106
  version_requirements: !ruby/object:Gem::Requirement
135
107
  requirements:
136
108
  - - '='
137
109
  - !ruby/object:Gem::Version
138
- version: 0.35.1
110
+ version: 0.92.0
139
111
  - !ruby/object:Gem::Dependency
140
- name: redcarpet
112
+ name: pry
141
113
  requirement: !ruby/object:Gem::Requirement
142
114
  requirements:
143
115
  - - ">="
@@ -151,7 +123,7 @@ dependencies:
151
123
  - !ruby/object:Gem::Version
152
124
  version: '0'
153
125
  - !ruby/object:Gem::Dependency
154
- name: pry
126
+ name: byebug
155
127
  requirement: !ruby/object:Gem::Requirement
156
128
  requirements:
157
129
  - - ">="
@@ -164,8 +136,22 @@ dependencies:
164
136
  - - ">="
165
137
  - !ruby/object:Gem::Version
166
138
  version: '0'
167
- description:
168
- email:
139
+ - !ruby/object:Gem::Dependency
140
+ name: simplecov
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - '='
144
+ - !ruby/object:Gem::Version
145
+ version: 0.21.2
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - '='
151
+ - !ruby/object:Gem::Version
152
+ version: 0.21.2
153
+ description:
154
+ email:
169
155
  executables: []
170
156
  extensions: []
171
157
  extra_rdoc_files: []
@@ -179,102 +165,106 @@ files:
179
165
  - Gemfile
180
166
  - LICENSE
181
167
  - README.md
168
+ - README_V2.md
169
+ - README_V3.md
182
170
  - RUBY_VERSION
183
171
  - Rakefile
184
172
  - VERSION
185
- - doc/Schemacop.html
186
- - doc/Schemacop/ArrayValidator.html
187
- - doc/Schemacop/BooleanValidator.html
188
- - doc/Schemacop/Caster.html
189
- - doc/Schemacop/Collector.html
190
- - doc/Schemacop/Dupper.html
191
- - doc/Schemacop/Exceptions.html
192
- - doc/Schemacop/Exceptions/InvalidSchemaError.html
193
- - doc/Schemacop/Exceptions/ValidationError.html
194
- - doc/Schemacop/FieldNode.html
195
- - doc/Schemacop/FloatValidator.html
196
- - doc/Schemacop/HashValidator.html
197
- - doc/Schemacop/IntegerValidator.html
198
- - doc/Schemacop/NilValidator.html
199
- - doc/Schemacop/Node.html
200
- - doc/Schemacop/NodeResolver.html
201
- - doc/Schemacop/NodeSupportingField.html
202
- - doc/Schemacop/NodeSupportingType.html
203
- - doc/Schemacop/NodeWithBlock.html
204
- - doc/Schemacop/NumberValidator.html
205
- - doc/Schemacop/ObjectValidator.html
206
- - doc/Schemacop/RootNode.html
207
- - doc/Schemacop/Schema.html
208
- - doc/Schemacop/StringValidator.html
209
- - doc/Schemacop/SymbolValidator.html
210
- - doc/ScopedEnv.html
211
- - doc/_index.html
212
- - doc/class_list.html
213
- - doc/css/common.css
214
- - doc/css/full_list.css
215
- - doc/css/style.css
216
- - doc/file.README.html
217
- - doc/file_list.html
218
- - doc/frames.html
219
- - doc/index.html
220
- - doc/inheritance.graphml
221
- - doc/inheritance.pdf
222
- - doc/js/app.js
223
- - doc/js/full_list.js
224
- - doc/js/jquery.js
225
- - doc/method_list.html
226
- - doc/top-level-namespace.html
227
173
  - lib/schemacop.rb
228
- - lib/schemacop/caster.rb
229
- - lib/schemacop/collector.rb
230
- - lib/schemacop/dupper.rb
174
+ - lib/schemacop/base_schema.rb
231
175
  - lib/schemacop/exceptions.rb
232
- - lib/schemacop/field_node.rb
233
- - lib/schemacop/node.rb
234
- - lib/schemacop/node_resolver.rb
235
- - lib/schemacop/node_supporting_field.rb
236
- - lib/schemacop/node_supporting_type.rb
237
- - lib/schemacop/node_with_block.rb
238
- - lib/schemacop/root_node.rb
176
+ - lib/schemacop/railtie.rb
239
177
  - lib/schemacop/schema.rb
178
+ - lib/schemacop/schema2.rb
179
+ - lib/schemacop/schema3.rb
240
180
  - lib/schemacop/scoped_env.rb
241
- - lib/schemacop/validator/array_validator.rb
242
- - lib/schemacop/validator/boolean_validator.rb
243
- - lib/schemacop/validator/float_validator.rb
244
- - lib/schemacop/validator/hash_validator.rb
245
- - lib/schemacop/validator/integer_validator.rb
246
- - lib/schemacop/validator/nil_validator.rb
247
- - lib/schemacop/validator/number_validator.rb
248
- - lib/schemacop/validator/object_validator.rb
249
- - lib/schemacop/validator/string_validator.rb
250
- - lib/schemacop/validator/symbol_validator.rb
181
+ - lib/schemacop/v2.rb
182
+ - lib/schemacop/v2/caster.rb
183
+ - lib/schemacop/v2/collector.rb
184
+ - lib/schemacop/v2/dupper.rb
185
+ - lib/schemacop/v2/field_node.rb
186
+ - lib/schemacop/v2/node.rb
187
+ - lib/schemacop/v2/node_resolver.rb
188
+ - lib/schemacop/v2/node_supporting_field.rb
189
+ - lib/schemacop/v2/node_supporting_type.rb
190
+ - lib/schemacop/v2/node_with_block.rb
191
+ - lib/schemacop/v2/root_node.rb
192
+ - lib/schemacop/v2/validator/array_validator.rb
193
+ - lib/schemacop/v2/validator/boolean_validator.rb
194
+ - lib/schemacop/v2/validator/float_validator.rb
195
+ - lib/schemacop/v2/validator/hash_validator.rb
196
+ - lib/schemacop/v2/validator/integer_validator.rb
197
+ - lib/schemacop/v2/validator/nil_validator.rb
198
+ - lib/schemacop/v2/validator/number_validator.rb
199
+ - lib/schemacop/v2/validator/object_validator.rb
200
+ - lib/schemacop/v2/validator/string_validator.rb
201
+ - lib/schemacop/v2/validator/symbol_validator.rb
202
+ - lib/schemacop/v3.rb
203
+ - lib/schemacop/v3/all_of_node.rb
204
+ - lib/schemacop/v3/any_of_node.rb
205
+ - lib/schemacop/v3/array_node.rb
206
+ - lib/schemacop/v3/boolean_node.rb
207
+ - lib/schemacop/v3/combination_node.rb
208
+ - lib/schemacop/v3/context.rb
209
+ - lib/schemacop/v3/dsl_scope.rb
210
+ - lib/schemacop/v3/global_context.rb
211
+ - lib/schemacop/v3/hash_node.rb
212
+ - lib/schemacop/v3/integer_node.rb
213
+ - lib/schemacop/v3/is_not_node.rb
214
+ - lib/schemacop/v3/node.rb
215
+ - lib/schemacop/v3/node_registry.rb
216
+ - lib/schemacop/v3/number_node.rb
217
+ - lib/schemacop/v3/numeric_node.rb
218
+ - lib/schemacop/v3/object_node.rb
219
+ - lib/schemacop/v3/one_of_node.rb
220
+ - lib/schemacop/v3/reference_node.rb
221
+ - lib/schemacop/v3/result.rb
222
+ - lib/schemacop/v3/string_node.rb
223
+ - lib/schemacop/v3/symbol_node.rb
251
224
  - schemacop.gemspec
252
- - test/casting_test.rb
253
- - test/collector_test.rb
254
- - test/custom_check_test.rb
255
- - test/custom_if_test.rb
256
- - test/defaults_test.rb
257
- - test/empty_test.rb
258
- - test/nil_dis_allow_test.rb
259
- - test/node_resolver_test.rb
260
- - test/short_forms_test.rb
261
- - test/test_helper.rb
262
- - test/types_test.rb
263
- - test/validator_array_test.rb
264
- - test/validator_boolean_test.rb
265
- - test/validator_float_test.rb
266
- - test/validator_hash_test.rb
267
- - test/validator_integer_test.rb
268
- - test/validator_nil_test.rb
269
- - test/validator_number_test.rb
270
- - test/validator_object_test.rb
271
- - test/validator_string_test.rb
272
- - test/validator_symbol_test.rb
225
+ - test/lib/test_helper.rb
226
+ - test/schemas/nested/group.rb
227
+ - test/schemas/user.rb
228
+ - test/unit/schemacop/v2/casting_test.rb
229
+ - test/unit/schemacop/v2/collector_test.rb
230
+ - test/unit/schemacop/v2/custom_check_test.rb
231
+ - test/unit/schemacop/v2/custom_if_test.rb
232
+ - test/unit/schemacop/v2/defaults_test.rb
233
+ - test/unit/schemacop/v2/empty_test.rb
234
+ - test/unit/schemacop/v2/nil_dis_allow_test.rb
235
+ - test/unit/schemacop/v2/node_resolver_test.rb
236
+ - test/unit/schemacop/v2/short_forms_test.rb
237
+ - test/unit/schemacop/v2/types_test.rb
238
+ - test/unit/schemacop/v2/validator_array_test.rb
239
+ - test/unit/schemacop/v2/validator_boolean_test.rb
240
+ - test/unit/schemacop/v2/validator_float_test.rb
241
+ - test/unit/schemacop/v2/validator_hash_test.rb
242
+ - test/unit/schemacop/v2/validator_integer_test.rb
243
+ - test/unit/schemacop/v2/validator_nil_test.rb
244
+ - test/unit/schemacop/v2/validator_number_test.rb
245
+ - test/unit/schemacop/v2/validator_object_test.rb
246
+ - test/unit/schemacop/v2/validator_string_test.rb
247
+ - test/unit/schemacop/v2/validator_symbol_test.rb
248
+ - test/unit/schemacop/v3/all_of_node_test.rb
249
+ - test/unit/schemacop/v3/any_of_node_test.rb
250
+ - test/unit/schemacop/v3/array_node_test.rb
251
+ - test/unit/schemacop/v3/boolean_node_test.rb
252
+ - test/unit/schemacop/v3/global_context_test.rb
253
+ - test/unit/schemacop/v3/hash_node_test.rb
254
+ - test/unit/schemacop/v3/integer_node_test.rb
255
+ - test/unit/schemacop/v3/is_not_node_test.rb
256
+ - test/unit/schemacop/v3/node_test.rb
257
+ - test/unit/schemacop/v3/number_node_test.rb
258
+ - test/unit/schemacop/v3/object_node_test.rb
259
+ - test/unit/schemacop/v3/one_of_node_test.rb
260
+ - test/unit/schemacop/v3/reference_node_test.rb
261
+ - test/unit/schemacop/v3/string_node_test.rb
262
+ - test/unit/schemacop/v3/symbol_node_test.rb
273
263
  homepage: https://github.com/sitrox/schemacop
274
264
  licenses:
275
265
  - MIT
276
266
  metadata: {}
277
- post_install_message:
267
+ post_install_message:
278
268
  rdoc_options: []
279
269
  require_paths:
280
270
  - lib
@@ -285,34 +275,51 @@ required_ruby_version: !ruby/object:Gem::Requirement
285
275
  version: '0'
286
276
  required_rubygems_version: !ruby/object:Gem::Requirement
287
277
  requirements:
288
- - - ">="
278
+ - - ">"
289
279
  - !ruby/object:Gem::Version
290
- version: '0'
280
+ version: 1.3.1
291
281
  requirements: []
292
- rubygems_version: 3.1.2
293
- signing_key:
282
+ rubygems_version: 3.1.4
283
+ signing_key:
294
284
  specification_version: 4
295
285
  summary: Schemacop validates ruby structures consisting of nested hashes and arrays
296
286
  against simple schema definitions.
297
287
  test_files:
298
- - test/casting_test.rb
299
- - test/collector_test.rb
300
- - test/custom_check_test.rb
301
- - test/custom_if_test.rb
302
- - test/defaults_test.rb
303
- - test/empty_test.rb
304
- - test/nil_dis_allow_test.rb
305
- - test/node_resolver_test.rb
306
- - test/short_forms_test.rb
307
- - test/test_helper.rb
308
- - test/types_test.rb
309
- - test/validator_array_test.rb
310
- - test/validator_boolean_test.rb
311
- - test/validator_float_test.rb
312
- - test/validator_hash_test.rb
313
- - test/validator_integer_test.rb
314
- - test/validator_nil_test.rb
315
- - test/validator_number_test.rb
316
- - test/validator_object_test.rb
317
- - test/validator_string_test.rb
318
- - test/validator_symbol_test.rb
288
+ - test/lib/test_helper.rb
289
+ - test/schemas/nested/group.rb
290
+ - test/schemas/user.rb
291
+ - test/unit/schemacop/v2/casting_test.rb
292
+ - test/unit/schemacop/v2/collector_test.rb
293
+ - test/unit/schemacop/v2/custom_check_test.rb
294
+ - test/unit/schemacop/v2/custom_if_test.rb
295
+ - test/unit/schemacop/v2/defaults_test.rb
296
+ - test/unit/schemacop/v2/empty_test.rb
297
+ - test/unit/schemacop/v2/nil_dis_allow_test.rb
298
+ - test/unit/schemacop/v2/node_resolver_test.rb
299
+ - test/unit/schemacop/v2/short_forms_test.rb
300
+ - test/unit/schemacop/v2/types_test.rb
301
+ - test/unit/schemacop/v2/validator_array_test.rb
302
+ - test/unit/schemacop/v2/validator_boolean_test.rb
303
+ - test/unit/schemacop/v2/validator_float_test.rb
304
+ - test/unit/schemacop/v2/validator_hash_test.rb
305
+ - test/unit/schemacop/v2/validator_integer_test.rb
306
+ - test/unit/schemacop/v2/validator_nil_test.rb
307
+ - test/unit/schemacop/v2/validator_number_test.rb
308
+ - test/unit/schemacop/v2/validator_object_test.rb
309
+ - test/unit/schemacop/v2/validator_string_test.rb
310
+ - test/unit/schemacop/v2/validator_symbol_test.rb
311
+ - test/unit/schemacop/v3/all_of_node_test.rb
312
+ - test/unit/schemacop/v3/any_of_node_test.rb
313
+ - test/unit/schemacop/v3/array_node_test.rb
314
+ - test/unit/schemacop/v3/boolean_node_test.rb
315
+ - test/unit/schemacop/v3/global_context_test.rb
316
+ - test/unit/schemacop/v3/hash_node_test.rb
317
+ - test/unit/schemacop/v3/integer_node_test.rb
318
+ - test/unit/schemacop/v3/is_not_node_test.rb
319
+ - test/unit/schemacop/v3/node_test.rb
320
+ - test/unit/schemacop/v3/number_node_test.rb
321
+ - test/unit/schemacop/v3/object_node_test.rb
322
+ - test/unit/schemacop/v3/one_of_node_test.rb
323
+ - test/unit/schemacop/v3/reference_node_test.rb
324
+ - test/unit/schemacop/v3/string_node_test.rb
325
+ - test/unit/schemacop/v3/symbol_node_test.rb