schemacop 3.0.0.rc3 → 3.0.2
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/CHANGELOG.md +32 -4
- data/LICENSE +1 -1
- data/README.md +1 -1
- data/README_V3.md +74 -8
- 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/caster.rb +1 -0
- data/lib/schemacop/v3/hash_node.rb +23 -14
- data/lib/schemacop/v3/node.rb +2 -2
- 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 +18 -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/global_context_test.rb +2 -0
- data/test/unit/schemacop/v3/hash_node_test.rb +94 -6
- data/test/unit/schemacop/v3/node_test.rb +14 -0
- data/test/unit/schemacop/v3/reference_node_test.rb +16 -0
- data/test/unit/schemacop/v3/string_node_test.rb +55 -0
- metadata +18 -5
- data/lib/schemacop/v2/root_node.rb +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 90acd1ba976d75dae0019274d843c5d727858655238148a10bd485973e964fba
|
4
|
+
data.tar.gz: 40e63d805b815c61bcf342fc449fa5f0be506f386b7a315df33c9baada0723cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff575cb152372e2cf0685ae1f5ac123c88245a6bb23acbdc7dd0daa27098d245fc90f9e6f5d381d9490d4476109d22c01a86df5744e84b872c6708e4841b7a06
|
7
|
+
data.tar.gz: fda34143fc547221dadfe7cdcb24206185e2b1736ad8e4925e70928fb7d22a5f280f54a70503b5cdf7380f30fcdf250f5663eeae26323dec8dbabd4e686928dc
|
data/CHANGELOG.md
CHANGED
@@ -10,19 +10,47 @@
|
|
10
10
|
### Changes
|
11
11
|
-->
|
12
12
|
|
13
|
-
## 3.0.
|
13
|
+
## 3.0.2 (2021-02-14)
|
14
|
+
|
15
|
+
* Fix #15 Code to ignore Zeitwerk fails when Zeitwerk is disabled
|
16
|
+
|
17
|
+
## 3.0.1 (2021-02-11)
|
18
|
+
|
19
|
+
* Add format `symbol` to strings
|
20
|
+
|
21
|
+
## 3.0.0 (2021-02-08)
|
22
|
+
|
23
|
+
* Setup Zeitwerk ignores for Rails applications
|
24
|
+
|
25
|
+
* Read previous `3.0.0.rcX` entries for all changes included
|
26
|
+
in this stable release
|
27
|
+
|
28
|
+
## 3.0.0.rc5 (2021-02-05)
|
29
|
+
|
30
|
+
* Use `ruby2_keywords` for compatibility with ruby `2.6.2`
|
31
|
+
|
32
|
+
## 3.0.0.rc4 (2021-02-02)
|
33
|
+
|
34
|
+
* Fix some minor bugs
|
35
|
+
|
36
|
+
* Improve documentation
|
37
|
+
|
38
|
+
* `used_external_schemas` for the `ReferenceNode` is now applied
|
39
|
+
recursively
|
40
|
+
|
41
|
+
## 3.0.0.rc3 (2021-01-28)
|
14
42
|
|
15
43
|
* Add minor improvements to the documentation
|
16
44
|
|
17
45
|
* Internal restructuring, no changes in API
|
18
46
|
|
19
|
-
## 3.0.0.rc2 (
|
47
|
+
## 3.0.0.rc2 (2021-01-28)
|
20
48
|
|
21
49
|
* Represent node names as strings internally
|
22
50
|
|
23
51
|
* Update documentation
|
24
52
|
|
25
|
-
## 3.0.0.rc1 (
|
53
|
+
## 3.0.0.rc1 (2021-01-22)
|
26
54
|
|
27
55
|
* Add support for ruby `3.0.0`
|
28
56
|
|
@@ -30,7 +58,7 @@
|
|
30
58
|
|
31
59
|
* Document all `v3` nodes
|
32
60
|
|
33
|
-
## 3.0.0.rc0 (
|
61
|
+
## 3.0.0.rc0 (2021-01-14)
|
34
62
|
|
35
63
|
* Add `Schemacop::Schema3`
|
36
64
|
|
data/LICENSE
CHANGED
data/README.md
CHANGED
data/README_V3.md
CHANGED
@@ -90,7 +90,7 @@ Schemacop can raise the following exceptions:
|
|
90
90
|
Example:
|
91
91
|
|
92
92
|
```ruby
|
93
|
-
Schemacop::Schema3.new do
|
93
|
+
Schemacop::Schema3.new :hash do
|
94
94
|
int!
|
95
95
|
end
|
96
96
|
|
@@ -241,6 +241,9 @@ transformed into various types.
|
|
241
241
|
* `number`
|
242
242
|
The string must be a number and will be casted to a ruby `Float` object.
|
243
243
|
|
244
|
+
* `symbol`
|
245
|
+
The string can be anything and will be casted to a ruby `Symbol` object.
|
246
|
+
|
244
247
|
#### Examples
|
245
248
|
|
246
249
|
```ruby
|
@@ -380,7 +383,7 @@ schema.validate!(1234) # => Schemacop::Exceptions::ValidationError: /: Invali
|
|
380
383
|
### Array
|
381
384
|
|
382
385
|
Type: `:array`\
|
383
|
-
DSL: `
|
386
|
+
DSL: `ary`
|
384
387
|
|
385
388
|
The array type represents a ruby `Array`.
|
386
389
|
It consists of one or multiple values, which can be validated using arbitrary nodes.
|
@@ -587,8 +590,9 @@ It consists of key-value-pairs that can be validated using arbitrary nodes.
|
|
587
590
|
|
588
591
|
* `additional_properties`
|
589
592
|
This option specifies whether additional, unspecified properties are allowed
|
590
|
-
(`true`) or not (`false`). By default, this is `
|
591
|
-
|
593
|
+
(`true`) or not (`false`). By default, this is `false`, i.e. you need to
|
594
|
+
explicitly set it to `true` if you want to allow arbitrary additional properties,
|
595
|
+
or use the `add` DSL method (see below) to specify additional properties.
|
592
596
|
|
593
597
|
* `property_names`
|
594
598
|
This option allows to specify a regexp pattern (as string) which validates the
|
@@ -673,6 +677,61 @@ end
|
|
673
677
|
schema.validate!(foo: 42, 'foo' => 43) # => Schemacop::Exceptions::ValidationError: /: Has 1 ambiguous properties: [:foo].
|
674
678
|
```
|
675
679
|
|
680
|
+
In addition to the normal node options (which vary from type to type, check
|
681
|
+
the respective nodes for details), properties also support the `as` option.
|
682
|
+
|
683
|
+
With this, you can "rename" properties in the output:
|
684
|
+
|
685
|
+
```ruby
|
686
|
+
schema = Schemacop::Schema3.new :hash do
|
687
|
+
int! :foo, as: :bar
|
688
|
+
end
|
689
|
+
|
690
|
+
schema.validate!({foo: 42}) # => {"bar"=>42}
|
691
|
+
```
|
692
|
+
|
693
|
+
Please note that if you specify a node with the same property name multiple
|
694
|
+
times, or use the `as` option to rename a node to the same name of another
|
695
|
+
node, the last specified node will be used:
|
696
|
+
|
697
|
+
```ruby
|
698
|
+
schema = Schemacop::Schema3.new :hash do
|
699
|
+
int? :foo
|
700
|
+
str? :foo
|
701
|
+
end
|
702
|
+
|
703
|
+
schema.validate!({foo: 1}) # => Schemacop::Exceptions::ValidationError: /foo: Invalid type, expected "string".
|
704
|
+
schema.validate!({foo: 'bar'}) # => {"foo"=>"bar"}
|
705
|
+
```
|
706
|
+
|
707
|
+
As well as:
|
708
|
+
|
709
|
+
```ruby
|
710
|
+
schema = Schemacop::Schema3.new :hash do
|
711
|
+
int? :foo
|
712
|
+
int? :bar, as: :foo
|
713
|
+
end
|
714
|
+
|
715
|
+
schema.validate!({foo: 1}) # => {"foo"=>1}
|
716
|
+
schema.validate!({foo: 1, bar: 2}) # => {"foo"=>2}
|
717
|
+
schema.validate!({bar: 2}) # => {"foo"=>2}
|
718
|
+
```
|
719
|
+
|
720
|
+
If you want to specify a node which may be one of multiple types, use the `one_of`
|
721
|
+
node (see further down for more details):
|
722
|
+
|
723
|
+
```ruby
|
724
|
+
schema = Schemacop::Schema3.new :hash do
|
725
|
+
one_of! :foo do
|
726
|
+
int
|
727
|
+
str
|
728
|
+
end
|
729
|
+
end
|
730
|
+
|
731
|
+
schema.validate!({foo: 1}) # => {"foo"=>1}
|
732
|
+
schema.validate!({foo: 'bar'}) # => {"foo"=>"bar"}
|
733
|
+
```
|
734
|
+
|
676
735
|
##### Pattern properties
|
677
736
|
|
678
737
|
In addition to symbols, property keys can also be a regular expression. Here,
|
@@ -1135,14 +1194,17 @@ local schemas > context schemas > global schemas
|
|
1135
1194
|
|
1136
1195
|
Where:
|
1137
1196
|
|
1138
|
-
* local schemas: Defined by using the DSL method
|
1197
|
+
* local schemas: Defined by using the DSL method `scm`
|
1139
1198
|
* context schemas: Defined in the current context using `context.schema`
|
1140
1199
|
* global schemas: Defined in a ruby file in the load path
|
1141
1200
|
|
1142
1201
|
### Rails applications
|
1143
1202
|
|
1144
|
-
In Rails applications, your schemas are automatically eager-
|
1145
|
-
path `'app/schemas'` when your application is started
|
1203
|
+
In Rails applications, your schemas are automatically eager-loaded from the load
|
1204
|
+
path `'app/schemas'` when your application is started, unless your application
|
1205
|
+
is running in the `DEVELOPMENT` environment. In the `DEVELOPMENT` environment,
|
1206
|
+
schemas are loaded each time when they are used, and as such you can make changes
|
1207
|
+
to your external schemas without having to restart the server each time.
|
1146
1208
|
|
1147
1209
|
After starting your application, you can reference them like normally defined
|
1148
1210
|
reference schemas, with the name being relative to the load path.
|
@@ -1190,8 +1252,12 @@ schema.validate!({usr: {first_name: 'Joe', last_name: 'Doe', groups: [{name: 'fo
|
|
1190
1252
|
### Non-Rails applications
|
1191
1253
|
|
1192
1254
|
Usage in non-Rails applications is the same as with usage in Rails applications,
|
1193
|
-
however you need to eager load the schemas yourself:
|
1255
|
+
however you might need to eager load the schemas yourself:
|
1194
1256
|
|
1195
1257
|
```ruby
|
1196
1258
|
Schemacop::V3::GlobalContext.eager_load!
|
1197
1259
|
```
|
1260
|
+
|
1261
|
+
As mentioned before, you can also use the external schemas without having to
|
1262
|
+
eager-load them, but if you use the schemas multiple times, it might be better
|
1263
|
+
to eager-load them on start of your application / script.
|
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.
|
1
|
+
3.0.2
|
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) && Rails.autoloaders.zeitwerk_enabled?
|
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/caster.rb
CHANGED
@@ -68,7 +68,7 @@ module Schemacop
|
|
68
68
|
|
69
69
|
# In schemacop, by default, additional properties are not allowed,
|
70
70
|
# the users explicitly need to enable additional properties
|
71
|
-
if options[:additional_properties]
|
71
|
+
if options[:additional_properties].is_a?(TrueClass)
|
72
72
|
json[:additionalProperties] = true
|
73
73
|
elsif options[:additional_properties].is_a?(Node)
|
74
74
|
json[:additionalProperties] = options[:additional_properties].as_json
|
@@ -141,7 +141,9 @@ module Schemacop
|
|
141
141
|
result.error "Property name #{name.inspect} does not match #{options[:property_names].inspect}."
|
142
142
|
end
|
143
143
|
|
144
|
-
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?
|
145
147
|
match = property_patterns.keys.find { |p| p.match?(name.to_s) }
|
146
148
|
if match
|
147
149
|
result.in_path(name) do
|
@@ -176,16 +178,10 @@ module Schemacop
|
|
176
178
|
data ||= default
|
177
179
|
return nil if data.nil?
|
178
180
|
|
179
|
-
|
180
|
-
data_hash = data.with_indifferent_access
|
181
|
-
|
182
|
-
if original_data_hash.size != data_hash.size
|
183
|
-
ambiguous_properties = original_data_hash.keys - data_hash.keys
|
184
|
-
|
185
|
-
result.error "Has #{ambiguous_properties.size} ambiguous properties: #{ambiguous_properties}."
|
186
|
-
end
|
181
|
+
data_hash = data.dup.with_indifferent_access
|
187
182
|
|
188
183
|
property_patterns = {}
|
184
|
+
as_names = []
|
189
185
|
|
190
186
|
@properties.each_value do |prop|
|
191
187
|
if prop.name.is_a?(Regexp)
|
@@ -193,10 +189,18 @@ module Schemacop
|
|
193
189
|
next
|
194
190
|
end
|
195
191
|
|
196
|
-
|
192
|
+
as_names << prop.as&.to_s if prop.as.present?
|
197
193
|
|
198
|
-
|
199
|
-
|
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)
|
200
204
|
end
|
201
205
|
end
|
202
206
|
|
@@ -213,7 +217,7 @@ module Schemacop
|
|
213
217
|
end
|
214
218
|
|
215
219
|
# Handle additional properties
|
216
|
-
if options[:additional_properties]
|
220
|
+
if options[:additional_properties].is_a?(TrueClass)
|
217
221
|
result = data_hash.merge(result)
|
218
222
|
elsif options[:additional_properties].is_a?(Node)
|
219
223
|
specified_properties = @properties.keys.to_set
|
@@ -238,6 +242,11 @@ module Schemacop
|
|
238
242
|
unless @options[:additional_properties].nil? || @options[:additional_properties].is_a?(TrueClass) || @options[:additional_properties].is_a?(FalseClass)
|
239
243
|
fail Schemacop::Exceptions::InvalidSchemaError, 'Option "additional_properties" must be a boolean value'
|
240
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
|
241
250
|
end
|
242
251
|
|
243
252
|
def validate_self
|
data/lib/schemacop/v3/node.rb
CHANGED
@@ -72,7 +72,7 @@ module Schemacop
|
|
72
72
|
disallowed_options = options.keys - self.class.allowed_options
|
73
73
|
|
74
74
|
if disallowed_options.any?
|
75
|
-
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."
|
76
76
|
end
|
77
77
|
|
78
78
|
# Assign attributes #
|
@@ -95,7 +95,7 @@ module Schemacop
|
|
95
95
|
# Run DSL block #
|
96
96
|
if block_given?
|
97
97
|
unless self.class.supports_children_options
|
98
|
-
fail "Node #{self.class} does not support blocks."
|
98
|
+
fail Schemacop::Exceptions::InvalidSchemaError, "Node #{self.class} does not support blocks."
|
99
99
|
end
|
100
100
|
|
101
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
|
@@ -16,6 +16,7 @@ module Schemacop
|
|
16
16
|
email: URI::MailTo::EMAIL_REGEXP,
|
17
17
|
boolean: /^(true|false)$/,
|
18
18
|
binary: nil,
|
19
|
+
symbol: nil,
|
19
20
|
integer: /^-?[0-9]+$/,
|
20
21
|
number: /^-?[0-9]+(\.[0-9]+)?$/
|
21
22
|
}.freeze
|
@@ -66,21 +67,31 @@ module Schemacop
|
|
66
67
|
end
|
67
68
|
|
68
69
|
def cast(value)
|
70
|
+
if value.present?
|
71
|
+
to_cast = value
|
72
|
+
elsif default.present?
|
73
|
+
to_cast = default
|
74
|
+
else
|
75
|
+
return nil
|
76
|
+
end
|
77
|
+
|
69
78
|
case options[:format]
|
70
79
|
when :boolean
|
71
|
-
return
|
80
|
+
return to_cast == 'true'
|
72
81
|
when :date
|
73
|
-
return Date.parse(
|
82
|
+
return Date.parse(to_cast)
|
74
83
|
when :'date-time'
|
75
|
-
return DateTime.parse(
|
84
|
+
return DateTime.parse(to_cast)
|
76
85
|
when :time
|
77
|
-
Time.parse(
|
86
|
+
Time.parse(to_cast)
|
78
87
|
when :integer
|
79
|
-
return Integer(
|
88
|
+
return Integer(to_cast)
|
80
89
|
when :number
|
81
|
-
return Float(
|
90
|
+
return Float(to_cast)
|
91
|
+
when :symbol
|
92
|
+
return to_cast.to_sym
|
82
93
|
else
|
83
|
-
return
|
94
|
+
return to_cast
|
84
95
|
end
|
85
96
|
end
|
86
97
|
|
data/schemacop.gemspec
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: schemacop 3.0.
|
2
|
+
# stub: schemacop 3.0.2 ruby lib
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "schemacop".freeze
|
6
|
-
s.version = "3.0.
|
6
|
+
s.version = "3.0.2"
|
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-14"
|
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.'
|
@@ -115,6 +115,43 @@ module Schemacop
|
|
115
115
|
assert_equal expected_float, s.validate!(float_field: '')
|
116
116
|
assert_equal expected_float, s.validate!(float_field: ' ')
|
117
117
|
end
|
118
|
+
|
119
|
+
def test_float_to_integer
|
120
|
+
s = Schema.new do
|
121
|
+
req :foo, :integer, cast: [Float]
|
122
|
+
end
|
123
|
+
|
124
|
+
assert_equal({ foo: 42 }, s.validate!(foo: 42.0))
|
125
|
+
assert_equal({ foo: 42 }, s.validate!(foo: Float(42)))
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_integer_to_float
|
129
|
+
s = Schema.new do
|
130
|
+
req :foo, :float, cast: [Integer]
|
131
|
+
end
|
132
|
+
|
133
|
+
assert_equal({ foo: 42.0 }, s.validate!(foo: 42))
|
134
|
+
assert_equal({ foo: 42.0 }, s.validate!(foo: Integer(42)))
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_invalid_cast_option
|
138
|
+
s = Schema.new do
|
139
|
+
req :foo, :integer, cast: true
|
140
|
+
end
|
141
|
+
|
142
|
+
assert_raises Schemacop::Exceptions::InvalidSchemaError do
|
143
|
+
s.validate!({ foo: '42' })
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
def test_impossible_cast
|
148
|
+
s = Schema.new do
|
149
|
+
req :foo, :integer, cast: [String]
|
150
|
+
end
|
151
|
+
|
152
|
+
assert_equal({ foo: 42 }, s.validate!(foo: '42'))
|
153
|
+
assert_verr { s.validate!(foo: 'foo') }
|
154
|
+
end
|
118
155
|
end
|
119
156
|
end
|
120
157
|
end
|
@@ -90,6 +90,17 @@ module Schemacop
|
|
90
90
|
assert_verr { s.validate!(o: true) }
|
91
91
|
assert_verr { s.validate!(r: nil, r_nil: false, o: true) }
|
92
92
|
end
|
93
|
+
|
94
|
+
def test_invalid_hash
|
95
|
+
s = Schema.new do
|
96
|
+
type :hash do
|
97
|
+
req :foo
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
assert_verr { s.validate!({ foo: 42, 'foo' => 42 }) }
|
102
|
+
assert_nothing_raised { s.validate!({ foo: 42 }.with_indifferent_access) }
|
103
|
+
end
|
93
104
|
end
|
94
105
|
end
|
95
106
|
end
|
@@ -25,8 +25,10 @@ module Schemacop
|
|
25
25
|
|
26
26
|
def test_schemas
|
27
27
|
assert_equal({}, GlobalContext.instance.schemas)
|
28
|
+
assert_equal({}, GlobalContext.schemas)
|
28
29
|
GlobalContext.instance.eager_load!
|
29
30
|
assert_equal(%i[nested/group user], GlobalContext.instance.schemas.keys)
|
31
|
+
assert_equal(%i[nested/group user], GlobalContext.schemas.keys)
|
30
32
|
assert_is_a Node, GlobalContext.instance.schemas.values.first
|
31
33
|
end
|
32
34
|
|
@@ -16,7 +16,7 @@ module Schemacop
|
|
16
16
|
assert_json(type: :object, additionalProperties: false)
|
17
17
|
end
|
18
18
|
|
19
|
-
def
|
19
|
+
def test_additional_properties_false_by_default
|
20
20
|
schema
|
21
21
|
assert_validation({})
|
22
22
|
assert_validation(foo: :bar, bar: :baz) do
|
@@ -26,6 +26,17 @@ module Schemacop
|
|
26
26
|
assert_json(type: :object, additionalProperties: false)
|
27
27
|
end
|
28
28
|
|
29
|
+
def test_additional_properties_false
|
30
|
+
schema :hash, additional_properties: false
|
31
|
+
|
32
|
+
assert_validation({})
|
33
|
+
assert_validation(foo: :bar, bar: :baz) do
|
34
|
+
error '/', 'Obsolete property "foo".'
|
35
|
+
error '/', 'Obsolete property "bar".'
|
36
|
+
end
|
37
|
+
assert_json(type: :object, additionalProperties: false)
|
38
|
+
end
|
39
|
+
|
29
40
|
def test_additional_properties_true
|
30
41
|
schema :hash, additional_properties: true
|
31
42
|
assert_validation({})
|
@@ -874,11 +885,88 @@ module Schemacop
|
|
874
885
|
end
|
875
886
|
end
|
876
887
|
|
877
|
-
|
878
|
-
|
879
|
-
|
880
|
-
|
881
|
-
|
888
|
+
def test_invalid_options
|
889
|
+
assert_raises_with_message Schemacop::Exceptions::InvalidSchemaError, 'Options [:foo] are not allowed for this node.' do
|
890
|
+
schema :hash, foo: 'bar' do
|
891
|
+
int! :id
|
892
|
+
end
|
893
|
+
end
|
894
|
+
end
|
895
|
+
|
896
|
+
def test_casting_optional
|
897
|
+
schema :hash do
|
898
|
+
str? :foo, format: :integer
|
899
|
+
end
|
900
|
+
|
901
|
+
assert_validation(nil)
|
902
|
+
assert_validation({})
|
903
|
+
|
904
|
+
assert_cast(nil, nil)
|
905
|
+
assert_cast({}, {}.with_indifferent_access)
|
906
|
+
end
|
907
|
+
|
908
|
+
def test_as_option
|
909
|
+
schema :hash do
|
910
|
+
int! :foo, as: :bar
|
911
|
+
end
|
912
|
+
|
913
|
+
assert_validation(nil)
|
914
|
+
assert_validation({ foo: 42 })
|
915
|
+
assert_validation({ bar: 13 }) do
|
916
|
+
error '/', 'Obsolete property "bar".'
|
917
|
+
error '/foo', 'Value must be given.'
|
918
|
+
end
|
919
|
+
|
920
|
+
assert_validation({ foo: '13' }) do
|
921
|
+
error '/foo', 'Invalid type, expected "integer".'
|
922
|
+
end
|
923
|
+
|
924
|
+
assert_cast(nil, nil)
|
925
|
+
assert_cast({ foo: 42 }, { bar: 42 }.with_indifferent_access)
|
926
|
+
end
|
927
|
+
|
928
|
+
def test_as_option_overriding
|
929
|
+
schema :hash do
|
930
|
+
int? :foo, as: :bar
|
931
|
+
int? :bar
|
932
|
+
end
|
933
|
+
|
934
|
+
assert_validation(nil)
|
935
|
+
assert_validation({})
|
936
|
+
assert_validation({ foo: 42 })
|
937
|
+
assert_validation({ foo: 42, bar: 13 })
|
938
|
+
|
939
|
+
assert_validation({ foo: '13' }) do
|
940
|
+
error '/foo', 'Invalid type, expected "integer".'
|
941
|
+
end
|
942
|
+
|
943
|
+
# assert_cast(nil, nil)
|
944
|
+
assert_cast({ foo: 42 }, { bar: 42 }.with_indifferent_access)
|
945
|
+
assert_cast({ foo: 42, bar: 13 }, { bar: 13 }.with_indifferent_access)
|
946
|
+
assert_cast({ bar: 13, foo: 42 }, { bar: 13 }.with_indifferent_access)
|
947
|
+
|
948
|
+
# Swap order
|
949
|
+
schema :hash do
|
950
|
+
int? :bar
|
951
|
+
int! :foo, as: :bar
|
952
|
+
end
|
953
|
+
|
954
|
+
assert_validation(nil)
|
955
|
+
assert_validation({ foo: 42 })
|
956
|
+
assert_validation({ foo: 42, bar: 13 })
|
957
|
+
assert_validation({ bar: 13 }) do
|
958
|
+
error '/foo', 'Value must be given.'
|
959
|
+
end
|
960
|
+
|
961
|
+
assert_validation({ foo: '13' }) do
|
962
|
+
error '/foo', 'Invalid type, expected "integer".'
|
963
|
+
end
|
964
|
+
|
965
|
+
assert_cast(nil, nil)
|
966
|
+
assert_cast({ foo: 42 }, { bar: 42 }.with_indifferent_access)
|
967
|
+
assert_cast({ foo: 42, bar: 13 }, { bar: 42 }.with_indifferent_access)
|
968
|
+
assert_cast({ bar: 13, foo: 42 }, { bar: 42 }.with_indifferent_access)
|
969
|
+
end
|
882
970
|
end
|
883
971
|
end
|
884
972
|
end
|
@@ -143,6 +143,20 @@ module Schemacop
|
|
143
143
|
error '/[0]', 'Value must be given.'
|
144
144
|
end
|
145
145
|
end
|
146
|
+
|
147
|
+
def test_not_support_block
|
148
|
+
assert_raises_with_message Schemacop::Exceptions::InvalidSchemaError, 'Node Schemacop::V3::IntegerNode does not support blocks.' do
|
149
|
+
schema :integer do
|
150
|
+
int :foo
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
def test_node_no_children
|
156
|
+
@schema = Schemacop::Schema3.new
|
157
|
+
|
158
|
+
assert_equal(@schema.root.children, [])
|
159
|
+
end
|
146
160
|
end
|
147
161
|
end
|
148
162
|
end
|
@@ -249,6 +249,8 @@ module Schemacop
|
|
249
249
|
ref? :node, :Node
|
250
250
|
end
|
251
251
|
|
252
|
+
assert_equal(@schema.root.used_external_schemas, [])
|
253
|
+
|
252
254
|
assert_validation({})
|
253
255
|
assert_validation(node: { name: '1', children: [{ name: '1' }, { name: '2' }] })
|
254
256
|
assert_validation(
|
@@ -313,6 +315,8 @@ module Schemacop
|
|
313
315
|
ref! :person, :Person
|
314
316
|
end
|
315
317
|
|
318
|
+
assert_equal(@schema.root.used_external_schemas, %i[Person PersonInfo])
|
319
|
+
|
316
320
|
assert_validation(person: { first_name: 'John', last_name: 'Doe' })
|
317
321
|
assert_validation(person: { first_name: 'John', last_name: 'Doe', info: { born_at: '1990-01-13' } })
|
318
322
|
assert_validation(person: { first_name_x: 'John', last_name: 'Doe' }) do
|
@@ -323,6 +327,18 @@ module Schemacop
|
|
323
327
|
error '/person/info/born_at', 'String does not match format "date".'
|
324
328
|
end
|
325
329
|
end
|
330
|
+
|
331
|
+
with_context context do
|
332
|
+
schema do
|
333
|
+
scm :PersonNode do
|
334
|
+
ref! :person, :Person
|
335
|
+
end
|
336
|
+
|
337
|
+
ref! :personNode, :PersonNode
|
338
|
+
end
|
339
|
+
|
340
|
+
assert_equal(@schema.root.used_external_schemas, %i[Person PersonInfo])
|
341
|
+
end
|
326
342
|
end
|
327
343
|
|
328
344
|
def test_defaults
|
@@ -111,6 +111,9 @@ module Schemacop
|
|
111
111
|
assert_validation 'foo 2020-01-29 bar' do
|
112
112
|
error '/', 'String does not match format "date".'
|
113
113
|
end
|
114
|
+
|
115
|
+
assert_cast(nil, nil)
|
116
|
+
assert_cast('2020-01-13', Date.new(2020, 1, 13))
|
114
117
|
end
|
115
118
|
|
116
119
|
def test_format_date_time
|
@@ -132,6 +135,9 @@ module Schemacop
|
|
132
135
|
assert_validation '2018-11-13T20:20:39Y' do
|
133
136
|
error '/', 'String does not match format "date-time".'
|
134
137
|
end
|
138
|
+
|
139
|
+
assert_cast(nil, nil)
|
140
|
+
assert_cast('2018-11-13T20:20:39+00:00', DateTime.new(2018, 11, 13, 20, 20, 39))
|
135
141
|
end
|
136
142
|
|
137
143
|
def test_format_email
|
@@ -154,6 +160,26 @@ module Schemacop
|
|
154
160
|
assert_validation '@john@example.com' do
|
155
161
|
error '/', 'String does not match format "email".'
|
156
162
|
end
|
163
|
+
|
164
|
+
assert_cast(nil, nil)
|
165
|
+
assert_cast('john.doe@example.com', 'john.doe@example.com')
|
166
|
+
end
|
167
|
+
|
168
|
+
def test_format_symbol
|
169
|
+
schema :string, format: :symbol
|
170
|
+
|
171
|
+
assert_json(type: :string, format: :symbol)
|
172
|
+
|
173
|
+
assert_validation 'foobar'
|
174
|
+
assert_validation ''
|
175
|
+
|
176
|
+
assert_validation 234 do
|
177
|
+
error '/', 'Invalid type, expected "string".'
|
178
|
+
end
|
179
|
+
|
180
|
+
assert_cast(nil, nil)
|
181
|
+
assert_cast('foobar', :foobar)
|
182
|
+
assert_cast('039n23$g- sfk3/', :'039n23$g- sfk3/')
|
157
183
|
end
|
158
184
|
|
159
185
|
def test_enum
|
@@ -187,18 +213,24 @@ module Schemacop
|
|
187
213
|
|
188
214
|
assert_cast 'true', true
|
189
215
|
assert_cast 'false', false
|
216
|
+
|
217
|
+
assert_cast nil, nil
|
190
218
|
end
|
191
219
|
|
192
220
|
def test_time_casting
|
193
221
|
schema :string, format: :time
|
194
222
|
assert_json(type: :string, format: :time)
|
195
223
|
assert_cast '20:30:39+00:00', Time.strptime('20:30:39+00:00', '%H:%M:%S%z')
|
224
|
+
|
225
|
+
assert_cast nil, nil
|
196
226
|
end
|
197
227
|
|
198
228
|
def test_date_casting
|
199
229
|
schema :string, format: :date
|
200
230
|
assert_json(type: :string, format: :date)
|
201
231
|
assert_cast '2018-11-13', Date.new(2018, 11, 13)
|
232
|
+
|
233
|
+
assert_cast nil, nil
|
202
234
|
end
|
203
235
|
|
204
236
|
def test_date_time_casting
|
@@ -207,12 +239,16 @@ module Schemacop
|
|
207
239
|
assert_cast '2018-11-13T20:20:39+00:00', DateTime.new(2018, 11, 13, 20, 20, 39)
|
208
240
|
assert_cast '2018-11-13T20:20:39Z', DateTime.new(2018, 11, 13, 20, 20, 39)
|
209
241
|
assert_cast '2018-11-13T20:20:39+01:00', DateTime.new(2018, 11, 13, 20, 20, 39, '+1')
|
242
|
+
|
243
|
+
assert_cast nil, nil
|
210
244
|
end
|
211
245
|
|
212
246
|
def test_email_casting
|
213
247
|
schema :string, format: :email
|
214
248
|
assert_json(type: :string, format: :email)
|
215
249
|
assert_cast 'support@example.com', 'support@example.com'
|
250
|
+
|
251
|
+
assert_cast nil, nil
|
216
252
|
end
|
217
253
|
|
218
254
|
def test_default
|
@@ -233,6 +269,25 @@ module Schemacop
|
|
233
269
|
assert_cast(nil, 'Hello')
|
234
270
|
end
|
235
271
|
|
272
|
+
def test_default_casting
|
273
|
+
schema :string, format: :integer, default: '42'
|
274
|
+
|
275
|
+
assert_json(
|
276
|
+
type: :string,
|
277
|
+
format: :integer,
|
278
|
+
default: '42'
|
279
|
+
)
|
280
|
+
|
281
|
+
assert_validation(nil)
|
282
|
+
assert_validation('123')
|
283
|
+
assert_validation(5) do
|
284
|
+
error '/', 'Invalid type, expected "string".'
|
285
|
+
end
|
286
|
+
|
287
|
+
assert_cast('123', 123)
|
288
|
+
assert_cast(nil, 42)
|
289
|
+
end
|
290
|
+
|
236
291
|
# Helper function that checks for all the options if the option is
|
237
292
|
# an integer or something else, in which case it needs to raise
|
238
293
|
def validate_self_should_error(value_to_check)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schemacop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sitrox
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-02-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '4.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: ruby2_keywords
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.0.4
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.0.4
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -188,7 +202,6 @@ files:
|
|
188
202
|
- lib/schemacop/v2/node_supporting_field.rb
|
189
203
|
- lib/schemacop/v2/node_supporting_type.rb
|
190
204
|
- lib/schemacop/v2/node_with_block.rb
|
191
|
-
- lib/schemacop/v2/root_node.rb
|
192
205
|
- lib/schemacop/v2/validator/array_validator.rb
|
193
206
|
- lib/schemacop/v2/validator/boolean_validator.rb
|
194
207
|
- lib/schemacop/v2/validator/float_validator.rb
|
@@ -275,9 +288,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
275
288
|
version: '0'
|
276
289
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
277
290
|
requirements:
|
278
|
-
- - "
|
291
|
+
- - ">="
|
279
292
|
- !ruby/object:Gem::Version
|
280
|
-
version:
|
293
|
+
version: '0'
|
281
294
|
requirements: []
|
282
295
|
rubygems_version: 3.1.4
|
283
296
|
signing_key:
|
File without changes
|