json-schema 3.0.0 → 4.1.1

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.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +15 -1
  3. data/lib/json-schema/attribute.rb +13 -14
  4. data/lib/json-schema/attributes/additionalitems.rb +1 -0
  5. data/lib/json-schema/attributes/additionalproperties.rb +3 -6
  6. data/lib/json-schema/attributes/allof.rb +6 -4
  7. data/lib/json-schema/attributes/anyof.rb +2 -2
  8. data/lib/json-schema/attributes/dependencies.rb +1 -0
  9. data/lib/json-schema/attributes/disallow.rb +2 -1
  10. data/lib/json-schema/attributes/enum.rb +2 -2
  11. data/lib/json-schema/attributes/extends.rb +6 -6
  12. data/lib/json-schema/attributes/format.rb +2 -1
  13. data/lib/json-schema/attributes/formats/date.rb +1 -0
  14. data/lib/json-schema/attributes/formats/date_time.rb +2 -1
  15. data/lib/json-schema/attributes/formats/date_time_v4.rb +1 -0
  16. data/lib/json-schema/attributes/formats/uri.rb +1 -0
  17. data/lib/json-schema/attributes/items.rb +1 -0
  18. data/lib/json-schema/attributes/limits/numeric.rb +1 -1
  19. data/lib/json-schema/attributes/maxdecimal.rb +1 -1
  20. data/lib/json-schema/attributes/not.rb +2 -2
  21. data/lib/json-schema/attributes/oneof.rb +2 -4
  22. data/lib/json-schema/attributes/patternproperties.rb +1 -0
  23. data/lib/json-schema/attributes/properties.rb +7 -7
  24. data/lib/json-schema/attributes/properties_v4.rb +1 -1
  25. data/lib/json-schema/attributes/propertynames.rb +23 -0
  26. data/lib/json-schema/attributes/ref.rb +7 -7
  27. data/lib/json-schema/attributes/required.rb +3 -2
  28. data/lib/json-schema/attributes/type.rb +3 -2
  29. data/lib/json-schema/attributes/type_v4.rb +1 -1
  30. data/lib/json-schema/errors/validation_error.rb +4 -5
  31. data/lib/json-schema/schema/reader.rb +2 -0
  32. data/lib/json-schema/schema/validator.rb +3 -3
  33. data/lib/json-schema/schema.rb +3 -4
  34. data/lib/json-schema/util/array_set.rb +1 -1
  35. data/lib/json-schema/util/uri.rb +7 -7
  36. data/lib/json-schema/util/uuid.rb +227 -226
  37. data/lib/json-schema/validator.rb +97 -84
  38. data/lib/json-schema/validators/draft1.rb +21 -23
  39. data/lib/json-schema/validators/draft2.rb +22 -24
  40. data/lib/json-schema/validators/draft3.rb +26 -28
  41. data/lib/json-schema/validators/draft4.rb +34 -36
  42. data/lib/json-schema/validators/draft6.rb +36 -37
  43. data/lib/json-schema/validators/hyper-draft1.rb +2 -3
  44. data/lib/json-schema/validators/hyper-draft2.rb +2 -3
  45. data/lib/json-schema/validators/hyper-draft3.rb +2 -3
  46. data/lib/json-schema/validators/hyper-draft4.rb +2 -3
  47. data/lib/json-schema/validators/hyper-draft6.rb +2 -3
  48. data/lib/json-schema.rb +2 -2
  49. data/resources/draft-06.json +12 -12
  50. metadata +7 -6
@@ -15,21 +15,22 @@ require 'json-schema/errors/json_parse_error'
15
15
  require 'json-schema/util/uri'
16
16
 
17
17
  module JSON
18
-
19
18
  class Validator
20
-
21
19
  @@schemas = {}
22
20
  @@cache_schemas = true
23
21
  @@default_opts = {
24
- :list => false,
25
- :version => nil,
26
- :validate_schema => false,
27
- :record_errors => false,
28
- :errors_as_objects => false,
29
- :insert_defaults => false,
30
- :clear_cache => false,
31
- :strict => false,
32
- :parse_data => true
22
+ list: false,
23
+ version: nil,
24
+ validate_schema: false,
25
+ record_errors: false,
26
+ errors_as_objects: false,
27
+ insert_defaults: false,
28
+ clear_cache: false,
29
+ strict: false,
30
+ allPropertiesRequired: false,
31
+ noAdditionalProperties: false,
32
+ parse_data: true,
33
+ parse_integer: true,
33
34
  }
34
35
  @@validators = {}
35
36
  @@default_validator = nil
@@ -38,28 +39,32 @@ module JSON
38
39
  @@serializer = nil
39
40
  @@mutex = Mutex.new
40
41
 
41
- def initialize(schema_data, data, opts={})
42
+ def initialize(schema_data, opts = {})
42
43
  @options = @@default_opts.clone.merge(opts)
43
44
  @errors = []
44
45
 
45
46
  configured_validator = self.class.validator_for_name(@options[:version])
46
47
  @options[:schema_reader] ||= self.class.schema_reader
47
48
 
48
- @validation_options = @options[:record_errors] ? {:record_errors => true} : {}
49
+ @validation_options = @options[:record_errors] ? { record_errors: true } : {}
49
50
  @validation_options[:insert_defaults] = true if @options[:insert_defaults]
50
- @validation_options[:strict] = true if @options[:strict] == true
51
+ if @options[:strict] == true
52
+ @validation_options[:allPropertiesRequired] = true
53
+ @validation_options[:noAdditionalProperties] = true
54
+ else
55
+ @validation_options[:allPropertiesRequired] = true if @options[:allPropertiesRequired]
56
+ @validation_options[:noAdditionalProperties] = true if @options[:noAdditionalProperties]
57
+ end
51
58
  @validation_options[:clear_cache] = true if !@@cache_schemas || @options[:clear_cache]
52
59
 
53
60
  @@mutex.synchronize { @base_schema = initialize_schema(schema_data, configured_validator) }
54
- @original_data = data
55
- @data = initialize_data(data)
56
61
  @@mutex.synchronize { build_schemas(@base_schema) }
57
62
 
58
63
  # validate the schema, if requested
59
64
  if @options[:validate_schema]
60
65
  # Don't clear the cache during metaschema validation!
61
- meta_validator = self.class.new(@base_schema.validator.metaschema, @base_schema.schema, {:clear_cache => false})
62
- meta_validator.validate
66
+ meta_validator = self.class.new(@base_schema.validator.metaschema, { clear_cache: false })
67
+ meta_validator.validate(@base_schema.schema)
63
68
  end
64
69
 
65
70
  # If the :fragment option is set, try and validate against the fragment
@@ -70,11 +75,11 @@ module JSON
70
75
 
71
76
  def schema_from_fragment(base_schema, fragment)
72
77
  schema_uri = base_schema.uri
73
- fragments = fragment.split("/").map { |f| f.gsub('~0', '~').gsub('~1', '/') }
78
+ fragments = fragment.split('/').map { |f| f.gsub('~0', '~').gsub('~1', '/') }
74
79
 
75
80
  # ensure the first element was a hash, per the fragment spec
76
- if fragments.shift != "#"
77
- raise JSON::Schema::SchemaError.new("Invalid fragment syntax in :fragment option")
81
+ if fragments.shift != '#'
82
+ raise JSON::Schema::SchemaError, 'Invalid fragment syntax in :fragment option'
78
83
  end
79
84
 
80
85
  schema_fragment = base_schema.schema
@@ -88,7 +93,7 @@ module JSON
88
93
  end
89
94
 
90
95
  unless schema_fragment.is_a?(Hash)
91
- raise JSON::Schema::SchemaError.new("Invalid fragment resolution for :fragment option")
96
+ raise JSON::Schema::SchemaError, 'Invalid fragment resolution for :fragment option'
92
97
  end
93
98
 
94
99
  schema = JSON::Schema.new(schema_fragment, schema_uri, base_schema.validator)
@@ -103,24 +108,28 @@ module JSON
103
108
  end
104
109
 
105
110
  # Run a simple true/false validation of data against a schema
106
- def validate
107
- @base_schema.validate(@data,[],self,@validation_options)
111
+ def validate(data)
112
+ original_data = data
113
+ data = initialize_data(data)
114
+ @base_schema.validate(data, [], self, @validation_options)
108
115
 
109
116
  if @options[:record_errors]
110
117
  if @options[:errors_as_objects]
111
- @errors.map{|e| e.to_hash}
118
+ @errors.map { |e| e.to_hash }
112
119
  else
113
- @errors.map{|e| e.to_string}
120
+ @errors.map { |e| e.to_string }
114
121
  end
115
122
  else
116
123
  true
117
124
  end
118
125
  ensure
126
+ @errors = []
127
+
119
128
  if @validation_options[:clear_cache] == true
120
129
  self.class.clear_cache
121
130
  end
122
131
  if @validation_options[:insert_defaults]
123
- self.class.merge_missing_values(@data, @original_data)
132
+ self.class.merge_missing_values(data, original_data)
124
133
  end
125
134
  end
126
135
 
@@ -141,13 +150,13 @@ module JSON
141
150
  schema = parent_schema.schema
142
151
 
143
152
  # Build ref schemas if they exist
144
- if schema["$ref"]
145
- load_ref_schema(parent_schema, schema["$ref"])
153
+ if schema['$ref']
154
+ load_ref_schema(parent_schema, schema['$ref'])
146
155
  end
147
156
 
148
- case schema["extends"]
157
+ case schema['extends']
149
158
  when String
150
- load_ref_schema(parent_schema, schema["extends"])
159
+ load_ref_schema(parent_schema, schema['extends'])
151
160
  when Array
152
161
  schema['extends'].each do |type|
153
162
  handle_schema(parent_schema, type)
@@ -155,7 +164,7 @@ module JSON
155
164
  end
156
165
 
157
166
  # Check for schemas in union types
158
- ["type", "disallow"].each do |key|
167
+ %w[type disallow].each do |key|
159
168
  if schema[key].is_a?(Array)
160
169
  schema[key].each do |type|
161
170
  if type.is_a?(Hash)
@@ -169,6 +178,7 @@ module JSON
169
178
  # are themselves schemas.
170
179
  %w[definitions properties patternProperties].each do |key|
171
180
  next unless value = schema[key]
181
+
172
182
  value.each do |k, inner_schema|
173
183
  handle_schema(parent_schema, inner_schema)
174
184
  end
@@ -177,20 +187,22 @@ module JSON
177
187
  # Schema properties whose values are themselves schemas.
178
188
  %w[additionalProperties additionalItems dependencies extends].each do |key|
179
189
  next unless schema[key].is_a?(Hash)
190
+
180
191
  handle_schema(parent_schema, schema[key])
181
192
  end
182
193
 
183
194
  # Schema properties whose values may be an array of schemas.
184
195
  %w[allOf anyOf oneOf not].each do |key|
185
196
  next unless value = schema[key]
197
+
186
198
  Array(value).each do |inner_schema|
187
199
  handle_schema(parent_schema, inner_schema)
188
200
  end
189
201
  end
190
202
 
191
203
  # Items are always schemas
192
- if schema["items"]
193
- items = schema["items"].clone
204
+ if schema['items']
205
+ items = schema['items'].clone
194
206
  items = [items] unless items.is_a?(Array)
195
207
 
196
208
  items.each do |item|
@@ -199,10 +211,9 @@ module JSON
199
211
  end
200
212
 
201
213
  # Convert enum to a ArraySet
202
- if schema["enum"].is_a?(Array)
203
- schema["enum"] = ArraySet.new(schema["enum"])
214
+ if schema['enum'].is_a?(Array)
215
+ schema['enum'] = ArraySet.new(schema['enum'])
204
216
  end
205
-
206
217
  end
207
218
 
208
219
  # Either load a reference schema or create a new schema
@@ -225,58 +236,57 @@ module JSON
225
236
  @errors
226
237
  end
227
238
 
228
-
229
239
  class << self
230
- def validate(schema, data,opts={})
240
+ def validate(schema, data, opts = {})
231
241
  begin
232
242
  validate!(schema, data, opts)
233
243
  rescue JSON::Schema::ValidationError, JSON::Schema::SchemaError
234
- return false
244
+ false
235
245
  end
236
246
  end
237
247
 
238
- def validate_json(schema, data, opts={})
239
- validate(schema, data, opts.merge(:json => true))
248
+ def validate_json(schema, data, opts = {})
249
+ validate(schema, data, opts.merge(json: true))
240
250
  end
241
251
 
242
- def validate_uri(schema, data, opts={})
243
- validate(schema, data, opts.merge(:uri => true))
252
+ def validate_uri(schema, data, opts = {})
253
+ validate(schema, data, opts.merge(uri: true))
244
254
  end
245
255
 
246
- def validate!(schema, data,opts={})
247
- validator = new(schema, data, opts)
248
- validator.validate
256
+ def validate!(schema, data, opts = {})
257
+ validator = new(schema, opts)
258
+ validator.validate(data)
249
259
  end
250
260
 
251
- def validate2(schema, data, opts={})
252
- warn "[DEPRECATION NOTICE] JSON::Validator#validate2 has been replaced by JSON::Validator#validate! and will be removed in version >= 3. Please use the #validate! method instead."
261
+ def validate2(schema, data, opts = {})
262
+ warn '[DEPRECATION NOTICE] JSON::Validator#validate2 has been replaced by JSON::Validator#validate! and will be removed in version >= 3. Please use the #validate! method instead.'
253
263
  validate!(schema, data, opts)
254
264
  end
255
265
 
256
- def validate_json!(schema, data, opts={})
257
- validate!(schema, data, opts.merge(:json => true))
266
+ def validate_json!(schema, data, opts = {})
267
+ validate!(schema, data, opts.merge(json: true))
258
268
  end
259
269
 
260
- def validate_uri!(schema, data, opts={})
261
- validate!(schema, data, opts.merge(:uri => true))
270
+ def validate_uri!(schema, data, opts = {})
271
+ validate!(schema, data, opts.merge(uri: true))
262
272
  end
263
273
 
264
- def fully_validate(schema, data, opts={})
265
- validate!(schema, data, opts.merge(:record_errors => true))
274
+ def fully_validate(schema, data, opts = {})
275
+ validate!(schema, data, opts.merge(record_errors: true))
266
276
  end
267
277
 
268
- def fully_validate_schema(schema, opts={})
278
+ def fully_validate_schema(schema, opts = {})
269
279
  data = schema
270
280
  schema = validator_for_name(opts[:version]).metaschema
271
281
  fully_validate(schema, data, opts)
272
282
  end
273
283
 
274
- def fully_validate_json(schema, data, opts={})
275
- fully_validate(schema, data, opts.merge(:json => true))
284
+ def fully_validate_json(schema, data, opts = {})
285
+ fully_validate(schema, data, opts.merge(json: true))
276
286
  end
277
287
 
278
- def fully_validate_uri(schema, data, opts={})
279
- fully_validate(schema, data, opts.merge(:uri => true))
288
+ def fully_validate_uri(schema, data, opts = {})
289
+ fully_validate(schema, data, opts.merge(uri: true))
280
290
  end
281
291
 
282
292
  def schema_reader
@@ -316,7 +326,7 @@ module JSON
316
326
  end
317
327
 
318
328
  def cache_schemas=(val)
319
- warn "[DEPRECATION NOTICE] Schema caching is now a validation option. Schemas will still be cached if this is set to true, but this method will be removed in version >= 3. Please use the :clear_cache validation option instead."
329
+ warn '[DEPRECATION NOTICE] Schema caching is now a validation option. Schemas will still be cached if this is set to true, but this method will be removed in version >= 3. Please use the :clear_cache validation option instead.'
320
330
  @@cache_schemas = val == true ? true : false
321
331
  end
322
332
 
@@ -328,32 +338,34 @@ module JSON
328
338
  @@default_validator
329
339
  end
330
340
 
331
- def validator_for_uri(schema_uri, raise_not_found=true)
341
+ def validator_for_uri(schema_uri, raise_not_found = true)
332
342
  return default_validator unless schema_uri
343
+
333
344
  u = JSON::Util::URI.parse(schema_uri)
334
345
  validator = validators["#{u.scheme}://#{u.host}#{u.path}"]
335
346
  if validator.nil? && raise_not_found
336
- raise JSON::Schema::SchemaError.new("Schema not found: #{schema_uri}")
347
+ raise JSON::Schema::SchemaError, "Schema not found: #{schema_uri}"
337
348
  else
338
349
  validator
339
350
  end
340
351
  end
341
352
 
342
- def validator_for_name(schema_name, raise_not_found=true)
353
+ def validator_for_name(schema_name, raise_not_found = true)
343
354
  return default_validator unless schema_name
355
+
344
356
  schema_name = schema_name.to_s
345
357
  validator = validators.values.detect do |v|
346
358
  Array(v.names).include?(schema_name)
347
359
  end
348
360
  if validator.nil? && raise_not_found
349
- raise JSON::Schema::SchemaError.new("The requested JSON schema version is not supported")
361
+ raise JSON::Schema::SchemaError, 'The requested JSON schema version is not supported'
350
362
  else
351
363
  validator
352
364
  end
353
365
  end
354
366
 
355
367
  def validator_for(schema_uri)
356
- warn "[DEPRECATION NOTICE] JSON::Validator#validator_for has been replaced by JSON::Validator#validator_for_uri and will be removed in version >= 3. Please use the #validator_for_uri method instead."
368
+ warn '[DEPRECATION NOTICE] JSON::Validator#validator_for has been replaced by JSON::Validator#validator_for_uri and will be removed in version >= 3. Please use the #validator_for_uri method instead.'
357
369
  validator_for_uri(schema_uri)
358
370
  end
359
371
 
@@ -365,7 +377,7 @@ module JSON
365
377
  @@default_validator = v
366
378
  end
367
379
 
368
- def register_format_validator(format, validation_proc, versions = (@@validators.flat_map{ |k, v| v.names.first } + [nil]))
380
+ def register_format_validator(format, validation_proc, versions = (@@validators.flat_map { |k, v| v.names.first } + [nil]))
369
381
  custom_format_validator = JSON::Schema::CustomFormat.new(validation_proc)
370
382
  versions.each do |version|
371
383
  validator = validator_for_name(version)
@@ -373,14 +385,14 @@ module JSON
373
385
  end
374
386
  end
375
387
 
376
- def deregister_format_validator(format, versions = (@@validators.flat_map{ |k, v| v.names.first } + [nil]))
388
+ def deregister_format_validator(format, versions = (@@validators.flat_map { |k, v| v.names.first } + [nil]))
377
389
  versions.each do |version|
378
390
  validator = validator_for_name(version)
379
391
  validator.formats[format.to_s] = validator.default_formats[format.to_s]
380
392
  end
381
393
  end
382
394
 
383
- def restore_default_formats(versions = (@@validators.flat_map{ |k, v| v.names.first } + [nil]))
395
+ def restore_default_formats(versions = (@@validators.flat_map { |k, v| v.names.first } + [nil]))
384
396
  versions.each do |version|
385
397
  validator = validator_for_name(version)
386
398
  validator.formats = validator.default_formats.clone
@@ -404,7 +416,7 @@ module JSON
404
416
  if @@available_json_backends.include?(backend)
405
417
  @@json_backend = backend
406
418
  else
407
- raise JSON::Schema::JsonParseError.new("The JSON backend '#{backend}' could not be found.")
419
+ raise JSON::Schema::JsonParseError, "The JSON backend '#{backend}' could not be found."
408
420
  end
409
421
  end
410
422
  end
@@ -414,26 +426,26 @@ module JSON
414
426
  begin
415
427
  MultiJson.respond_to?(:adapter) ? MultiJson.load(s) : MultiJson.decode(s)
416
428
  rescue MultiJson::ParseError => e
417
- raise JSON::Schema::JsonParseError.new(e.message)
429
+ raise JSON::Schema::JsonParseError, e.message
418
430
  end
419
431
  else
420
432
  case @@json_backend.to_s
421
433
  when 'json'
422
434
  begin
423
- JSON.parse(s, :quirks_mode => true)
435
+ JSON.parse(s, quirks_mode: true)
424
436
  rescue JSON::ParserError => e
425
- raise JSON::Schema::JsonParseError.new(e.message)
437
+ raise JSON::Schema::JsonParseError, e.message
426
438
  end
427
439
  when 'yajl'
428
440
  begin
429
441
  json = StringIO.new(s)
430
442
  parser = Yajl::Parser.new
431
- parser.parse(json) or raise JSON::Schema::JsonParseError.new("The JSON could not be parsed by yajl")
443
+ parser.parse(json) or raise(JSON::Schema::JsonParseError, 'The JSON could not be parsed by yajl')
432
444
  rescue Yajl::ParseError => e
433
- raise JSON::Schema::JsonParseError.new(e.message)
445
+ raise JSON::Schema::JsonParseError, e.message
434
446
  end
435
447
  else
436
- raise JSON::Schema::JsonParseError.new("No supported JSON parsers found. The following parsers are suported:\n * yajl-ruby\n * json")
448
+ raise JSON::Schema::JsonParseError, "No supported JSON parsers found. The following parsers are suported:\n * yajl-ruby\n * json"
437
449
  end
438
450
  end
439
451
  end
@@ -472,7 +484,6 @@ module JSON
472
484
  end
473
485
  end
474
486
 
475
-
476
487
  if Gem::Specification::find_all_by_name('yajl-ruby').any?
477
488
  require 'yajl'
478
489
  @@available_json_backends << 'yajl'
@@ -480,11 +491,11 @@ module JSON
480
491
  end
481
492
 
482
493
  if @@json_backend == 'yajl'
483
- @@serializer = lambda{|o| Yajl::Encoder.encode(o) }
494
+ @@serializer = lambda { |o| Yajl::Encoder.encode(o) }
484
495
  elsif @@json_backend == 'json'
485
- @@serializer = lambda{|o| JSON.dump(o) }
496
+ @@serializer = lambda { |o| JSON.dump(o) }
486
497
  else
487
- @@serializer = lambda{|o| YAML.dump(o) }
498
+ @@serializer = lambda { |o| YAML.dump(o) }
488
499
  end
489
500
  end
490
501
  end
@@ -493,10 +504,10 @@ module JSON
493
504
 
494
505
  if Gem::Specification::find_all_by_name('uuidtools').any?
495
506
  require 'uuidtools'
496
- @@fake_uuid_generator = lambda{|s| UUIDTools::UUID.sha1_create(UUIDTools::UUID_URL_NAMESPACE, s).to_s }
507
+ @@fake_uuid_generator = lambda { |s| UUIDTools::UUID.sha1_create(UUIDTools::UUID_URL_NAMESPACE, s).to_s }
497
508
  else
498
509
  require 'json-schema/util/uuid'
499
- @@fake_uuid_generator = lambda{|s| JSON::Util::UUID.create_v5(s,JSON::Util::UUID::Nil).to_s }
510
+ @@fake_uuid_generator = lambda { |s| JSON::Util::UUID.create_v5(s, JSON::Util::UUID::Nil).to_s }
500
511
  end
501
512
 
502
513
  def serialize schema
@@ -552,7 +563,7 @@ module JSON
552
563
  end
553
564
  self.class.add_schema(schema)
554
565
  else
555
- raise JSON::Schema::SchemaParseError, "Invalid schema - must be either a string or a hash"
566
+ raise JSON::Schema::SchemaParseError, 'Invalid schema - must be either a string or a hash'
556
567
  end
557
568
 
558
569
  schema
@@ -567,7 +578,9 @@ module JSON
567
578
  data = self.class.parse(custom_open(json_uri))
568
579
  elsif data.is_a?(String)
569
580
  begin
570
- data = self.class.parse(data)
581
+ # Check if the string is valid integer
582
+ strict_convert = data.match?(/\A[+-]?\d+\z/) && !@options[:parse_integer]
583
+ data = strict_convert ? data : self.class.parse(data)
571
584
  rescue JSON::Schema::JsonParseError
572
585
  begin
573
586
  json_uri = Util::URI.normalized_uri(data)
@@ -2,27 +2,26 @@ require 'json-schema/schema/validator'
2
2
 
3
3
  module JSON
4
4
  class Schema
5
-
6
5
  class Draft1 < Validator
7
6
  def initialize
8
7
  super
9
8
  @attributes = {
10
- "type" => JSON::Schema::TypeAttribute,
11
- "disallow" => JSON::Schema::DisallowAttribute,
12
- "format" => JSON::Schema::FormatAttribute,
13
- "maximum" => JSON::Schema::MaximumInclusiveAttribute,
14
- "minimum" => JSON::Schema::MinimumInclusiveAttribute,
15
- "minItems" => JSON::Schema::MinItemsAttribute,
16
- "maxItems" => JSON::Schema::MaxItemsAttribute,
17
- "minLength" => JSON::Schema::MinLengthAttribute,
18
- "maxLength" => JSON::Schema::MaxLengthAttribute,
19
- "maxDecimal" => JSON::Schema::MaxDecimalAttribute,
20
- "enum" => JSON::Schema::EnumAttribute,
21
- "properties" => JSON::Schema::PropertiesOptionalAttribute,
22
- "pattern" => JSON::Schema::PatternAttribute,
23
- "additionalProperties" => JSON::Schema::AdditionalPropertiesAttribute,
24
- "items" => JSON::Schema::ItemsAttribute,
25
- "extends" => JSON::Schema::ExtendsAttribute
9
+ 'type' => JSON::Schema::TypeAttribute,
10
+ 'disallow' => JSON::Schema::DisallowAttribute,
11
+ 'format' => JSON::Schema::FormatAttribute,
12
+ 'maximum' => JSON::Schema::MaximumInclusiveAttribute,
13
+ 'minimum' => JSON::Schema::MinimumInclusiveAttribute,
14
+ 'minItems' => JSON::Schema::MinItemsAttribute,
15
+ 'maxItems' => JSON::Schema::MaxItemsAttribute,
16
+ 'minLength' => JSON::Schema::MinLengthAttribute,
17
+ 'maxLength' => JSON::Schema::MaxLengthAttribute,
18
+ 'maxDecimal' => JSON::Schema::MaxDecimalAttribute,
19
+ 'enum' => JSON::Schema::EnumAttribute,
20
+ 'properties' => JSON::Schema::PropertiesOptionalAttribute,
21
+ 'pattern' => JSON::Schema::PatternAttribute,
22
+ 'additionalProperties' => JSON::Schema::AdditionalPropertiesAttribute,
23
+ 'items' => JSON::Schema::ItemsAttribute,
24
+ 'extends' => JSON::Schema::ExtendsAttribute,
26
25
  }
27
26
  @default_formats = {
28
27
  'date-time' => DateTimeFormat,
@@ -30,16 +29,15 @@ module JSON
30
29
  'time' => TimeFormat,
31
30
  'ip-address' => IP4Format,
32
31
  'ipv6' => IP6Format,
33
- 'uri' => UriFormat
32
+ 'uri' => UriFormat,
34
33
  }
35
34
  @formats = @default_formats.clone
36
- @uri = JSON::Util::URI.parse("http://json-schema.org/draft-01/schema#")
37
- @names = ["draft1"]
38
- @metaschema_name = "draft-01.json"
35
+ @uri = JSON::Util::URI.parse('http://json-schema.org/draft-01/schema#')
36
+ @names = ['draft1']
37
+ @metaschema_name = 'draft-01.json'
39
38
  end
40
39
 
41
- JSON::Validator.register_validator(self.new)
40
+ JSON::Validator.register_validator(new)
42
41
  end
43
-
44
42
  end
45
43
  end
@@ -2,28 +2,27 @@ require 'json-schema/schema/validator'
2
2
 
3
3
  module JSON
4
4
  class Schema
5
-
6
5
  class Draft2 < Validator
7
6
  def initialize
8
7
  super
9
8
  @attributes = {
10
- "type" => JSON::Schema::TypeAttribute,
11
- "disallow" => JSON::Schema::DisallowAttribute,
12
- "format" => JSON::Schema::FormatAttribute,
13
- "maximum" => JSON::Schema::MaximumInclusiveAttribute,
14
- "minimum" => JSON::Schema::MinimumInclusiveAttribute,
15
- "minItems" => JSON::Schema::MinItemsAttribute,
16
- "maxItems" => JSON::Schema::MaxItemsAttribute,
17
- "uniqueItems" => JSON::Schema::UniqueItemsAttribute,
18
- "minLength" => JSON::Schema::MinLengthAttribute,
19
- "maxLength" => JSON::Schema::MaxLengthAttribute,
20
- "divisibleBy" => JSON::Schema::DivisibleByAttribute,
21
- "enum" => JSON::Schema::EnumAttribute,
22
- "properties" => JSON::Schema::PropertiesOptionalAttribute,
23
- "pattern" => JSON::Schema::PatternAttribute,
24
- "additionalProperties" => JSON::Schema::AdditionalPropertiesAttribute,
25
- "items" => JSON::Schema::ItemsAttribute,
26
- "extends" => JSON::Schema::ExtendsAttribute
9
+ 'type' => JSON::Schema::TypeAttribute,
10
+ 'disallow' => JSON::Schema::DisallowAttribute,
11
+ 'format' => JSON::Schema::FormatAttribute,
12
+ 'maximum' => JSON::Schema::MaximumInclusiveAttribute,
13
+ 'minimum' => JSON::Schema::MinimumInclusiveAttribute,
14
+ 'minItems' => JSON::Schema::MinItemsAttribute,
15
+ 'maxItems' => JSON::Schema::MaxItemsAttribute,
16
+ 'uniqueItems' => JSON::Schema::UniqueItemsAttribute,
17
+ 'minLength' => JSON::Schema::MinLengthAttribute,
18
+ 'maxLength' => JSON::Schema::MaxLengthAttribute,
19
+ 'divisibleBy' => JSON::Schema::DivisibleByAttribute,
20
+ 'enum' => JSON::Schema::EnumAttribute,
21
+ 'properties' => JSON::Schema::PropertiesOptionalAttribute,
22
+ 'pattern' => JSON::Schema::PatternAttribute,
23
+ 'additionalProperties' => JSON::Schema::AdditionalPropertiesAttribute,
24
+ 'items' => JSON::Schema::ItemsAttribute,
25
+ 'extends' => JSON::Schema::ExtendsAttribute,
27
26
  }
28
27
  @default_formats = {
29
28
  'date-time' => DateTimeFormat,
@@ -31,16 +30,15 @@ module JSON
31
30
  'time' => TimeFormat,
32
31
  'ip-address' => IP4Format,
33
32
  'ipv6' => IP6Format,
34
- 'uri' => UriFormat
33
+ 'uri' => UriFormat,
35
34
  }
36
35
  @formats = @default_formats.clone
37
- @uri = JSON::Util::URI.parse("http://json-schema.org/draft-02/schema#")
38
- @names = ["draft2"]
39
- @metaschema_name = "draft-02.json"
36
+ @uri = JSON::Util::URI.parse('http://json-schema.org/draft-02/schema#')
37
+ @names = ['draft2']
38
+ @metaschema_name = 'draft-02.json'
40
39
  end
41
40
 
42
- JSON::Validator.register_validator(self.new)
41
+ JSON::Validator.register_validator(new)
43
42
  end
44
-
45
43
  end
46
44
  end