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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 86a824c8ccca5369721dff7f7ccebb581cb34685a31aa50126444a92593ee20c
4
- data.tar.gz: a336258896003d683a4b9b3d5c8a1a7e5070c1cef06eb4975ba0ba8d872c8f0a
3
+ metadata.gz: 45a0558e32f2c4a8e4d9db631ac874629ed7e92a378a177266a216b9e35295bd
4
+ data.tar.gz: fa2da0867bf598a32ba7728b246343f6bf3849aa1ccdddf9093dcd360df2b53e
5
5
  SHA512:
6
- metadata.gz: f4faf09edddbbd5fa892ee9b7f4dc75a0e551744e625f2b8552fe68678113abfd07dc2b8f3344f0d75c7f37aa84281b7c37195f8dd9aa70b2b89e5742a98452c
7
- data.tar.gz: 2f07ee47aba8a6147a6088f7f3fe6e0c35168b9a59ee540c00cd3f8693104b74e74227fa68c96604410098d774ea9774c50f135f20a51448f349b8b297d4a2f1
6
+ metadata.gz: 557da4f2765fc6a9c081b1b894f57b9acb8f3f16ff72c56589064672d060b1879b4d68a498692aeb4764b78ab1091de9b5b0a8dbd4b0ebc0e8bc401875ff5167
7
+ data.tar.gz: 54748996bd7ea09dda23163c808e32300e898ceb3910d1decfaa0516d49a268d79afeb9c9292f3a3fbc6d5f128ba8de1470111c66470585772b5903580088cbb
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Change log
2
2
 
3
+ ## 3.0.14 (2021-10-11)
4
+
5
+ * Add string format `integer_list`
6
+
7
+ * Improve handling for booleans
8
+
3
9
  ## 3.0.13 (2021-10-04)
4
10
 
5
11
  * When using `boolean` with `cast_str: true`, `"0"` is now casted to `false` and
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.13
1
+ 3.0.14
@@ -187,7 +187,7 @@ module Schemacop
187
187
 
188
188
  casted_data = prop.cast(data_hash[prop.name])
189
189
 
190
- if casted_data.present? || data_hash.include?(prop.name)
190
+ if !casted_data.nil? || data_hash.include?(prop.name)
191
191
  result[prop_name] = casted_data
192
192
  end
193
193
 
@@ -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 if @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: /^([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]+)?$/
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
- return to_cast == 'true' || to_cast == '1'
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.13 ruby lib
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.13"
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-04"
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.13
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-04 00:00:00.000000000 Z
11
+ date: 2021-10-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport