json-schema 2.7.0 → 2.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -4
- data/lib/json-schema/attribute.rb +10 -0
- data/lib/json-schema/attributes/allof.rb +1 -1
- data/lib/json-schema/attributes/anyof.rb +1 -1
- data/lib/json-schema/attributes/not.rb +1 -1
- data/lib/json-schema/attributes/oneof.rb +2 -2
- data/lib/json-schema/attributes/ref.rb +1 -17
- data/lib/json-schema/attributes/type.rb +0 -10
- data/lib/json-schema/attributes/type_v4.rb +1 -1
- data/lib/json-schema/schema.rb +2 -2
- data/lib/json-schema/schema/validator.rb +2 -1
- data/lib/json-schema/util/array_set.rb +4 -4
- data/lib/json-schema/util/uri.rb +42 -0
- data/lib/json-schema/util/uuid.rb +0 -1
- data/lib/json-schema/validator.rb +48 -58
- data/lib/json-schema/validators/draft6.rb +56 -0
- data/lib/json-schema/validators/hyper-draft3.rb +13 -0
- data/lib/json-schema/validators/hyper-draft6.rb +13 -0
- data/resources/draft-03.json +173 -173
- data/resources/draft-06.json +150 -0
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 598f5a11313e53a8a719936d8bbe08bddb6d07b3
|
4
|
+
data.tar.gz: d9a1cde316718f0fdfd042f737bcb3d1b637d313
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e28327d9e15a145572c347c2124a9645a4e303cbad1641dde72dad47536f2071eb0fcc9628b439bb24d6f109cf1fd146d8cba2728236d2a88717a29db20fe875
|
7
|
+
data.tar.gz: b414849b2f9e74d7bfcfb0198ff11739caeb08eebd4929a5bd6e445b1a89c3b79c916b453f2c3d9cde05719f997e5b6eac0835534cbacc2bdb9016c296c8228f
|
data/README.md
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
[![Gem Version](https://badge.fury.io/rb/json-schema.svg)](https://badge.fury.io/rb/json-schema)
|
1
2
|
[![Travis](https://travis-ci.org/ruby-json-schema/json-schema.svg?branch=master)](https://travis-ci.org/ruby-json-schema/json-schema)
|
2
3
|
[![Code Climate](https://codeclimate.com/github/ruby-json-schema/json-schema/badges/gpa.svg)](https://codeclimate.com/github/ruby-json-schema/json-schema)
|
3
4
|
|
@@ -290,17 +291,17 @@ class BitwiseAndAttribute < JSON::Schema::Attribute
|
|
290
291
|
def self.validate(current_schema, data, fragments, processor, validator, options = {})
|
291
292
|
if data.is_a?(Integer) && data & current_schema.schema['bitwise-and'].to_i == 0
|
292
293
|
message = "The property '#{build_fragment(fragments)}' did not evaluate to true when bitwise-AND'd with #{current_schema.schema['bitwise-or']}"
|
293
|
-
|
294
|
+
validation_error(processor, message, fragments, current_schema, self, options[:record_errors])
|
294
295
|
end
|
295
296
|
end
|
296
297
|
end
|
297
298
|
|
298
|
-
class ExtendedSchema < JSON::Schema::
|
299
|
+
class ExtendedSchema < JSON::Schema::Draft3
|
299
300
|
def initialize
|
300
301
|
super
|
301
|
-
extend_schema_definition("http://json-schema.org/draft-03/schema#")
|
302
302
|
@attributes["bitwise-and"] = BitwiseAndAttribute
|
303
|
-
@uri = URI.parse("http://test.com/test.json")
|
303
|
+
@uri = JSON::Util::URI.parse("http://test.com/test.json")
|
304
|
+
@names = ["http://test.com/test.json"]
|
304
305
|
end
|
305
306
|
|
306
307
|
JSON::Validator.register_validator(self.new)
|
@@ -38,6 +38,16 @@ module JSON
|
|
38
38
|
valid_classes = TYPE_CLASS_MAPPINGS.fetch(type) { return true }
|
39
39
|
Array(valid_classes).any? { |c| data.is_a?(c) }
|
40
40
|
end
|
41
|
+
|
42
|
+
# Lookup Schema type of given class instance
|
43
|
+
def self.type_of_data(data)
|
44
|
+
type, _ = TYPE_CLASS_MAPPINGS.map { |k,v| [k,v] }.sort_by { |(_, v)|
|
45
|
+
-Array(v).map { |klass| klass.ancestors.size }.max
|
46
|
+
}.find { |(_, v)|
|
47
|
+
Array(v).any? { |klass| data.kind_of?(klass) }
|
48
|
+
}
|
49
|
+
type
|
50
|
+
end
|
41
51
|
end
|
42
52
|
end
|
43
53
|
end
|
@@ -29,7 +29,7 @@ module JSON
|
|
29
29
|
end
|
30
30
|
|
31
31
|
if !valid || !errors.empty?
|
32
|
-
message = "The property '#{build_fragment(fragments)}' of type #{data
|
32
|
+
message = "The property '#{build_fragment(fragments)}' of type #{type_of_data(data)} did not match all of the required schemas"
|
33
33
|
validation_error(processor, message, fragments, current_schema, self, options[:record_errors])
|
34
34
|
validation_errors(processor).last.sub_errors = errors
|
35
35
|
end
|
@@ -37,7 +37,7 @@ module JSON
|
|
37
37
|
end
|
38
38
|
|
39
39
|
if !valid
|
40
|
-
message = "The property '#{build_fragment(fragments)}' of type #{data
|
40
|
+
message = "The property '#{build_fragment(fragments)}' of type #{type_of_data(data)} did not match one or more of the required schemas"
|
41
41
|
validation_error(processor, message, fragments, current_schema, self, options[:record_errors])
|
42
42
|
validation_errors(processor).last.sub_errors = errors
|
43
43
|
end
|
@@ -14,7 +14,7 @@ module JSON
|
|
14
14
|
if options[:record_errors] && errors_copy.length != processor.validation_errors.length
|
15
15
|
processor.validation_errors.replace(errors_copy)
|
16
16
|
else
|
17
|
-
message = "The property '#{build_fragment(fragments)}' of type #{data
|
17
|
+
message = "The property '#{build_fragment(fragments)}' of type #{type_of_data(data)} matched the disallowed schema"
|
18
18
|
failed = false
|
19
19
|
end
|
20
20
|
rescue ValidationError
|
@@ -43,9 +43,9 @@ module JSON
|
|
43
43
|
end
|
44
44
|
|
45
45
|
if validation_error_count == one_of.length
|
46
|
-
message = "The property '#{build_fragment(fragments)}' of type #{data
|
46
|
+
message = "The property '#{build_fragment(fragments)}' of type #{type_of_data(data)} did not match any of the required schemas"
|
47
47
|
else
|
48
|
-
message = "The property '#{build_fragment(fragments)}' of type #{data
|
48
|
+
message = "The property '#{build_fragment(fragments)}' of type #{type_of_data(data)} matched more than one of the required schemas"
|
49
49
|
end
|
50
50
|
|
51
51
|
validation_error(processor, message, fragments, current_schema, self, options[:record_errors]) if message
|
@@ -22,23 +22,7 @@ module JSON
|
|
22
22
|
def self.get_referenced_uri_and_schema(s, current_schema, validator)
|
23
23
|
uri,schema = nil,nil
|
24
24
|
|
25
|
-
temp_uri = JSON::Util::URI.
|
26
|
-
temp_uri.defer_validation do
|
27
|
-
if temp_uri.relative?
|
28
|
-
temp_uri.merge!(current_schema.uri)
|
29
|
-
# Check for absolute path
|
30
|
-
path, fragment = s['$ref'].split("#")
|
31
|
-
if path.nil? || path == ''
|
32
|
-
temp_uri.path = current_schema.uri.path
|
33
|
-
elsif path[0,1] == "/"
|
34
|
-
temp_uri.path = Pathname.new(path).cleanpath.to_s
|
35
|
-
else
|
36
|
-
temp_uri.join!(path)
|
37
|
-
end
|
38
|
-
temp_uri.fragment = fragment
|
39
|
-
end
|
40
|
-
temp_uri.fragment = "" if temp_uri.fragment.nil? || temp_uri.fragment.empty?
|
41
|
-
end
|
25
|
+
temp_uri = JSON::Util::URI.normalize_ref(s['$ref'], current_schema.uri)
|
42
26
|
|
43
27
|
# Grab the parent schema from the schema list
|
44
28
|
schema_key = temp_uri.to_s.split("#")[0] + "#"
|
@@ -68,16 +68,6 @@ module JSON
|
|
68
68
|
def self.list_types(types)
|
69
69
|
types.map { |type| type.is_a?(String) ? type : '(schema)' }.join(', ')
|
70
70
|
end
|
71
|
-
|
72
|
-
# Lookup Schema type of given class instance
|
73
|
-
def self.type_of_data(data)
|
74
|
-
type, _ = TYPE_CLASS_MAPPINGS.map { |k,v| [k,v] }.sort_by { |(_, v)|
|
75
|
-
-Array(v).map { |klass| klass.ancestors.size }.max
|
76
|
-
}.find { |(_, v)|
|
77
|
-
Array(v).any? { |klass| data.kind_of?(klass) }
|
78
|
-
}
|
79
|
-
type
|
80
|
-
end
|
81
71
|
end
|
82
72
|
end
|
83
73
|
end
|
data/lib/json-schema/schema.rb
CHANGED
@@ -21,7 +21,7 @@ module JSON
|
|
21
21
|
|
22
22
|
# If there is a $schema on this schema, use it to determine which validator to use
|
23
23
|
if @schema['$schema']
|
24
|
-
@validator = JSON::Validator.
|
24
|
+
@validator = JSON::Validator.validator_for_uri(@schema['$schema'])
|
25
25
|
elsif parent_validator
|
26
26
|
@validator = parent_validator
|
27
27
|
else
|
@@ -52,7 +52,7 @@ module JSON
|
|
52
52
|
def to_array_schema
|
53
53
|
array_schema = { 'type' => 'array', 'items' => schema }
|
54
54
|
array_schema['$schema'] = schema['$schema'] unless schema['$schema'].nil?
|
55
|
-
|
55
|
+
self.class.new(array_schema, uri, validator)
|
56
56
|
end
|
57
57
|
|
58
58
|
def to_s
|
@@ -14,7 +14,8 @@ module JSON
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def extend_schema_definition(schema_uri)
|
17
|
-
|
17
|
+
warn "[DEPRECATION NOTICE] The preferred way to extend a Validator is by subclassing, rather than #extend_schema_definition. This method will be removed in version >= 3."
|
18
|
+
validator = JSON::Validator.validator_for_uri(schema_uri)
|
18
19
|
@attributes.merge!(validator.attributes)
|
19
20
|
end
|
20
21
|
|
@@ -7,14 +7,14 @@ class ArraySet < Array
|
|
7
7
|
def include?(obj)
|
8
8
|
if !defined? @values
|
9
9
|
@values = Set.new
|
10
|
-
self.each { |x| @values <<
|
10
|
+
self.each { |x| @values << convert_to_float_if_numeric(x) }
|
11
11
|
end
|
12
|
-
@values.include?(
|
12
|
+
@values.include?(convert_to_float_if_numeric(obj))
|
13
13
|
end
|
14
14
|
|
15
15
|
private
|
16
16
|
|
17
|
-
def
|
18
|
-
value.is_a?(
|
17
|
+
def convert_to_float_if_numeric(value)
|
18
|
+
value.is_a?(Numeric) ? value.to_f : value
|
19
19
|
end
|
20
20
|
end
|
data/lib/json-schema/util/uri.rb
CHANGED
@@ -23,6 +23,43 @@ module JSON
|
|
23
23
|
normalized_uri
|
24
24
|
end
|
25
25
|
|
26
|
+
def self.absolutize_ref(ref, base)
|
27
|
+
ref_uri = strip_fragment(ref.dup)
|
28
|
+
|
29
|
+
return ref_uri if ref_uri.absolute?
|
30
|
+
return parse(base) if ref_uri.path.empty?
|
31
|
+
|
32
|
+
uri = strip_fragment(base.dup).join(ref_uri.path)
|
33
|
+
normalized_uri(uri)
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.normalize_ref(ref, base)
|
37
|
+
ref_uri = parse(ref)
|
38
|
+
base_uri = parse(base)
|
39
|
+
|
40
|
+
ref_uri.defer_validation do
|
41
|
+
if ref_uri.relative?
|
42
|
+
ref_uri.merge!(base_uri)
|
43
|
+
|
44
|
+
# Check for absolute path
|
45
|
+
path, fragment = ref.to_s.split("#")
|
46
|
+
if path.nil? || path == ''
|
47
|
+
ref_uri.path = base_uri.path
|
48
|
+
elsif path[0,1] == "/"
|
49
|
+
ref_uri.path = Pathname.new(path).cleanpath.to_s
|
50
|
+
else
|
51
|
+
ref_uri.join!(path)
|
52
|
+
end
|
53
|
+
|
54
|
+
ref_uri.fragment = fragment
|
55
|
+
end
|
56
|
+
|
57
|
+
ref_uri.fragment = "" if ref_uri.fragment.nil? || ref_uri.fragment.empty?
|
58
|
+
end
|
59
|
+
|
60
|
+
ref_uri
|
61
|
+
end
|
62
|
+
|
26
63
|
def self.parse(uri)
|
27
64
|
if uri.is_a?(Addressable::URI)
|
28
65
|
return uri.dup
|
@@ -63,6 +100,11 @@ module JSON
|
|
63
100
|
|
64
101
|
Addressable::URI.unescape(parsed_uri.path)
|
65
102
|
end
|
103
|
+
|
104
|
+
def self.clear_cache
|
105
|
+
@parse_cache = {}
|
106
|
+
@normalize_cache = {}
|
107
|
+
end
|
66
108
|
end
|
67
109
|
end
|
68
110
|
end
|
@@ -41,9 +41,9 @@ module JSON
|
|
41
41
|
@options = @@default_opts.clone.merge(opts)
|
42
42
|
@errors = []
|
43
43
|
|
44
|
-
validator =
|
44
|
+
validator = self.class.validator_for_name(@options[:version])
|
45
45
|
@options[:version] = validator
|
46
|
-
@options[:schema_reader] ||=
|
46
|
+
@options[:schema_reader] ||= self.class.schema_reader
|
47
47
|
|
48
48
|
@validation_options = @options[:record_errors] ? {:record_errors => true} : {}
|
49
49
|
@validation_options[:insert_defaults] = true if @options[:insert_defaults]
|
@@ -58,7 +58,7 @@ module JSON
|
|
58
58
|
# validate the schema, if requested
|
59
59
|
if @options[:validate_schema]
|
60
60
|
if @base_schema.schema["$schema"]
|
61
|
-
base_validator =
|
61
|
+
base_validator = self.class.validator_for_name(@base_schema.schema["$schema"])
|
62
62
|
end
|
63
63
|
metaschema = base_validator ? base_validator.metaschema : validator.metaschema
|
64
64
|
# Don't clear the cache during metaschema validation!
|
@@ -123,33 +123,25 @@ module JSON
|
|
123
123
|
end
|
124
124
|
ensure
|
125
125
|
if @validation_options[:clear_cache] == true
|
126
|
-
|
126
|
+
self.class.clear_cache
|
127
127
|
end
|
128
128
|
if @validation_options[:insert_defaults]
|
129
|
-
|
129
|
+
self.class.merge_missing_values(@data, @original_data)
|
130
130
|
end
|
131
131
|
end
|
132
132
|
|
133
133
|
def load_ref_schema(parent_schema, ref)
|
134
|
-
schema_uri =
|
134
|
+
schema_uri = JSON::Util::URI.absolutize_ref(ref, parent_schema.uri)
|
135
135
|
return true if self.class.schema_loaded?(schema_uri)
|
136
136
|
|
137
|
+
validator = self.class.validator_for_uri(schema_uri, false)
|
138
|
+
schema_uri = JSON::Util::URI.file_uri(validator.metaschema) if validator
|
139
|
+
|
137
140
|
schema = @options[:schema_reader].read(schema_uri)
|
138
141
|
self.class.add_schema(schema)
|
139
142
|
build_schemas(schema)
|
140
143
|
end
|
141
144
|
|
142
|
-
def absolutize_ref_uri(ref, parent_schema_uri)
|
143
|
-
ref_uri = JSON::Util::URI.strip_fragment(ref)
|
144
|
-
|
145
|
-
return ref_uri if ref_uri.absolute?
|
146
|
-
# This is a self reference and thus the schema does not need to be re-loaded
|
147
|
-
return parent_schema_uri if ref_uri.path.empty?
|
148
|
-
|
149
|
-
uri = JSON::Util::URI.strip_fragment(parent_schema_uri.dup)
|
150
|
-
Util::URI.normalized_uri(uri.join(ref_uri.path))
|
151
|
-
end
|
152
|
-
|
153
145
|
# Build all schemas with IDs, mapping out the namespace
|
154
146
|
def build_schemas(parent_schema)
|
155
147
|
schema = parent_schema.schema
|
@@ -225,7 +217,7 @@ module JSON
|
|
225
217
|
schema_uri = parent_schema.uri.dup
|
226
218
|
schema = JSON::Schema.new(obj, schema_uri, parent_schema.validator)
|
227
219
|
if obj['id']
|
228
|
-
|
220
|
+
self.class.add_schema(schema)
|
229
221
|
end
|
230
222
|
build_schemas(schema)
|
231
223
|
end
|
@@ -258,10 +250,14 @@ module JSON
|
|
258
250
|
end
|
259
251
|
|
260
252
|
def validate!(schema, data,opts={})
|
261
|
-
validator =
|
253
|
+
validator = new(schema, data, opts)
|
262
254
|
validator.validate
|
263
255
|
end
|
264
|
-
|
256
|
+
|
257
|
+
def validate2(schema, data, opts={})
|
258
|
+
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."
|
259
|
+
validate!(schema, data, opts)
|
260
|
+
end
|
265
261
|
|
266
262
|
def validate_json!(schema, data, opts={})
|
267
263
|
validate!(schema, data, opts.merge(:json => true))
|
@@ -277,7 +273,7 @@ module JSON
|
|
277
273
|
|
278
274
|
def fully_validate_schema(schema, opts={})
|
279
275
|
data = schema
|
280
|
-
schema =
|
276
|
+
schema = validator_for_name(opts[:version]).metaschema
|
281
277
|
fully_validate(schema, data, opts)
|
282
278
|
end
|
283
279
|
|
@@ -299,6 +295,7 @@ module JSON
|
|
299
295
|
|
300
296
|
def clear_cache
|
301
297
|
@@schemas = {}
|
298
|
+
JSON::Util::URI.clear_cache
|
302
299
|
end
|
303
300
|
|
304
301
|
def schemas
|
@@ -337,28 +334,34 @@ module JSON
|
|
337
334
|
@@default_validator
|
338
335
|
end
|
339
336
|
|
340
|
-
def validator_for_uri(schema_uri)
|
337
|
+
def validator_for_uri(schema_uri, raise_not_found=true)
|
341
338
|
return default_validator unless schema_uri
|
342
339
|
u = JSON::Util::URI.parse(schema_uri)
|
343
340
|
validator = validators["#{u.scheme}://#{u.host}#{u.path}"]
|
344
|
-
if validator.nil?
|
341
|
+
if validator.nil? && raise_not_found
|
345
342
|
raise JSON::Schema::SchemaError.new("Schema not found: #{schema_uri}")
|
346
343
|
else
|
347
344
|
validator
|
348
345
|
end
|
349
346
|
end
|
350
347
|
|
351
|
-
def validator_for_name(schema_name)
|
348
|
+
def validator_for_name(schema_name, raise_not_found=true)
|
352
349
|
return default_validator unless schema_name
|
353
|
-
|
354
|
-
|
350
|
+
schema_name = schema_name.to_s
|
351
|
+
validator = validators.values.detect do |v|
|
352
|
+
Array(v.names).include?(schema_name)
|
353
|
+
end
|
354
|
+
if validator.nil? && raise_not_found
|
355
355
|
raise JSON::Schema::SchemaError.new("The requested JSON schema version is not supported")
|
356
356
|
else
|
357
357
|
validator
|
358
358
|
end
|
359
359
|
end
|
360
360
|
|
361
|
-
|
361
|
+
def validator_for(schema_uri)
|
362
|
+
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."
|
363
|
+
validator_for_uri(schema_uri)
|
364
|
+
end
|
362
365
|
|
363
366
|
def register_validator(v)
|
364
367
|
@@validators["#{v.uri.scheme}://#{v.uri.host}#{v.uri.path}"] = v
|
@@ -368,21 +371,24 @@ module JSON
|
|
368
371
|
@@default_validator = v
|
369
372
|
end
|
370
373
|
|
371
|
-
def register_format_validator(format, validation_proc, versions =
|
374
|
+
def register_format_validator(format, validation_proc, versions = (@@validators.flat_map{ |k, v| v.names.first } + [nil]))
|
372
375
|
custom_format_validator = JSON::Schema::CustomFormat.new(validation_proc)
|
373
|
-
|
376
|
+
versions.each do |version|
|
377
|
+
validator = validator_for_name(version)
|
374
378
|
validator.formats[format.to_s] = custom_format_validator
|
375
379
|
end
|
376
380
|
end
|
377
381
|
|
378
|
-
def deregister_format_validator(format, versions =
|
379
|
-
|
382
|
+
def deregister_format_validator(format, versions = (@@validators.flat_map{ |k, v| v.names.first } + [nil]))
|
383
|
+
versions.each do |version|
|
384
|
+
validator = validator_for_name(version)
|
380
385
|
validator.formats[format.to_s] = validator.default_formats[format.to_s]
|
381
386
|
end
|
382
387
|
end
|
383
388
|
|
384
|
-
def restore_default_formats(versions =
|
385
|
-
|
389
|
+
def restore_default_formats(versions = (@@validators.flat_map{ |k, v| v.names.first } + [nil]))
|
390
|
+
versions.each do |version|
|
391
|
+
validator = validator_for_name(version)
|
386
392
|
validator.formats = validator.default_formats.clone
|
387
393
|
end
|
388
394
|
end
|
@@ -487,22 +493,6 @@ module JSON
|
|
487
493
|
@@serializer = lambda{|o| YAML.dump(o) }
|
488
494
|
end
|
489
495
|
end
|
490
|
-
|
491
|
-
private
|
492
|
-
|
493
|
-
def validators_for_names(names)
|
494
|
-
names = names.map { |name| name.to_s }
|
495
|
-
[].tap do |memo|
|
496
|
-
validators.each do |_, validator|
|
497
|
-
if (validator.names & names).any?
|
498
|
-
memo << validator
|
499
|
-
end
|
500
|
-
end
|
501
|
-
if names.include?('')
|
502
|
-
memo << default_validator
|
503
|
-
end
|
504
|
-
end
|
505
|
-
end
|
506
496
|
end
|
507
497
|
|
508
498
|
private
|
@@ -532,11 +522,11 @@ module JSON
|
|
532
522
|
begin
|
533
523
|
# Build a fake URI for this
|
534
524
|
schema_uri = JSON::Util::URI.parse(fake_uuid(schema))
|
535
|
-
schema = JSON::Schema.new(
|
525
|
+
schema = JSON::Schema.new(self.class.parse(schema), schema_uri, @options[:version])
|
536
526
|
if @options[:list] && @options[:fragment].nil?
|
537
527
|
schema = schema.to_array_schema
|
538
528
|
end
|
539
|
-
|
529
|
+
self.class.add_schema(schema)
|
540
530
|
rescue JSON::Schema::JsonParseError
|
541
531
|
# Build a uri for it
|
542
532
|
schema_uri = Util::URI.normalized_uri(schema)
|
@@ -548,13 +538,13 @@ module JSON
|
|
548
538
|
schema = schema.to_array_schema
|
549
539
|
end
|
550
540
|
|
551
|
-
|
541
|
+
self.class.add_schema(schema)
|
552
542
|
else
|
553
543
|
schema = self.class.schema_for_uri(schema_uri)
|
554
544
|
if @options[:list] && @options[:fragment].nil?
|
555
545
|
schema = schema.to_array_schema
|
556
546
|
schema.uri = JSON::Util::URI.parse(fake_uuid(serialize(schema.schema)))
|
557
|
-
|
547
|
+
self.class.add_schema(schema)
|
558
548
|
end
|
559
549
|
schema
|
560
550
|
end
|
@@ -566,7 +556,7 @@ module JSON
|
|
566
556
|
if @options[:list] && @options[:fragment].nil?
|
567
557
|
schema = schema.to_array_schema
|
568
558
|
end
|
569
|
-
|
559
|
+
self.class.add_schema(schema)
|
570
560
|
else
|
571
561
|
raise JSON::Schema::SchemaParseError, "Invalid schema - must be either a string or a hash"
|
572
562
|
end
|
@@ -577,17 +567,17 @@ module JSON
|
|
577
567
|
def initialize_data(data)
|
578
568
|
if @options[:parse_data]
|
579
569
|
if @options[:json]
|
580
|
-
data =
|
570
|
+
data = self.class.parse(data)
|
581
571
|
elsif @options[:uri]
|
582
572
|
json_uri = Util::URI.normalized_uri(data)
|
583
|
-
data =
|
573
|
+
data = self.class.parse(custom_open(json_uri))
|
584
574
|
elsif data.is_a?(String)
|
585
575
|
begin
|
586
|
-
data =
|
576
|
+
data = self.class.parse(data)
|
587
577
|
rescue JSON::Schema::JsonParseError
|
588
578
|
begin
|
589
579
|
json_uri = Util::URI.normalized_uri(data)
|
590
|
-
data =
|
580
|
+
data = self.class.parse(custom_open(json_uri))
|
591
581
|
rescue JSON::Schema::JsonLoadError
|
592
582
|
# Silently discard the error - use the data as-is
|
593
583
|
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'json-schema/schema/validator'
|
2
|
+
|
3
|
+
module JSON
|
4
|
+
class Schema
|
5
|
+
|
6
|
+
class Draft6 < Validator
|
7
|
+
def initialize
|
8
|
+
super
|
9
|
+
@attributes = {
|
10
|
+
"type" => JSON::Schema::TypeV4Attribute,
|
11
|
+
"allOf" => JSON::Schema::AllOfAttribute,
|
12
|
+
"anyOf" => JSON::Schema::AnyOfAttribute,
|
13
|
+
"oneOf" => JSON::Schema::OneOfAttribute,
|
14
|
+
"not" => JSON::Schema::NotAttribute,
|
15
|
+
"disallow" => JSON::Schema::DisallowAttribute,
|
16
|
+
"format" => JSON::Schema::FormatAttribute,
|
17
|
+
"maximum" => JSON::Schema::MaximumAttribute,
|
18
|
+
"minimum" => JSON::Schema::MinimumAttribute,
|
19
|
+
"minItems" => JSON::Schema::MinItemsAttribute,
|
20
|
+
"maxItems" => JSON::Schema::MaxItemsAttribute,
|
21
|
+
"minProperties" => JSON::Schema::MinPropertiesAttribute,
|
22
|
+
"maxProperties" => JSON::Schema::MaxPropertiesAttribute,
|
23
|
+
"uniqueItems" => JSON::Schema::UniqueItemsAttribute,
|
24
|
+
"minLength" => JSON::Schema::MinLengthAttribute,
|
25
|
+
"maxLength" => JSON::Schema::MaxLengthAttribute,
|
26
|
+
"multipleOf" => JSON::Schema::MultipleOfAttribute,
|
27
|
+
"enum" => JSON::Schema::EnumAttribute,
|
28
|
+
"properties" => JSON::Schema::PropertiesV4Attribute,
|
29
|
+
"required" => JSON::Schema::RequiredAttribute,
|
30
|
+
"pattern" => JSON::Schema::PatternAttribute,
|
31
|
+
"patternProperties" => JSON::Schema::PatternPropertiesAttribute,
|
32
|
+
"additionalProperties" => JSON::Schema::AdditionalPropertiesAttribute,
|
33
|
+
"items" => JSON::Schema::ItemsAttribute,
|
34
|
+
"additionalItems" => JSON::Schema::AdditionalItemsAttribute,
|
35
|
+
"dependencies" => JSON::Schema::DependenciesV4Attribute,
|
36
|
+
"extends" => JSON::Schema::ExtendsAttribute,
|
37
|
+
"$ref" => JSON::Schema::RefAttribute
|
38
|
+
}
|
39
|
+
@default_formats = {
|
40
|
+
'date-time' => DateTimeV4Format,
|
41
|
+
'ipv4' => IP4Format,
|
42
|
+
'ipv6' => IP6Format,
|
43
|
+
'uri' => UriFormat
|
44
|
+
}
|
45
|
+
@formats = @default_formats.clone
|
46
|
+
@uri = JSON::Util::URI.parse("http://json-schema.org/draft-06/schema#")
|
47
|
+
@names = ["draft6", "http://json-schema.org/draft-06/schema#"]
|
48
|
+
@metaschema_name = "draft-06.json"
|
49
|
+
end
|
50
|
+
|
51
|
+
JSON::Validator.register_validator(self.new)
|
52
|
+
JSON::Validator.register_default_validator(self.new)
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
data/resources/draft-03.json
CHANGED
@@ -1,174 +1,174 @@
|
|
1
1
|
{
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
}
|
2
|
+
"$schema": "http://json-schema.org/draft-03/schema#",
|
3
|
+
"id": "http://json-schema.org/draft-03/schema#",
|
4
|
+
"type": "object",
|
5
|
+
|
6
|
+
"properties": {
|
7
|
+
"type": {
|
8
|
+
"type": [ "string", "array" ],
|
9
|
+
"items": {
|
10
|
+
"type": [ "string", { "$ref": "#" } ]
|
11
|
+
},
|
12
|
+
"uniqueItems": true,
|
13
|
+
"default": "any"
|
14
|
+
},
|
15
|
+
|
16
|
+
"properties": {
|
17
|
+
"type": "object",
|
18
|
+
"additionalProperties": { "$ref": "#" },
|
19
|
+
"default": {}
|
20
|
+
},
|
21
|
+
|
22
|
+
"patternProperties": {
|
23
|
+
"type": "object",
|
24
|
+
"additionalProperties": { "$ref": "#" },
|
25
|
+
"default": {}
|
26
|
+
},
|
27
|
+
|
28
|
+
"additionalProperties": {
|
29
|
+
"type": [ { "$ref": "#" }, "boolean" ],
|
30
|
+
"default": {}
|
31
|
+
},
|
32
|
+
|
33
|
+
"items": {
|
34
|
+
"type": [ { "$ref": "#" }, "array" ],
|
35
|
+
"items": { "$ref": "#" },
|
36
|
+
"default": {}
|
37
|
+
},
|
38
|
+
|
39
|
+
"additionalItems": {
|
40
|
+
"type": [ { "$ref": "#" }, "boolean" ],
|
41
|
+
"default": {}
|
42
|
+
},
|
43
|
+
|
44
|
+
"required": {
|
45
|
+
"type": "boolean",
|
46
|
+
"default": false
|
47
|
+
},
|
48
|
+
|
49
|
+
"dependencies": {
|
50
|
+
"type": "object",
|
51
|
+
"additionalProperties": {
|
52
|
+
"type": [ "string", "array", { "$ref": "#" } ],
|
53
|
+
"items": {
|
54
|
+
"type": "string"
|
55
|
+
}
|
56
|
+
},
|
57
|
+
"default": {}
|
58
|
+
},
|
59
|
+
|
60
|
+
"minimum": {
|
61
|
+
"type": "number"
|
62
|
+
},
|
63
|
+
|
64
|
+
"maximum": {
|
65
|
+
"type": "number"
|
66
|
+
},
|
67
|
+
|
68
|
+
"exclusiveMinimum": {
|
69
|
+
"type": "boolean",
|
70
|
+
"default": false
|
71
|
+
},
|
72
|
+
|
73
|
+
"exclusiveMaximum": {
|
74
|
+
"type": "boolean",
|
75
|
+
"default": false
|
76
|
+
},
|
77
|
+
|
78
|
+
"minItems": {
|
79
|
+
"type": "integer",
|
80
|
+
"minimum": 0,
|
81
|
+
"default": 0
|
82
|
+
},
|
83
|
+
|
84
|
+
"maxItems": {
|
85
|
+
"type": "integer",
|
86
|
+
"minimum": 0
|
87
|
+
},
|
88
|
+
|
89
|
+
"uniqueItems": {
|
90
|
+
"type": "boolean",
|
91
|
+
"default": false
|
92
|
+
},
|
93
|
+
|
94
|
+
"pattern": {
|
95
|
+
"type": "string",
|
96
|
+
"format": "regex"
|
97
|
+
},
|
98
|
+
|
99
|
+
"minLength": {
|
100
|
+
"type": "integer",
|
101
|
+
"minimum": 0,
|
102
|
+
"default": 0
|
103
|
+
},
|
104
|
+
|
105
|
+
"maxLength": {
|
106
|
+
"type": "integer"
|
107
|
+
},
|
108
|
+
|
109
|
+
"enum": {
|
110
|
+
"type": "array",
|
111
|
+
"minItems": 1,
|
112
|
+
"uniqueItems": true
|
113
|
+
},
|
114
|
+
|
115
|
+
"default": {
|
116
|
+
"type": "any"
|
117
|
+
},
|
118
|
+
|
119
|
+
"title": {
|
120
|
+
"type": "string"
|
121
|
+
},
|
122
|
+
|
123
|
+
"description": {
|
124
|
+
"type": "string"
|
125
|
+
},
|
126
|
+
|
127
|
+
"format": {
|
128
|
+
"type": "string"
|
129
|
+
},
|
130
|
+
|
131
|
+
"divisibleBy": {
|
132
|
+
"type": "number",
|
133
|
+
"minimum": 0,
|
134
|
+
"exclusiveMinimum": true,
|
135
|
+
"default": 1
|
136
|
+
},
|
137
|
+
|
138
|
+
"disallow": {
|
139
|
+
"type": [ "string", "array" ],
|
140
|
+
"items": {
|
141
|
+
"type": [ "string", { "$ref": "#" } ]
|
142
|
+
},
|
143
|
+
"uniqueItems": true
|
144
|
+
},
|
145
|
+
|
146
|
+
"extends": {
|
147
|
+
"type": [ { "$ref": "#" }, "array" ],
|
148
|
+
"items": { "$ref": "#" },
|
149
|
+
"default": {}
|
150
|
+
},
|
151
|
+
|
152
|
+
"id": {
|
153
|
+
"type": "string",
|
154
|
+
"format": "uri"
|
155
|
+
},
|
156
|
+
|
157
|
+
"$ref": {
|
158
|
+
"type": "string",
|
159
|
+
"format": "uri"
|
160
|
+
},
|
161
|
+
|
162
|
+
"$schema": {
|
163
|
+
"type": "string",
|
164
|
+
"format": "uri"
|
165
|
+
}
|
166
|
+
},
|
167
|
+
|
168
|
+
"dependencies": {
|
169
|
+
"exclusiveMinimum": "minimum",
|
170
|
+
"exclusiveMaximum": "maximum"
|
171
|
+
},
|
172
|
+
|
173
|
+
"default": {}
|
174
|
+
}
|
@@ -0,0 +1,150 @@
|
|
1
|
+
{
|
2
|
+
"id": "http://json-schema.org/draft-06/schema#",
|
3
|
+
"$schema": "http://json-schema.org/draft-06/schema#",
|
4
|
+
"description": "Core schema meta-schema",
|
5
|
+
"definitions": {
|
6
|
+
"schemaArray": {
|
7
|
+
"type": "array",
|
8
|
+
"minItems": 1,
|
9
|
+
"items": { "$ref": "#" }
|
10
|
+
},
|
11
|
+
"positiveInteger": {
|
12
|
+
"type": "integer",
|
13
|
+
"minimum": 0
|
14
|
+
},
|
15
|
+
"positiveIntegerDefault0": {
|
16
|
+
"allOf": [ { "$ref": "#/definitions/positiveInteger" }, { "default": 0 } ]
|
17
|
+
},
|
18
|
+
"simpleTypes": {
|
19
|
+
"enum": [ "array", "boolean", "integer", "null", "number", "object", "string" ]
|
20
|
+
},
|
21
|
+
"stringArray": {
|
22
|
+
"type": "array",
|
23
|
+
"items": { "type": "string" },
|
24
|
+
"minItems": 1,
|
25
|
+
"uniqueItems": true
|
26
|
+
}
|
27
|
+
},
|
28
|
+
"type": "object",
|
29
|
+
"properties": {
|
30
|
+
"id": {
|
31
|
+
"type": "string",
|
32
|
+
"format": "uri"
|
33
|
+
},
|
34
|
+
"$schema": {
|
35
|
+
"type": "string",
|
36
|
+
"format": "uri"
|
37
|
+
},
|
38
|
+
"title": {
|
39
|
+
"type": "string"
|
40
|
+
},
|
41
|
+
"description": {
|
42
|
+
"type": "string"
|
43
|
+
},
|
44
|
+
"default": {},
|
45
|
+
"multipleOf": {
|
46
|
+
"type": "number",
|
47
|
+
"minimum": 0,
|
48
|
+
"exclusiveMinimum": true
|
49
|
+
},
|
50
|
+
"maximum": {
|
51
|
+
"type": "number"
|
52
|
+
},
|
53
|
+
"exclusiveMaximum": {
|
54
|
+
"type": "boolean",
|
55
|
+
"default": false
|
56
|
+
},
|
57
|
+
"minimum": {
|
58
|
+
"type": "number"
|
59
|
+
},
|
60
|
+
"exclusiveMinimum": {
|
61
|
+
"type": "boolean",
|
62
|
+
"default": false
|
63
|
+
},
|
64
|
+
"maxLength": { "$ref": "#/definitions/positiveInteger" },
|
65
|
+
"minLength": { "$ref": "#/definitions/positiveIntegerDefault0" },
|
66
|
+
"pattern": {
|
67
|
+
"type": "string",
|
68
|
+
"format": "regex"
|
69
|
+
},
|
70
|
+
"additionalItems": {
|
71
|
+
"anyOf": [
|
72
|
+
{ "type": "boolean" },
|
73
|
+
{ "$ref": "#" }
|
74
|
+
],
|
75
|
+
"default": {}
|
76
|
+
},
|
77
|
+
"items": {
|
78
|
+
"anyOf": [
|
79
|
+
{ "$ref": "#" },
|
80
|
+
{ "$ref": "#/definitions/schemaArray" }
|
81
|
+
],
|
82
|
+
"default": {}
|
83
|
+
},
|
84
|
+
"maxItems": { "$ref": "#/definitions/positiveInteger" },
|
85
|
+
"minItems": { "$ref": "#/definitions/positiveIntegerDefault0" },
|
86
|
+
"uniqueItems": {
|
87
|
+
"type": "boolean",
|
88
|
+
"default": false
|
89
|
+
},
|
90
|
+
"maxProperties": { "$ref": "#/definitions/positiveInteger" },
|
91
|
+
"minProperties": { "$ref": "#/definitions/positiveIntegerDefault0" },
|
92
|
+
"required": { "$ref": "#/definitions/stringArray" },
|
93
|
+
"additionalProperties": {
|
94
|
+
"anyOf": [
|
95
|
+
{ "type": "boolean" },
|
96
|
+
{ "$ref": "#" }
|
97
|
+
],
|
98
|
+
"default": {}
|
99
|
+
},
|
100
|
+
"definitions": {
|
101
|
+
"type": "object",
|
102
|
+
"additionalProperties": { "$ref": "#" },
|
103
|
+
"default": {}
|
104
|
+
},
|
105
|
+
"properties": {
|
106
|
+
"type": "object",
|
107
|
+
"additionalProperties": { "$ref": "#" },
|
108
|
+
"default": {}
|
109
|
+
},
|
110
|
+
"patternProperties": {
|
111
|
+
"type": "object",
|
112
|
+
"additionalProperties": { "$ref": "#" },
|
113
|
+
"default": {}
|
114
|
+
},
|
115
|
+
"dependencies": {
|
116
|
+
"type": "object",
|
117
|
+
"additionalProperties": {
|
118
|
+
"anyOf": [
|
119
|
+
{ "$ref": "#" },
|
120
|
+
{ "$ref": "#/definitions/stringArray" }
|
121
|
+
]
|
122
|
+
}
|
123
|
+
},
|
124
|
+
"enum": {
|
125
|
+
"type": "array",
|
126
|
+
"minItems": 1,
|
127
|
+
"uniqueItems": true
|
128
|
+
},
|
129
|
+
"type": {
|
130
|
+
"anyOf": [
|
131
|
+
{ "$ref": "#/definitions/simpleTypes" },
|
132
|
+
{
|
133
|
+
"type": "array",
|
134
|
+
"items": { "$ref": "#/definitions/simpleTypes" },
|
135
|
+
"minItems": 1,
|
136
|
+
"uniqueItems": true
|
137
|
+
}
|
138
|
+
]
|
139
|
+
},
|
140
|
+
"allOf": { "$ref": "#/definitions/schemaArray" },
|
141
|
+
"anyOf": { "$ref": "#/definitions/schemaArray" },
|
142
|
+
"oneOf": { "$ref": "#/definitions/schemaArray" },
|
143
|
+
"not": { "$ref": "#" }
|
144
|
+
},
|
145
|
+
"dependencies": {
|
146
|
+
"exclusiveMaximum": [ "maximum" ],
|
147
|
+
"exclusiveMinimum": [ "minimum" ]
|
148
|
+
},
|
149
|
+
"default": {}
|
150
|
+
}
|
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.
|
4
|
+
version: 2.8.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:
|
11
|
+
date: 2017-02-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -142,13 +142,17 @@ files:
|
|
142
142
|
- lib/json-schema/validators/draft2.rb
|
143
143
|
- lib/json-schema/validators/draft3.rb
|
144
144
|
- lib/json-schema/validators/draft4.rb
|
145
|
+
- lib/json-schema/validators/draft6.rb
|
145
146
|
- lib/json-schema/validators/hyper-draft1.rb
|
146
147
|
- lib/json-schema/validators/hyper-draft2.rb
|
148
|
+
- lib/json-schema/validators/hyper-draft3.rb
|
147
149
|
- lib/json-schema/validators/hyper-draft4.rb
|
150
|
+
- lib/json-schema/validators/hyper-draft6.rb
|
148
151
|
- resources/draft-01.json
|
149
152
|
- resources/draft-02.json
|
150
153
|
- resources/draft-03.json
|
151
154
|
- resources/draft-04.json
|
155
|
+
- resources/draft-06.json
|
152
156
|
homepage: http://github.com/ruby-json-schema/json-schema/tree/master
|
153
157
|
licenses:
|
154
158
|
- MIT
|
@@ -169,7 +173,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
169
173
|
version: '1.8'
|
170
174
|
requirements: []
|
171
175
|
rubyforge_project:
|
172
|
-
rubygems_version: 2.
|
176
|
+
rubygems_version: 2.6.8
|
173
177
|
signing_key:
|
174
178
|
specification_version: 4
|
175
179
|
summary: Ruby JSON Schema Validator
|