schemacop 3.0.0.rc1 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.releaser_config +0 -1
- data/CHANGELOG.md +41 -1
- data/README.md +1 -1
- data/README_V3.md +296 -87
- data/Rakefile +1 -0
- data/VERSION +1 -1
- data/lib/schemacop.rb +1 -0
- data/lib/schemacop/railtie.rb +7 -0
- data/lib/schemacop/scoped_env.rb +3 -3
- data/lib/schemacop/v2.rb +0 -1
- data/lib/schemacop/v2/caster.rb +1 -0
- data/lib/schemacop/v3/array_node.rb +1 -2
- data/lib/schemacop/v3/hash_node.rb +55 -26
- data/lib/schemacop/v3/node.rb +10 -5
- data/lib/schemacop/v3/node_registry.rb +0 -4
- data/lib/schemacop/v3/reference_node.rb +7 -1
- data/lib/schemacop/v3/string_node.rb +15 -7
- data/schemacop.gemspec +8 -5
- data/test/lib/test_helper.rb +17 -2
- data/test/unit/schemacop/v2/casting_test.rb +37 -0
- data/test/unit/schemacop/v2/validator_hash_test.rb +11 -0
- data/test/unit/schemacop/v3/all_of_node_test.rb +1 -2
- data/test/unit/schemacop/v3/any_of_node_test.rb +6 -6
- data/test/unit/schemacop/v3/array_node_test.rb +13 -3
- data/test/unit/schemacop/v3/global_context_test.rb +2 -0
- data/test/unit/schemacop/v3/hash_node_test.rb +167 -21
- data/test/unit/schemacop/v3/node_test.rb +14 -0
- data/test/unit/schemacop/v3/one_of_node_test.rb +6 -6
- data/test/unit/schemacop/v3/reference_node_test.rb +18 -2
- data/test/unit/schemacop/v3/string_node_test.rb +38 -0
- metadata +18 -5
- data/lib/schemacop/v2/root_node.rb +0 -6
data/Rakefile
CHANGED
@@ -18,6 +18,7 @@ task :gemspec do
|
|
18
18
|
# needs access to ActiveSupport::HashWithIndifferentAccess and expects
|
19
19
|
# behavior of that as in version 5 of ActiveSupport.
|
20
20
|
spec.add_dependency 'activesupport', '>= 4.0'
|
21
|
+
spec.add_dependency 'ruby2_keywords', '0.0.4'
|
21
22
|
spec.add_development_dependency 'bundler'
|
22
23
|
spec.add_development_dependency 'rake'
|
23
24
|
spec.add_development_dependency 'minitest'
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.0.0
|
1
|
+
3.0.0
|
data/lib/schemacop.rb
CHANGED
data/lib/schemacop/railtie.rb
CHANGED
@@ -5,6 +5,13 @@ module Schemacop
|
|
5
5
|
unless Rails.env.development?
|
6
6
|
V3::GlobalContext.eager_load!
|
7
7
|
end
|
8
|
+
|
9
|
+
# Tell Zeitwerk to ignore the files in our load path
|
10
|
+
if defined?(Rails) && defined?(Zeitwerk)
|
11
|
+
Schemacop.load_paths.each do |load_path|
|
12
|
+
Rails.autoloaders.main.ignore(Rails.root.join(load_path))
|
13
|
+
end
|
14
|
+
end
|
8
15
|
end
|
9
16
|
end
|
10
17
|
end
|
data/lib/schemacop/scoped_env.rb
CHANGED
@@ -7,14 +7,14 @@ module Schemacop
|
|
7
7
|
@prefix = prefix
|
8
8
|
end
|
9
9
|
|
10
|
-
def method_missing(symbol, *args,
|
10
|
+
ruby2_keywords def method_missing(symbol, *args, &block)
|
11
11
|
symbol = :"#{@prefix}#{symbol}" if @prefix
|
12
12
|
|
13
13
|
if @methods.include?(symbol)
|
14
14
|
if @delegation_object.respond_to?(symbol)
|
15
|
-
@delegation_object.send(symbol, *args,
|
15
|
+
@delegation_object.send(symbol, *args, &block)
|
16
16
|
elsif @backup_binding.respond_to?(symbol)
|
17
|
-
@backup_binding.send(symbol, *args,
|
17
|
+
@backup_binding.send(symbol, *args, &block)
|
18
18
|
else
|
19
19
|
super
|
20
20
|
end
|
data/lib/schemacop/v2.rb
CHANGED
@@ -10,7 +10,6 @@ require 'schemacop/v2/node'
|
|
10
10
|
require 'schemacop/v2/node_with_block'
|
11
11
|
require 'schemacop/v2/node_supporting_type'
|
12
12
|
require 'schemacop/v2/field_node'
|
13
|
-
require 'schemacop/v2/root_node'
|
14
13
|
require 'schemacop/v2/node_supporting_field'
|
15
14
|
require 'schemacop/v2/caster'
|
16
15
|
require 'schemacop/v2/dupper'
|
data/lib/schemacop/v2/caster.rb
CHANGED
@@ -172,10 +172,9 @@ module Schemacop
|
|
172
172
|
list_item.present?
|
173
173
|
end
|
174
174
|
|
175
|
-
def item_for_data(data
|
175
|
+
def item_for_data(data)
|
176
176
|
item = children.find { |c| item_matches?(c, data) }
|
177
177
|
return item if item
|
178
|
-
return nil unless force
|
179
178
|
|
180
179
|
fail "Could not find specification for item #{data.inspect}."
|
181
180
|
end
|
@@ -11,6 +11,8 @@ module Schemacop
|
|
11
11
|
|
12
12
|
supports_children(name: true)
|
13
13
|
|
14
|
+
attr_reader :properties
|
15
|
+
|
14
16
|
def self.allowed_options
|
15
17
|
super + ATTRIBUTES - %i[dependencies] + %i[additional_properties]
|
16
18
|
end
|
@@ -19,6 +21,14 @@ module Schemacop
|
|
19
21
|
super + NodeRegistry.dsl_methods(true) + %i[dsl_dep dsl_add]
|
20
22
|
end
|
21
23
|
|
24
|
+
def self.sanitize_exp(exp)
|
25
|
+
exp = exp.to_s
|
26
|
+
if exp.start_with?('(?-mix:')
|
27
|
+
exp = exp.to_s.gsub(/^\(\?-mix:/, '').gsub(/\)$/, '')
|
28
|
+
end
|
29
|
+
return exp
|
30
|
+
end
|
31
|
+
|
22
32
|
def add_child(node)
|
23
33
|
unless node.name
|
24
34
|
fail Exceptions::InvalidSchemaError, 'Child nodes must have a name.'
|
@@ -54,11 +64,11 @@ module Schemacop
|
|
54
64
|
|
55
65
|
json = {}
|
56
66
|
json[:properties] = Hash[properties.values.map { |p| [p.name, p.as_json] }] if properties.any?
|
57
|
-
json[:patternProperties] = Hash[pattern_properties.values.map { |p| [sanitize_exp(p.name), p.as_json] }] if pattern_properties.any?
|
67
|
+
json[:patternProperties] = Hash[pattern_properties.values.map { |p| [self.class.sanitize_exp(p.name), p.as_json] }] if pattern_properties.any?
|
58
68
|
|
59
69
|
# In schemacop, by default, additional properties are not allowed,
|
60
70
|
# the users explicitly need to enable additional properties
|
61
|
-
if options[:additional_properties]
|
71
|
+
if options[:additional_properties].is_a?(TrueClass)
|
62
72
|
json[:additionalProperties] = true
|
63
73
|
elsif options[:additional_properties].is_a?(Node)
|
64
74
|
json[:additionalProperties] = options[:additional_properties].as_json
|
@@ -75,14 +85,6 @@ module Schemacop
|
|
75
85
|
return process_json(ATTRIBUTES, json)
|
76
86
|
end
|
77
87
|
|
78
|
-
def sanitize_exp(exp)
|
79
|
-
exp = exp.to_s
|
80
|
-
if exp.start_with?('(?-mix:')
|
81
|
-
exp = exp.to_s.gsub(/^\(\?-mix:/, '').gsub(/\)$/, '')
|
82
|
-
end
|
83
|
-
return exp
|
84
|
-
end
|
85
|
-
|
86
88
|
def allowed_types
|
87
89
|
{ Hash => :object }
|
88
90
|
end
|
@@ -91,14 +93,23 @@ module Schemacop
|
|
91
93
|
super_data = super
|
92
94
|
return if super_data.nil?
|
93
95
|
|
96
|
+
original_data_hash = super_data.dup
|
97
|
+
data_hash = super_data.with_indifferent_access
|
98
|
+
|
99
|
+
if original_data_hash.size != data_hash.size
|
100
|
+
ambiguous_properties = original_data_hash.keys - data_hash.keys
|
101
|
+
|
102
|
+
result.error "Has #{ambiguous_properties.size} ambiguous properties: #{ambiguous_properties}."
|
103
|
+
end
|
104
|
+
|
94
105
|
# Validate min_properties #
|
95
|
-
if options[:min_properties] &&
|
96
|
-
result.error "Has #{
|
106
|
+
if options[:min_properties] && data_hash.size < options[:min_properties]
|
107
|
+
result.error "Has #{data_hash.size} properties but needs at least #{options[:min_properties]}."
|
97
108
|
end
|
98
109
|
|
99
110
|
# Validate max_properties #
|
100
|
-
if options[:max_properties] &&
|
101
|
-
result.error "Has #{
|
111
|
+
if options[:max_properties] && data_hash.size > options[:max_properties]
|
112
|
+
result.error "Has #{data_hash.size} properties but needs at most #{options[:max_properties]}."
|
102
113
|
end
|
103
114
|
|
104
115
|
# Validate specified properties #
|
@@ -106,13 +117,13 @@ module Schemacop
|
|
106
117
|
result.in_path(node.name) do
|
107
118
|
next if node.name.is_a?(Regexp)
|
108
119
|
|
109
|
-
node._validate(
|
120
|
+
node._validate(data_hash[node.name], result: result)
|
110
121
|
end
|
111
122
|
end
|
112
123
|
|
113
124
|
# Validate additional properties #
|
114
125
|
specified_properties = @properties.keys.to_set
|
115
|
-
additional_properties =
|
126
|
+
additional_properties = data_hash.reject { |k, _v| specified_properties.include?(k.to_s) }
|
116
127
|
|
117
128
|
property_patterns = {}
|
118
129
|
|
@@ -130,7 +141,9 @@ module Schemacop
|
|
130
141
|
result.error "Property name #{name.inspect} does not match #{options[:property_names].inspect}."
|
131
142
|
end
|
132
143
|
|
133
|
-
if options[:additional_properties].
|
144
|
+
if options[:additional_properties].is_a?(TrueClass)
|
145
|
+
next
|
146
|
+
elsif options[:additional_properties].is_a?(FalseClass) || options[:additional_properties].blank?
|
134
147
|
match = property_patterns.keys.find { |p| p.match?(name.to_s) }
|
135
148
|
if match
|
136
149
|
result.in_path(name) do
|
@@ -149,7 +162,7 @@ module Schemacop
|
|
149
162
|
# Validate dependencies #
|
150
163
|
options[:dependencies]&.each do |source, targets|
|
151
164
|
targets.each do |target|
|
152
|
-
if
|
165
|
+
if data_hash[source].present? && data_hash[target].blank?
|
153
166
|
result.error "Missing property #{target.to_s.inspect} because #{source.to_s.inspect} is given."
|
154
167
|
end
|
155
168
|
end
|
@@ -161,11 +174,14 @@ module Schemacop
|
|
161
174
|
end
|
162
175
|
|
163
176
|
def cast(data)
|
164
|
-
result = {}
|
177
|
+
result = {}.with_indifferent_access
|
165
178
|
data ||= default
|
166
179
|
return nil if data.nil?
|
167
180
|
|
181
|
+
data_hash = data.dup.with_indifferent_access
|
182
|
+
|
168
183
|
property_patterns = {}
|
184
|
+
as_names = []
|
169
185
|
|
170
186
|
@properties.each_value do |prop|
|
171
187
|
if prop.name.is_a?(Regexp)
|
@@ -173,16 +189,24 @@ module Schemacop
|
|
173
189
|
next
|
174
190
|
end
|
175
191
|
|
176
|
-
|
192
|
+
as_names << prop.as&.to_s if prop.as.present?
|
177
193
|
|
178
|
-
|
179
|
-
|
194
|
+
prop_name = prop.as&.to_s || prop.name
|
195
|
+
|
196
|
+
casted_data = prop.cast(data_hash[prop.name])
|
197
|
+
|
198
|
+
if casted_data.present? || data_hash.include?(prop.name)
|
199
|
+
result[prop_name] = casted_data
|
200
|
+
end
|
201
|
+
|
202
|
+
if result[prop_name].nil? && !data_hash.include?(prop.name) && !as_names.include?(prop.name)
|
203
|
+
result.delete(prop_name)
|
180
204
|
end
|
181
205
|
end
|
182
206
|
|
183
207
|
# Handle regex properties
|
184
208
|
specified_properties = @properties.keys.to_set
|
185
|
-
additional_properties =
|
209
|
+
additional_properties = data_hash.reject { |k, _v| specified_properties.include?(k.to_s.to_sym) }
|
186
210
|
|
187
211
|
if additional_properties.any? && property_patterns.any?
|
188
212
|
additional_properties.each do |name, additional_property|
|
@@ -193,11 +217,11 @@ module Schemacop
|
|
193
217
|
end
|
194
218
|
|
195
219
|
# Handle additional properties
|
196
|
-
if options[:additional_properties]
|
197
|
-
result =
|
220
|
+
if options[:additional_properties].is_a?(TrueClass)
|
221
|
+
result = data_hash.merge(result)
|
198
222
|
elsif options[:additional_properties].is_a?(Node)
|
199
223
|
specified_properties = @properties.keys.to_set
|
200
|
-
additional_properties =
|
224
|
+
additional_properties = data_hash.reject { |k, _v| specified_properties.include?(k.to_s.to_sym) }
|
201
225
|
if additional_properties.any?
|
202
226
|
additional_properties_result = {}
|
203
227
|
additional_properties.each do |key, value|
|
@@ -218,6 +242,11 @@ module Schemacop
|
|
218
242
|
unless @options[:additional_properties].nil? || @options[:additional_properties].is_a?(TrueClass) || @options[:additional_properties].is_a?(FalseClass)
|
219
243
|
fail Schemacop::Exceptions::InvalidSchemaError, 'Option "additional_properties" must be a boolean value'
|
220
244
|
end
|
245
|
+
|
246
|
+
# Default the additional_properties option to false if it's not given
|
247
|
+
if @options[:additional_properties].nil?
|
248
|
+
@options[:additional_properties] = false
|
249
|
+
end
|
221
250
|
end
|
222
251
|
|
223
252
|
def validate_self
|
data/lib/schemacop/v3/node.rb
CHANGED
@@ -2,6 +2,7 @@ module Schemacop
|
|
2
2
|
module V3
|
3
3
|
class Node
|
4
4
|
attr_reader :name
|
5
|
+
attr_reader :as
|
5
6
|
attr_reader :default
|
6
7
|
attr_reader :title
|
7
8
|
attr_reader :description
|
@@ -32,8 +33,10 @@ module Schemacop
|
|
32
33
|
if options.delete(:cast_str)
|
33
34
|
format = NodeRegistry.name(klass)
|
34
35
|
one_of_options = {
|
35
|
-
required:
|
36
|
-
name:
|
36
|
+
required: options.delete(:required),
|
37
|
+
name: options.delete(:name),
|
38
|
+
as: options.delete(:as),
|
39
|
+
description: options.delete(:description)
|
37
40
|
}
|
38
41
|
node = create(:one_of, **one_of_options) do
|
39
42
|
self.node node
|
@@ -45,7 +48,7 @@ module Schemacop
|
|
45
48
|
end
|
46
49
|
|
47
50
|
def self.allowed_options
|
48
|
-
%i[name required default description examples enum parent options cast_str title]
|
51
|
+
%i[name required default description examples enum parent options cast_str title as]
|
49
52
|
end
|
50
53
|
|
51
54
|
def self.dsl_methods
|
@@ -69,11 +72,13 @@ module Schemacop
|
|
69
72
|
disallowed_options = options.keys - self.class.allowed_options
|
70
73
|
|
71
74
|
if disallowed_options.any?
|
72
|
-
fail "Options #{disallowed_options.inspect} are not allowed for this node."
|
75
|
+
fail Schemacop::Exceptions::InvalidSchemaError, "Options #{disallowed_options.inspect} are not allowed for this node."
|
73
76
|
end
|
74
77
|
|
75
78
|
# Assign attributes #
|
76
79
|
@name = options.delete(:name)
|
80
|
+
@name = @name.to_s unless @name.nil? || @name.is_a?(Regexp)
|
81
|
+
@as = options.delete(:as)
|
77
82
|
@required = !!options.delete(:required)
|
78
83
|
@default = options.delete(:default)
|
79
84
|
@title = options.delete(:title)
|
@@ -90,7 +95,7 @@ module Schemacop
|
|
90
95
|
# Run DSL block #
|
91
96
|
if block_given?
|
92
97
|
unless self.class.supports_children_options
|
93
|
-
fail "Node #{self.class} does not support blocks."
|
98
|
+
fail Schemacop::Exceptions::InvalidSchemaError, "Node #{self.class} does not support blocks."
|
94
99
|
end
|
95
100
|
|
96
101
|
scope = DslScope.new(self)
|
@@ -36,7 +36,13 @@ module Schemacop
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def used_external_schemas
|
39
|
-
|
39
|
+
target_children_schema = target.used_external_schemas
|
40
|
+
|
41
|
+
if schemas.include?(@path)
|
42
|
+
return target_children_schema
|
43
|
+
else
|
44
|
+
return [@path] + target_children_schema
|
45
|
+
end
|
40
46
|
end
|
41
47
|
|
42
48
|
protected
|
@@ -66,21 +66,29 @@ module Schemacop
|
|
66
66
|
end
|
67
67
|
|
68
68
|
def cast(value)
|
69
|
+
if value.present?
|
70
|
+
to_cast = value
|
71
|
+
elsif default.present?
|
72
|
+
to_cast = default
|
73
|
+
else
|
74
|
+
return nil
|
75
|
+
end
|
76
|
+
|
69
77
|
case options[:format]
|
70
78
|
when :boolean
|
71
|
-
return
|
79
|
+
return to_cast == 'true'
|
72
80
|
when :date
|
73
|
-
return Date.parse(
|
81
|
+
return Date.parse(to_cast)
|
74
82
|
when :'date-time'
|
75
|
-
return DateTime.parse(
|
83
|
+
return DateTime.parse(to_cast)
|
76
84
|
when :time
|
77
|
-
Time.parse(
|
85
|
+
Time.parse(to_cast)
|
78
86
|
when :integer
|
79
|
-
return Integer(
|
87
|
+
return Integer(to_cast)
|
80
88
|
when :number
|
81
|
-
return Float(
|
89
|
+
return Float(to_cast)
|
82
90
|
else
|
83
|
-
return
|
91
|
+
return to_cast
|
84
92
|
end
|
85
93
|
end
|
86
94
|
|
data/schemacop.gemspec
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: schemacop 3.0.0
|
2
|
+
# stub: schemacop 3.0.0 ruby lib
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "schemacop".freeze
|
6
|
-
s.version = "3.0.0
|
6
|
+
s.version = "3.0.0"
|
7
7
|
|
8
|
-
s.required_rubygems_version = Gem::Requirement.new("
|
8
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
9
9
|
s.require_paths = ["lib".freeze]
|
10
10
|
s.authors = ["Sitrox".freeze]
|
11
|
-
s.date = "2021-
|
12
|
-
s.files = [".gitignore".freeze, ".releaser_config".freeze, ".rubocop.yml".freeze, ".travis.yml".freeze, ".yardopts".freeze, "CHANGELOG.md".freeze, "Gemfile".freeze, "LICENSE".freeze, "README.md".freeze, "README_V2.md".freeze, "README_V3.md".freeze, "RUBY_VERSION".freeze, "Rakefile".freeze, "VERSION".freeze, "lib/schemacop.rb".freeze, "lib/schemacop/base_schema.rb".freeze, "lib/schemacop/exceptions.rb".freeze, "lib/schemacop/railtie.rb".freeze, "lib/schemacop/schema.rb".freeze, "lib/schemacop/schema2.rb".freeze, "lib/schemacop/schema3.rb".freeze, "lib/schemacop/scoped_env.rb".freeze, "lib/schemacop/v2.rb".freeze, "lib/schemacop/v2/caster.rb".freeze, "lib/schemacop/v2/collector.rb".freeze, "lib/schemacop/v2/dupper.rb".freeze, "lib/schemacop/v2/field_node.rb".freeze, "lib/schemacop/v2/node.rb".freeze, "lib/schemacop/v2/node_resolver.rb".freeze, "lib/schemacop/v2/node_supporting_field.rb".freeze, "lib/schemacop/v2/node_supporting_type.rb".freeze, "lib/schemacop/v2/node_with_block.rb".freeze, "lib/schemacop/v2/
|
11
|
+
s.date = "2021-02-08"
|
12
|
+
s.files = [".gitignore".freeze, ".releaser_config".freeze, ".rubocop.yml".freeze, ".travis.yml".freeze, ".yardopts".freeze, "CHANGELOG.md".freeze, "Gemfile".freeze, "LICENSE".freeze, "README.md".freeze, "README_V2.md".freeze, "README_V3.md".freeze, "RUBY_VERSION".freeze, "Rakefile".freeze, "VERSION".freeze, "lib/schemacop.rb".freeze, "lib/schemacop/base_schema.rb".freeze, "lib/schemacop/exceptions.rb".freeze, "lib/schemacop/railtie.rb".freeze, "lib/schemacop/schema.rb".freeze, "lib/schemacop/schema2.rb".freeze, "lib/schemacop/schema3.rb".freeze, "lib/schemacop/scoped_env.rb".freeze, "lib/schemacop/v2.rb".freeze, "lib/schemacop/v2/caster.rb".freeze, "lib/schemacop/v2/collector.rb".freeze, "lib/schemacop/v2/dupper.rb".freeze, "lib/schemacop/v2/field_node.rb".freeze, "lib/schemacop/v2/node.rb".freeze, "lib/schemacop/v2/node_resolver.rb".freeze, "lib/schemacop/v2/node_supporting_field.rb".freeze, "lib/schemacop/v2/node_supporting_type.rb".freeze, "lib/schemacop/v2/node_with_block.rb".freeze, "lib/schemacop/v2/validator/array_validator.rb".freeze, "lib/schemacop/v2/validator/boolean_validator.rb".freeze, "lib/schemacop/v2/validator/float_validator.rb".freeze, "lib/schemacop/v2/validator/hash_validator.rb".freeze, "lib/schemacop/v2/validator/integer_validator.rb".freeze, "lib/schemacop/v2/validator/nil_validator.rb".freeze, "lib/schemacop/v2/validator/number_validator.rb".freeze, "lib/schemacop/v2/validator/object_validator.rb".freeze, "lib/schemacop/v2/validator/string_validator.rb".freeze, "lib/schemacop/v2/validator/symbol_validator.rb".freeze, "lib/schemacop/v3.rb".freeze, "lib/schemacop/v3/all_of_node.rb".freeze, "lib/schemacop/v3/any_of_node.rb".freeze, "lib/schemacop/v3/array_node.rb".freeze, "lib/schemacop/v3/boolean_node.rb".freeze, "lib/schemacop/v3/combination_node.rb".freeze, "lib/schemacop/v3/context.rb".freeze, "lib/schemacop/v3/dsl_scope.rb".freeze, "lib/schemacop/v3/global_context.rb".freeze, "lib/schemacop/v3/hash_node.rb".freeze, "lib/schemacop/v3/integer_node.rb".freeze, "lib/schemacop/v3/is_not_node.rb".freeze, "lib/schemacop/v3/node.rb".freeze, "lib/schemacop/v3/node_registry.rb".freeze, "lib/schemacop/v3/number_node.rb".freeze, "lib/schemacop/v3/numeric_node.rb".freeze, "lib/schemacop/v3/object_node.rb".freeze, "lib/schemacop/v3/one_of_node.rb".freeze, "lib/schemacop/v3/reference_node.rb".freeze, "lib/schemacop/v3/result.rb".freeze, "lib/schemacop/v3/string_node.rb".freeze, "lib/schemacop/v3/symbol_node.rb".freeze, "schemacop.gemspec".freeze, "test/lib/test_helper.rb".freeze, "test/schemas/nested/group.rb".freeze, "test/schemas/user.rb".freeze, "test/unit/schemacop/v2/casting_test.rb".freeze, "test/unit/schemacop/v2/collector_test.rb".freeze, "test/unit/schemacop/v2/custom_check_test.rb".freeze, "test/unit/schemacop/v2/custom_if_test.rb".freeze, "test/unit/schemacop/v2/defaults_test.rb".freeze, "test/unit/schemacop/v2/empty_test.rb".freeze, "test/unit/schemacop/v2/nil_dis_allow_test.rb".freeze, "test/unit/schemacop/v2/node_resolver_test.rb".freeze, "test/unit/schemacop/v2/short_forms_test.rb".freeze, "test/unit/schemacop/v2/types_test.rb".freeze, "test/unit/schemacop/v2/validator_array_test.rb".freeze, "test/unit/schemacop/v2/validator_boolean_test.rb".freeze, "test/unit/schemacop/v2/validator_float_test.rb".freeze, "test/unit/schemacop/v2/validator_hash_test.rb".freeze, "test/unit/schemacop/v2/validator_integer_test.rb".freeze, "test/unit/schemacop/v2/validator_nil_test.rb".freeze, "test/unit/schemacop/v2/validator_number_test.rb".freeze, "test/unit/schemacop/v2/validator_object_test.rb".freeze, "test/unit/schemacop/v2/validator_string_test.rb".freeze, "test/unit/schemacop/v2/validator_symbol_test.rb".freeze, "test/unit/schemacop/v3/all_of_node_test.rb".freeze, "test/unit/schemacop/v3/any_of_node_test.rb".freeze, "test/unit/schemacop/v3/array_node_test.rb".freeze, "test/unit/schemacop/v3/boolean_node_test.rb".freeze, "test/unit/schemacop/v3/global_context_test.rb".freeze, "test/unit/schemacop/v3/hash_node_test.rb".freeze, "test/unit/schemacop/v3/integer_node_test.rb".freeze, "test/unit/schemacop/v3/is_not_node_test.rb".freeze, "test/unit/schemacop/v3/node_test.rb".freeze, "test/unit/schemacop/v3/number_node_test.rb".freeze, "test/unit/schemacop/v3/object_node_test.rb".freeze, "test/unit/schemacop/v3/one_of_node_test.rb".freeze, "test/unit/schemacop/v3/reference_node_test.rb".freeze, "test/unit/schemacop/v3/string_node_test.rb".freeze, "test/unit/schemacop/v3/symbol_node_test.rb".freeze]
|
13
13
|
s.homepage = "https://github.com/sitrox/schemacop".freeze
|
14
14
|
s.licenses = ["MIT".freeze]
|
15
15
|
s.rubygems_version = "3.0.3".freeze
|
@@ -21,6 +21,7 @@ Gem::Specification.new do |s|
|
|
21
21
|
|
22
22
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
23
23
|
s.add_runtime_dependency(%q<activesupport>.freeze, [">= 4.0"])
|
24
|
+
s.add_runtime_dependency(%q<ruby2_keywords>.freeze, ["= 0.0.4"])
|
24
25
|
s.add_development_dependency(%q<bundler>.freeze, [">= 0"])
|
25
26
|
s.add_development_dependency(%q<rake>.freeze, [">= 0"])
|
26
27
|
s.add_development_dependency(%q<minitest>.freeze, [">= 0"])
|
@@ -32,6 +33,7 @@ Gem::Specification.new do |s|
|
|
32
33
|
s.add_development_dependency(%q<simplecov>.freeze, ["= 0.21.2"])
|
33
34
|
else
|
34
35
|
s.add_dependency(%q<activesupport>.freeze, [">= 4.0"])
|
36
|
+
s.add_dependency(%q<ruby2_keywords>.freeze, ["= 0.0.4"])
|
35
37
|
s.add_dependency(%q<bundler>.freeze, [">= 0"])
|
36
38
|
s.add_dependency(%q<rake>.freeze, [">= 0"])
|
37
39
|
s.add_dependency(%q<minitest>.freeze, [">= 0"])
|
@@ -44,6 +46,7 @@ Gem::Specification.new do |s|
|
|
44
46
|
end
|
45
47
|
else
|
46
48
|
s.add_dependency(%q<activesupport>.freeze, [">= 4.0"])
|
49
|
+
s.add_dependency(%q<ruby2_keywords>.freeze, ["= 0.0.4"])
|
47
50
|
s.add_dependency(%q<bundler>.freeze, [">= 0"])
|
48
51
|
s.add_dependency(%q<rake>.freeze, [">= 0"])
|
49
52
|
s.add_dependency(%q<minitest>.freeze, [">= 0"])
|
data/test/lib/test_helper.rb
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
require 'simplecov'
|
2
|
-
SimpleCov.start
|
2
|
+
SimpleCov.start do
|
3
|
+
add_group 'v3', 'lib/schemacop/v3'
|
4
|
+
add_group 'v2', 'lib/schemacop/v2'
|
5
|
+
|
6
|
+
# We don't care about the test coverage for the
|
7
|
+
# tests themselves
|
8
|
+
add_filter 'test'
|
9
|
+
|
10
|
+
# Also enable branch coverage reporting
|
11
|
+
enable_coverage :branch
|
12
|
+
end
|
3
13
|
|
4
14
|
# TODO: Move to more sensible location
|
5
15
|
def assert_verr(&block)
|
@@ -141,7 +151,12 @@ class V3Test < SchemacopTest
|
|
141
151
|
input_data_was = Marshal.load(Marshal.dump(input_data))
|
142
152
|
result = @schema.validate(input_data)
|
143
153
|
assert_empty result.errors
|
144
|
-
|
154
|
+
|
155
|
+
if expected_data.nil?
|
156
|
+
assert_nil result.data, 'Unexpected result data.'
|
157
|
+
else
|
158
|
+
assert_equal expected_data, result.data, 'Unexpected result data.'
|
159
|
+
end
|
145
160
|
|
146
161
|
if input_data.nil?
|
147
162
|
assert_nil input_data_was, 'Expected input_data to stay the same.'
|