json-schema 5.1.1 → 5.2.0
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.
- checksums.yaml +4 -4
- data/lib/json-schema/attribute.rb +2 -2
- data/lib/json-schema/attributes/allof.rb +27 -2
- data/lib/json-schema/attributes/const.rb +1 -1
- data/lib/json-schema/attributes/divisibleby.rb +1 -1
- data/lib/json-schema/attributes/enum.rb +1 -1
- data/lib/json-schema/attributes/formats/custom.rb +1 -1
- data/lib/json-schema/attributes/formats/date.rb +1 -1
- data/lib/json-schema/attributes/formats/date_time.rb +1 -1
- data/lib/json-schema/attributes/formats/date_time_v4.rb +1 -1
- data/lib/json-schema/attributes/formats/ip.rb +1 -1
- data/lib/json-schema/attributes/formats/time.rb +1 -1
- data/lib/json-schema/attributes/formats/uri.rb +1 -1
- data/lib/json-schema/attributes/limit.rb +2 -2
- data/lib/json-schema/attributes/maxdecimal.rb +1 -1
- data/lib/json-schema/attributes/oneof.rb +5 -5
- data/lib/json-schema/attributes/pattern.rb +1 -1
- data/lib/json-schema/attributes/properties.rb +1 -1
- data/lib/json-schema/attributes/properties_v4.rb +1 -1
- data/lib/json-schema/attributes/ref.rb +5 -5
- data/lib/json-schema/attributes/required.rb +1 -1
- data/lib/json-schema/attributes/type.rb +5 -5
- data/lib/json-schema/attributes/type_v4.rb +1 -1
- data/lib/json-schema/attributes/uniqueitems.rb +1 -1
- data/lib/json-schema/errors/validation_error.rb +3 -2
- data/lib/json-schema/schema/validator.rb +1 -1
- data/lib/json-schema/schema.rb +7 -7
- data/lib/json-schema/util/uuid.rb +4 -4
- data/lib/json-schema/validator.rb +38 -25
- data/lib/json-schema.rb +1 -1
- metadata +6 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 97a2b4d9e49213c47ca77141334410829d0d03cb5a3578ca985b03faabc91f25
|
4
|
+
data.tar.gz: feed8cd6688bcb611fc5010ad40e96bd2838c5338f35d959b1216b2bd2f449dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1faa5f35d538f52cb1490d19c875b49025351589b13854b4e40d14d89208b6da683d850afbe1b2e21b781943186d866db1bfc5021c6b021b955c69c6c464374e
|
7
|
+
data.tar.gz: 14b4744fc7b5b47bed8e0599aa1b0dd3ded3338748ab21e07b8bbfbf9d5ca13d310099d90b7436cb43b8e2e0f22b4c9f2ed5e884475f028616144a826cf8b582
|
@@ -9,8 +9,8 @@ module JSON
|
|
9
9
|
"#/#{fragments.join('/')}"
|
10
10
|
end
|
11
11
|
|
12
|
-
def self.validation_error(processor, message, fragments, current_schema, failed_attribute, record_errors)
|
13
|
-
error = ValidationError.new(message, fragments, failed_attribute, current_schema)
|
12
|
+
def self.validation_error(processor, message, fragments, current_schema, failed_attribute, record_errors, properties = [])
|
13
|
+
error = ValidationError.new(message, fragments, failed_attribute, current_schema, properties)
|
14
14
|
if record_errors
|
15
15
|
processor.validation_error(error)
|
16
16
|
else
|
@@ -17,20 +17,45 @@ module JSON
|
|
17
17
|
pre_validation_error_count = validation_errors(processor).count
|
18
18
|
|
19
19
|
begin
|
20
|
-
|
20
|
+
# Cannot raise if noAdditionalProperties is true, we need to
|
21
|
+
# evaluate each sub schema within the allOf, before raising.
|
22
|
+
if options[:noAdditionalProperties] == true
|
23
|
+
schema.validate(data, fragments, processor, options.merge(record_errors: true))
|
24
|
+
else
|
25
|
+
schema.validate(data, fragments, processor, options)
|
26
|
+
end
|
21
27
|
rescue ValidationError => e
|
22
28
|
valid = false
|
23
29
|
message = e.message
|
24
30
|
end
|
25
31
|
|
26
32
|
diff = validation_errors(processor).count - pre_validation_error_count
|
33
|
+
|
27
34
|
while diff > 0
|
28
35
|
diff = diff - 1
|
29
36
|
errors["allOf ##{schema_index}"].push(validation_errors(processor).pop)
|
30
37
|
end
|
31
38
|
end
|
32
39
|
|
33
|
-
|
40
|
+
# Find any properties that are missing across all subschemas.
|
41
|
+
common_missing_properties = {}
|
42
|
+
if options[:noAdditionalProperties] == true && !errors.empty?
|
43
|
+
all_property_errors = errors.values.flatten.map(&:properties)
|
44
|
+
common_missing_properties = (all_property_errors.first || []).to_set
|
45
|
+
|
46
|
+
all_property_errors[1..].each do |curr_property_errors|
|
47
|
+
common_missing_properties = common_missing_properties & curr_property_errors.to_set
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# PropertiesV4Attribute represents errors that would indicate an
|
52
|
+
# additional property was detected. If we filter these out, we should
|
53
|
+
# be left with errors that are not dependent on any other sub schema.
|
54
|
+
non_missing_property_errors = errors.values.flatten.reject do |error|
|
55
|
+
error.failed_attribute == JSON::Schema::PropertiesV4Attribute
|
56
|
+
end
|
57
|
+
|
58
|
+
if !valid || !non_missing_property_errors.empty? || !common_missing_properties.empty?
|
34
59
|
message ||= "The property '#{build_fragment(fragments)}' of type #{type_of_data(data)} did not match all of the required schemas"
|
35
60
|
validation_error(processor, message, fragments, current_schema, self, options[:record_errors])
|
36
61
|
validation_errors(processor).last.sub_errors = errors
|
@@ -3,7 +3,7 @@ require 'json-schema/attribute'
|
|
3
3
|
module JSON
|
4
4
|
class Schema
|
5
5
|
class ConstAttribute < Attribute
|
6
|
-
def self.validate(current_schema, data, fragments, processor,
|
6
|
+
def self.validate(current_schema, data, fragments, processor, _validator, options = {})
|
7
7
|
const_value = current_schema.schema['const']
|
8
8
|
unless const_value == data
|
9
9
|
message = "The property '#{build_fragment(fragments)}' value #{data.inspect} did not match constant '#{const_value}'"
|
@@ -7,7 +7,7 @@ module JSON
|
|
7
7
|
'divisibleBy'
|
8
8
|
end
|
9
9
|
|
10
|
-
def self.validate(current_schema, data, fragments, processor,
|
10
|
+
def self.validate(current_schema, data, fragments, processor, _validator, options = {})
|
11
11
|
return unless data.is_a?(Numeric)
|
12
12
|
|
13
13
|
factor = current_schema.schema[keyword]
|
@@ -3,7 +3,7 @@ require 'json-schema/attribute'
|
|
3
3
|
module JSON
|
4
4
|
class Schema
|
5
5
|
class EnumAttribute < Attribute
|
6
|
-
def self.validate(current_schema, data, fragments, processor,
|
6
|
+
def self.validate(current_schema, data, fragments, processor, _validator, options = {})
|
7
7
|
enum = current_schema.schema['enum']
|
8
8
|
return if enum.include?(data)
|
9
9
|
|
@@ -8,7 +8,7 @@ module JSON
|
|
8
8
|
@validation_proc = validation_proc
|
9
9
|
end
|
10
10
|
|
11
|
-
def validate(current_schema, data, fragments, processor,
|
11
|
+
def validate(current_schema, data, fragments, processor, _validator, options = {})
|
12
12
|
begin
|
13
13
|
@validation_proc.call data
|
14
14
|
rescue JSON::Schema::CustomFormatError => e
|
@@ -5,7 +5,7 @@ module JSON
|
|
5
5
|
class DateFormat < FormatAttribute
|
6
6
|
REGEXP = /\A\d{4}-\d{2}-\d{2}\z/
|
7
7
|
|
8
|
-
def self.validate(current_schema, data, fragments, processor,
|
8
|
+
def self.validate(current_schema, data, fragments, processor, _validator, options = {})
|
9
9
|
if data.is_a?(String)
|
10
10
|
error_message = "The property '#{build_fragment(fragments)}' must be a date in the format of YYYY-MM-DD"
|
11
11
|
if REGEXP.match(data)
|
@@ -5,7 +5,7 @@ module JSON
|
|
5
5
|
class DateTimeFormat < FormatAttribute
|
6
6
|
REGEXP = /\A\d{4}-\d{2}-\d{2}T(\d{2}):(\d{2}):(\d{2})([\.,]\d+)?(Z|[+-](\d{2})(:?\d{2})?)?\z/
|
7
7
|
|
8
|
-
def self.validate(current_schema, data, fragments, processor,
|
8
|
+
def self.validate(current_schema, data, fragments, processor, _validator, options = {})
|
9
9
|
# Timestamp in restricted ISO-8601 YYYY-MM-DDThh:mm:ssZ with optional decimal fraction of the second
|
10
10
|
if data.is_a?(String)
|
11
11
|
error_message = "The property '#{build_fragment(fragments)}' must be a date/time in the ISO-8601 format of YYYY-MM-DDThh:mm:ssZ or YYYY-MM-DDThh:mm:ss.ssZ"
|
@@ -3,7 +3,7 @@ require 'json-schema/attributes/format'
|
|
3
3
|
module JSON
|
4
4
|
class Schema
|
5
5
|
class DateTimeV4Format < FormatAttribute
|
6
|
-
def self.validate(current_schema, data, fragments, processor,
|
6
|
+
def self.validate(current_schema, data, fragments, processor, _validator, options = {})
|
7
7
|
return unless data.is_a?(String)
|
8
8
|
|
9
9
|
DateTime.rfc3339(data)
|
@@ -5,7 +5,7 @@ require 'socket'
|
|
5
5
|
module JSON
|
6
6
|
class Schema
|
7
7
|
class IPFormat < FormatAttribute
|
8
|
-
def self.validate(current_schema, data, fragments, processor,
|
8
|
+
def self.validate(current_schema, data, fragments, processor, _validator, options = {})
|
9
9
|
return unless data.is_a?(String)
|
10
10
|
|
11
11
|
begin
|
@@ -5,7 +5,7 @@ module JSON
|
|
5
5
|
class TimeFormat < FormatAttribute
|
6
6
|
REGEXP = /\A(\d{2}):(\d{2}):(\d{2})\z/
|
7
7
|
|
8
|
-
def self.validate(current_schema, data, fragments, processor,
|
8
|
+
def self.validate(current_schema, data, fragments, processor, _validator, options = {})
|
9
9
|
if data.is_a?(String)
|
10
10
|
error_message = "The property '#{build_fragment(fragments)}' must be a time in the format of hh:mm:ss"
|
11
11
|
if (m = REGEXP.match(data))
|
@@ -4,7 +4,7 @@ require 'json-schema/errors/uri_error'
|
|
4
4
|
module JSON
|
5
5
|
class Schema
|
6
6
|
class UriFormat < FormatAttribute
|
7
|
-
def self.validate(current_schema, data, fragments, processor,
|
7
|
+
def self.validate(current_schema, data, fragments, processor, _validator, options = {})
|
8
8
|
return unless data.is_a?(String)
|
9
9
|
|
10
10
|
error_message = "The property '#{build_fragment(fragments)}' must be a valid URI"
|
@@ -3,7 +3,7 @@ require 'json-schema/attribute'
|
|
3
3
|
module JSON
|
4
4
|
class Schema
|
5
5
|
class LimitAttribute < Attribute
|
6
|
-
def self.validate(current_schema, data, fragments, processor,
|
6
|
+
def self.validate(current_schema, data, fragments, processor, _validator, options = {})
|
7
7
|
schema = current_schema.schema
|
8
8
|
return unless data.is_a?(acceptable_type) && invalid?(schema, value(data))
|
9
9
|
|
@@ -28,7 +28,7 @@ module JSON
|
|
28
28
|
schema[limit_name]
|
29
29
|
end
|
30
30
|
|
31
|
-
def self.exclusive?(
|
31
|
+
def self.exclusive?(_schema)
|
32
32
|
false
|
33
33
|
end
|
34
34
|
|
@@ -3,7 +3,7 @@ require 'json-schema/attribute'
|
|
3
3
|
module JSON
|
4
4
|
class Schema
|
5
5
|
class MaxDecimalAttribute < Attribute
|
6
|
-
def self.validate(current_schema, data, fragments, processor,
|
6
|
+
def self.validate(current_schema, data, fragments, processor, _validator, options = {})
|
7
7
|
return unless data.is_a?(Numeric)
|
8
8
|
|
9
9
|
max_decimal_places = current_schema.schema['maxDecimal']
|
@@ -40,11 +40,11 @@ module JSON
|
|
40
40
|
return
|
41
41
|
end
|
42
42
|
|
43
|
-
if validation_error_count == one_of.length
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
43
|
+
message = if validation_error_count == one_of.length
|
44
|
+
"The property '#{build_fragment(fragments)}' of type #{type_of_data(data)} did not match any of the required schemas"
|
45
|
+
else
|
46
|
+
"The property '#{build_fragment(fragments)}' of type #{type_of_data(data)} matched more than one of the required schemas"
|
47
|
+
end
|
48
48
|
|
49
49
|
validation_error(processor, message, fragments, current_schema, self, options[:record_errors]) if message
|
50
50
|
validation_errors(processor).last.sub_errors = errors if message
|
@@ -3,7 +3,7 @@ require 'json-schema/attribute'
|
|
3
3
|
module JSON
|
4
4
|
class Schema
|
5
5
|
class PatternAttribute < Attribute
|
6
|
-
def self.validate(current_schema, data, fragments, processor,
|
6
|
+
def self.validate(current_schema, data, fragments, processor, _validator, options = {})
|
7
7
|
return unless data.is_a?(String)
|
8
8
|
|
9
9
|
pattern = current_schema.schema['pattern']
|
@@ -58,7 +58,7 @@ module JSON
|
|
58
58
|
unless diff.empty?
|
59
59
|
properties = diff.keys.join(', ')
|
60
60
|
message = "The property '#{build_fragment(fragments)}' contained undefined properties: '#{properties}'"
|
61
|
-
validation_error(processor, message, fragments, current_schema, self, options[:record_errors])
|
61
|
+
validation_error(processor, message, fragments, current_schema, self, options[:record_errors], diff.keys)
|
62
62
|
end
|
63
63
|
end
|
64
64
|
end
|
@@ -5,7 +5,7 @@ module JSON
|
|
5
5
|
class PropertiesV4Attribute < PropertiesAttribute
|
6
6
|
# draft4 relies on its own RequiredAttribute validation at a higher level, rather than
|
7
7
|
# as an attribute of individual properties.
|
8
|
-
def self.required?(
|
8
|
+
def self.required?(_schema, options)
|
9
9
|
options[:allPropertiesRequired] == true
|
10
10
|
end
|
11
11
|
end
|
@@ -37,11 +37,11 @@ module JSON
|
|
37
37
|
fragments.each do |fragment|
|
38
38
|
if fragment && fragment != ''
|
39
39
|
fragment = fragment.gsub('~0', '~').gsub('~1', '/')
|
40
|
-
if target_schema.is_a?(Array)
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
40
|
+
target_schema = if target_schema.is_a?(Array)
|
41
|
+
target_schema[fragment.to_i]
|
42
|
+
else
|
43
|
+
target_schema[fragment]
|
44
|
+
end
|
45
45
|
fragment_path = fragment_path + "/#{fragment}"
|
46
46
|
if target_schema.nil?
|
47
47
|
raise SchemaError, "The fragment '#{fragment_path}' does not exist on schema #{ref_schema.uri}"
|
@@ -3,7 +3,7 @@ require 'json-schema/attribute'
|
|
3
3
|
module JSON
|
4
4
|
class Schema
|
5
5
|
class RequiredAttribute < Attribute
|
6
|
-
def self.validate(current_schema, data, fragments, processor,
|
6
|
+
def self.validate(current_schema, data, fragments, processor, _validator, options = {})
|
7
7
|
return unless data.is_a?(Hash)
|
8
8
|
|
9
9
|
schema = current_schema.schema
|
@@ -5,11 +5,11 @@ module JSON
|
|
5
5
|
class TypeAttribute < Attribute
|
6
6
|
def self.validate(current_schema, data, fragments, processor, validator, options = {})
|
7
7
|
union = true
|
8
|
-
if options[:disallow]
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
types = if options[:disallow]
|
9
|
+
current_schema.schema['disallow']
|
10
|
+
else
|
11
|
+
current_schema.schema['type']
|
12
|
+
end
|
13
13
|
|
14
14
|
if !types.is_a?(Array)
|
15
15
|
types = [types]
|
@@ -3,7 +3,7 @@ require 'json-schema/attribute'
|
|
3
3
|
module JSON
|
4
4
|
class Schema
|
5
5
|
class TypeV4Attribute < Attribute
|
6
|
-
def self.validate(current_schema, data, fragments, processor,
|
6
|
+
def self.validate(current_schema, data, fragments, processor, _validator, options = {})
|
7
7
|
union = true
|
8
8
|
types = current_schema.schema['type']
|
9
9
|
if !types.is_a?(Array)
|
@@ -3,7 +3,7 @@ require 'json-schema/attribute'
|
|
3
3
|
module JSON
|
4
4
|
class Schema
|
5
5
|
class UniqueItemsAttribute < Attribute
|
6
|
-
def self.validate(current_schema, data, fragments, processor,
|
6
|
+
def self.validate(current_schema, data, fragments, processor, _validator, options = {})
|
7
7
|
return unless data.is_a?(Array)
|
8
8
|
|
9
9
|
if data.clone.uniq!
|
@@ -2,14 +2,15 @@ module JSON
|
|
2
2
|
class Schema
|
3
3
|
class ValidationError < StandardError
|
4
4
|
INDENT = ' '
|
5
|
-
attr_accessor :fragments, :schema, :failed_attribute, :sub_errors, :message
|
5
|
+
attr_accessor :fragments, :schema, :failed_attribute, :sub_errors, :message, :properties
|
6
6
|
|
7
|
-
def initialize(message, fragments, failed_attribute, schema)
|
7
|
+
def initialize(message, fragments, failed_attribute, schema, properties = [])
|
8
8
|
@fragments = fragments.clone
|
9
9
|
@schema = schema
|
10
10
|
@sub_errors = {}
|
11
11
|
@failed_attribute = failed_attribute
|
12
12
|
@message = message
|
13
|
+
@properties = properties
|
13
14
|
super(message_with_schema)
|
14
15
|
end
|
15
16
|
|
data/lib/json-schema/schema.rb
CHANGED
@@ -19,13 +19,13 @@ module JSON
|
|
19
19
|
@uri = JSON::Util::URI.strip_fragment(@uri)
|
20
20
|
|
21
21
|
# If there is a $schema on this schema, use it to determine which validator to use
|
22
|
-
if @schema['$schema']
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
22
|
+
@validator = if @schema['$schema']
|
23
|
+
JSON::Validator.validator_for_uri(@schema['$schema'])
|
24
|
+
elsif parent_validator
|
25
|
+
parent_validator
|
26
|
+
else
|
27
|
+
JSON::Validator.default_validator
|
28
|
+
end
|
29
29
|
end
|
30
30
|
|
31
31
|
def validate(data, fragments, processor, options = {})
|
@@ -64,7 +64,7 @@ module JSON
|
|
64
64
|
ret.freeze
|
65
65
|
ret
|
66
66
|
end
|
67
|
-
alias
|
67
|
+
alias create_v5 create_sha1
|
68
68
|
|
69
69
|
# UUID generation using MD5 (for backward compat.)
|
70
70
|
def create_md5 str, namespace
|
@@ -77,7 +77,7 @@ module JSON
|
|
77
77
|
ret.freeze
|
78
78
|
ret
|
79
79
|
end
|
80
|
-
alias
|
80
|
+
alias create_v3 create_md5
|
81
81
|
|
82
82
|
# UUID generation using random-number generator. From it's random
|
83
83
|
# nature, there's no warranty that the created ID is really universaly
|
@@ -94,7 +94,7 @@ module JSON
|
|
94
94
|
ret.freeze
|
95
95
|
ret
|
96
96
|
end
|
97
|
-
alias
|
97
|
+
alias create_v4 create_random
|
98
98
|
|
99
99
|
def read_state fp # :nodoc:
|
100
100
|
fp.rewind
|
@@ -172,7 +172,7 @@ module JSON
|
|
172
172
|
ch = ch | 0x80
|
173
173
|
pack tl, tm, th, cl, ch, m
|
174
174
|
end
|
175
|
-
alias
|
175
|
+
alias create_v1 create
|
176
176
|
|
177
177
|
# A simple GUID parser: just ignores unknown characters and convert
|
178
178
|
# hexadecimal dump into 16-octet object.
|
@@ -3,7 +3,6 @@ require 'pathname'
|
|
3
3
|
require 'bigdecimal'
|
4
4
|
require 'digest/sha1'
|
5
5
|
require 'date'
|
6
|
-
require 'thread'
|
7
6
|
require 'timeout'
|
8
7
|
require 'stringio'
|
9
8
|
require 'yaml'
|
@@ -42,7 +41,6 @@ module JSON
|
|
42
41
|
|
43
42
|
def initialize(schema_data, opts = {})
|
44
43
|
@options = @@default_opts.clone.merge(opts)
|
45
|
-
@errors = []
|
46
44
|
|
47
45
|
configured_validator = self.class.validator_for_name(@options[:version])
|
48
46
|
@options[:schema_reader] ||= self.class.schema_reader
|
@@ -108,24 +106,47 @@ module JSON
|
|
108
106
|
end
|
109
107
|
end
|
110
108
|
|
109
|
+
class ErrorRecorder < SimpleDelegator
|
110
|
+
def initialize(sub)
|
111
|
+
@errors = []
|
112
|
+
|
113
|
+
super
|
114
|
+
end
|
115
|
+
|
116
|
+
def validation_error(error)
|
117
|
+
@errors.push(error)
|
118
|
+
end
|
119
|
+
|
120
|
+
def validation_errors
|
121
|
+
@errors
|
122
|
+
end
|
123
|
+
|
124
|
+
def with_errors
|
125
|
+
self
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def with_errors
|
130
|
+
ErrorRecorder.new(self)
|
131
|
+
end
|
132
|
+
|
111
133
|
# Run a simple true/false validation of data against a schema
|
112
134
|
def validate(data)
|
113
135
|
original_data = data
|
114
136
|
data = initialize_data(data)
|
115
|
-
|
137
|
+
error_recorder = with_errors
|
138
|
+
@base_schema.validate(data, [], error_recorder, @validation_options)
|
116
139
|
|
117
140
|
if @options[:record_errors]
|
118
141
|
if @options[:errors_as_objects]
|
119
|
-
|
142
|
+
error_recorder.validation_errors.map { |e| e.to_hash }
|
120
143
|
else
|
121
|
-
|
144
|
+
error_recorder.validation_errors.map { |e| e.to_string }
|
122
145
|
end
|
123
146
|
else
|
124
147
|
true
|
125
148
|
end
|
126
149
|
ensure
|
127
|
-
@errors = []
|
128
|
-
|
129
150
|
if @validation_options[:clear_cache] == true
|
130
151
|
self.class.clear_cache
|
131
152
|
end
|
@@ -229,14 +250,6 @@ module JSON
|
|
229
250
|
end
|
230
251
|
end
|
231
252
|
|
232
|
-
def validation_error(error)
|
233
|
-
@errors.push(error)
|
234
|
-
end
|
235
|
-
|
236
|
-
def validation_errors
|
237
|
-
@errors
|
238
|
-
end
|
239
|
-
|
240
253
|
class << self
|
241
254
|
def validate(schema, data, opts = {})
|
242
255
|
begin
|
@@ -470,7 +483,7 @@ module JSON
|
|
470
483
|
end
|
471
484
|
|
472
485
|
if !defined?(MultiJson)
|
473
|
-
if Gem::Specification
|
486
|
+
if Gem::Specification.find_all_by_name('json').any?
|
474
487
|
require 'json'
|
475
488
|
@@available_json_backends << 'json'
|
476
489
|
@@json_backend = 'json'
|
@@ -484,25 +497,25 @@ module JSON
|
|
484
497
|
end
|
485
498
|
end
|
486
499
|
|
487
|
-
if Gem::Specification
|
500
|
+
if Gem::Specification.find_all_by_name('yajl-ruby').any?
|
488
501
|
require 'yajl'
|
489
502
|
@@available_json_backends << 'yajl'
|
490
503
|
@@json_backend = 'yajl'
|
491
504
|
end
|
492
505
|
|
493
|
-
if @@json_backend == 'yajl'
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
506
|
+
@@serializer = if @@json_backend == 'yajl'
|
507
|
+
lambda { |o| Yajl::Encoder.encode(o) }
|
508
|
+
elsif @@json_backend == 'json'
|
509
|
+
lambda { |o| JSON.dump(o) }
|
510
|
+
else
|
511
|
+
lambda { |o| YAML.dump(o) }
|
512
|
+
end
|
500
513
|
end
|
501
514
|
end
|
502
515
|
|
503
516
|
private
|
504
517
|
|
505
|
-
if Gem::Specification
|
518
|
+
if Gem::Specification.find_all_by_name('uuidtools').any?
|
506
519
|
require 'uuidtools'
|
507
520
|
@@fake_uuid_generator = lambda { |s| UUIDTools::UUID.sha1_create(UUIDTools::UUID_URL_NAMESPACE, s).to_s }
|
508
521
|
else
|
data/lib/json-schema.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json-schema
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.
|
4
|
+
version: 5.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kenny Hoxworth
|
8
8
|
- Vox Pupuli
|
9
|
-
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: minitest
|
@@ -45,14 +44,14 @@ dependencies:
|
|
45
44
|
requirements:
|
46
45
|
- - "~>"
|
47
46
|
- !ruby/object:Gem::Version
|
48
|
-
version: 3.
|
47
|
+
version: 3.1.0
|
49
48
|
type: :development
|
50
49
|
prerelease: false
|
51
50
|
version_requirements: !ruby/object:Gem::Requirement
|
52
51
|
requirements:
|
53
52
|
- - "~>"
|
54
53
|
- !ruby/object:Gem::Version
|
55
|
-
version: 3.
|
54
|
+
version: 3.1.0
|
56
55
|
- !ruby/object:Gem::Dependency
|
57
56
|
name: webmock
|
58
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -95,13 +94,12 @@ dependencies:
|
|
95
94
|
- - "~>"
|
96
95
|
- !ruby/object:Gem::Version
|
97
96
|
version: '3.1'
|
98
|
-
description:
|
99
97
|
email: voxpupuli@groups.io
|
100
98
|
executables: []
|
101
99
|
extensions: []
|
102
100
|
extra_rdoc_files:
|
103
|
-
- README.md
|
104
101
|
- LICENSE.md
|
102
|
+
- README.md
|
105
103
|
files:
|
106
104
|
- LICENSE.md
|
107
105
|
- README.md
|
@@ -194,7 +192,6 @@ metadata:
|
|
194
192
|
changelog_uri: https://github.com/voxpupuli/json-schema//blob/master/CHANGELOG.md
|
195
193
|
bug_tracker_uri: https://github.com/voxpupuli/json-schema//issues
|
196
194
|
funding_uri: https://github.com/sponsors/voxpupuli
|
197
|
-
post_install_message:
|
198
195
|
rdoc_options: []
|
199
196
|
require_paths:
|
200
197
|
- lib
|
@@ -209,8 +206,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
209
206
|
- !ruby/object:Gem::Version
|
210
207
|
version: '0'
|
211
208
|
requirements: []
|
212
|
-
rubygems_version: 3.
|
213
|
-
signing_key:
|
209
|
+
rubygems_version: 3.6.7
|
214
210
|
specification_version: 4
|
215
211
|
summary: Ruby JSON Schema Validator
|
216
212
|
test_files: []
|