schemacop 3.0.13 → 3.0.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README_V3.md +3 -0
- data/VERSION +1 -1
- data/lib/schemacop/v3/hash_node.rb +1 -1
- data/lib/schemacop/v3/node.rb +2 -2
- data/lib/schemacop/v3/string_node.rb +13 -10
- data/schemacop.gemspec +3 -3
- data/test/unit/schemacop/v3/boolean_node_test.rb +32 -0
- data/test/unit/schemacop/v3/string_node_test.rb +24 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 45a0558e32f2c4a8e4d9db631ac874629ed7e92a378a177266a216b9e35295bd
|
4
|
+
data.tar.gz: fa2da0867bf598a32ba7728b246343f6bf3849aa1ccdddf9093dcd360df2b53e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 557da4f2765fc6a9c081b1b894f57b9acb8f3f16ff72c56589064672d060b1879b4d68a498692aeb4764b78ab1091de9b5b0a8dbd4b0ebc0e8bc401875ff5167
|
7
|
+
data.tar.gz: 54748996bd7ea09dda23163c808e32300e898ceb3910d1decfaa0516d49a268d79afeb9c9292f3a3fbc6d5f128ba8de1470111c66470585772b5903580088cbb
|
data/CHANGELOG.md
CHANGED
data/README_V3.md
CHANGED
@@ -246,6 +246,9 @@ transformed into various types.
|
|
246
246
|
* `number`
|
247
247
|
The string must be a number and will be casted to a ruby `Float` object.
|
248
248
|
|
249
|
+
* `integer_list`
|
250
|
+
The string must consist of comma-separated integers casted to a ruby `Array<Integer>` object
|
251
|
+
|
249
252
|
* `symbol`
|
250
253
|
The string can be anything and will be casted to a ruby `Symbol` object.
|
251
254
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.0.
|
1
|
+
3.0.14
|
data/lib/schemacop/v3/node.rb
CHANGED
@@ -178,7 +178,7 @@ module Schemacop
|
|
178
178
|
json[:title] = @title if @title
|
179
179
|
json[context.swagger_json? ? :example : :examples] = @examples if @examples
|
180
180
|
json[:description] = @description if @description
|
181
|
-
json[:default] = @default
|
181
|
+
json[:default] = @default unless @default.nil?
|
182
182
|
json[:enum] = @enum.to_a if @enum
|
183
183
|
|
184
184
|
return json.as_json
|
@@ -197,7 +197,7 @@ module Schemacop
|
|
197
197
|
|
198
198
|
# Apply default #
|
199
199
|
if data.nil?
|
200
|
-
if default
|
200
|
+
if !default.nil?
|
201
201
|
data = default
|
202
202
|
else
|
203
203
|
return nil
|
@@ -9,15 +9,16 @@ module Schemacop
|
|
9
9
|
|
10
10
|
# rubocop:disable Layout/LineLength
|
11
11
|
FORMAT_PATTERNS = {
|
12
|
-
date:
|
13
|
-
'date-time':
|
14
|
-
time:
|
15
|
-
email:
|
16
|
-
boolean:
|
17
|
-
binary:
|
18
|
-
symbol:
|
19
|
-
integer:
|
20
|
-
number:
|
12
|
+
date: /^([0-9]{4})-?(1[0-2]|0[1-9])-?(3[01]|0[1-9]|[12][0-9])$/,
|
13
|
+
'date-time': /^(-?(?:[1-9][0-9]*)?[0-9]{4})-(1[0-2]|0[1-9])-(3[01]|0[1-9]|[12][0-9])T(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])(\.[0-9]+)?(Z|[+-](?:2[0-3]|[01][0-9]):[0-5][0-9])?$/,
|
14
|
+
time: /^(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])(\.[0-9]+)?(Z|[+-](?:2[0-3]|[01][0-9]):[0-5][0-9])?$/,
|
15
|
+
email: URI::MailTo::EMAIL_REGEXP,
|
16
|
+
boolean: /^(true|false|0|1)$/,
|
17
|
+
binary: nil,
|
18
|
+
symbol: nil,
|
19
|
+
integer: /^-?[0-9]+$/,
|
20
|
+
number: /^-?[0-9]+(\.[0-9]+)?$/,
|
21
|
+
'integer-list': /^(-?[0-9]+)(,-?[0-9]+)*$/
|
21
22
|
}.freeze
|
22
23
|
# rubocop:enable Layout/LineLength
|
23
24
|
|
@@ -92,7 +93,7 @@ module Schemacop
|
|
92
93
|
|
93
94
|
case options[:format]
|
94
95
|
when :boolean
|
95
|
-
|
96
|
+
%w[true 1].include?(to_cast)
|
96
97
|
when :date
|
97
98
|
return Date.parse(to_cast)
|
98
99
|
when :'date-time'
|
@@ -103,6 +104,8 @@ module Schemacop
|
|
103
104
|
return Integer(to_cast)
|
104
105
|
when :number
|
105
106
|
return Float(to_cast)
|
107
|
+
when :'integer-list'
|
108
|
+
return to_cast.split(',').map(&:to_i)
|
106
109
|
when :symbol
|
107
110
|
return to_cast.to_sym
|
108
111
|
else
|
data/schemacop.gemspec
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: schemacop 3.0.
|
2
|
+
# stub: schemacop 3.0.14 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.14"
|
7
7
|
|
8
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-10-
|
11
|
+
s.date = "2021-10-11"
|
12
12
|
s.files = [".github/workflows/ruby.yml".freeze, ".gitignore".freeze, ".releaser_config".freeze, ".rubocop.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]
|
@@ -18,6 +18,38 @@ module Schemacop
|
|
18
18
|
assert_json(type: :boolean)
|
19
19
|
end
|
20
20
|
|
21
|
+
def test_required_default
|
22
|
+
schema do
|
23
|
+
boo? :enabled, default: true
|
24
|
+
end
|
25
|
+
|
26
|
+
assert_validation(enabled: true)
|
27
|
+
assert_validation(enabled: false)
|
28
|
+
|
29
|
+
assert_cast({}, { 'enabled' => true })
|
30
|
+
|
31
|
+
schema do
|
32
|
+
boo? :enabled, default: false
|
33
|
+
end
|
34
|
+
|
35
|
+
assert_validation(enabled: true)
|
36
|
+
assert_validation(enabled: false)
|
37
|
+
|
38
|
+
assert_cast({}, { 'enabled' => false })
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_default_bug
|
42
|
+
schema do
|
43
|
+
str! :send_message
|
44
|
+
boo? :always_show_successful, default: true
|
45
|
+
end
|
46
|
+
|
47
|
+
assert_cast(
|
48
|
+
{ 'send_message' => 'foo' },
|
49
|
+
{ 'send_message' => 'foo', 'always_show_successful' => true }
|
50
|
+
)
|
51
|
+
end
|
52
|
+
|
21
53
|
def test_required
|
22
54
|
schema :boolean, required: true
|
23
55
|
|
@@ -200,6 +200,30 @@ module Schemacop
|
|
200
200
|
assert_cast('039n23$g- sfk3/', :'039n23$g- sfk3/')
|
201
201
|
end
|
202
202
|
|
203
|
+
def test_format_integer_list
|
204
|
+
schema :string, format: :integer_list
|
205
|
+
|
206
|
+
assert_json(type: :string, format: :'integer-list')
|
207
|
+
|
208
|
+
assert_validation '1,2,3,4'
|
209
|
+
assert_validation '1,2,-3,-54'
|
210
|
+
assert_validation '2'
|
211
|
+
assert_validation '-2'
|
212
|
+
|
213
|
+
assert_validation 234 do
|
214
|
+
error '/', StringNodeTest.invalid_type_error(Integer)
|
215
|
+
end
|
216
|
+
|
217
|
+
assert_validation 'sd sfdij soidf' do
|
218
|
+
error '/', 'String does not match format "integer-list".'
|
219
|
+
end
|
220
|
+
|
221
|
+
assert_cast nil, nil
|
222
|
+
assert_cast '1,-2,3', [1, -2, 3]
|
223
|
+
assert_cast '1', [1]
|
224
|
+
assert_cast '-1', [-1]
|
225
|
+
end
|
226
|
+
|
203
227
|
def test_enum
|
204
228
|
schema :string, enum: ['foo', 'some string', 'some other string', 42]
|
205
229
|
|
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.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sitrox
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-10-
|
11
|
+
date: 2021-10-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|