schemacop 3.0.6 → 3.0.11

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: db3239081f4731794b9e52be8901752fc9ed70ca8a0c6b0afaa148be11015f36
4
- data.tar.gz: cdb44d05750c603be99188670833605da946f507ab726456ed49aa2422381e68
3
+ metadata.gz: 40958dccae4c661f133f181907cc729c0002ca02702a6675c1beb1c90fed425e
4
+ data.tar.gz: 4ef5dcf205bd5f5cc8203867e95d07ff5a56a8c4654f3eac89e90596cb9a2e39
5
5
  SHA512:
6
- metadata.gz: c64bf86004b0f5a0c7e52aa833d7b37efe267c993bd26fd7cadfa18891dbcc6375c89f0af68f91c168c0b83fa9e641dc5e3ec6b5121b9c67d8135956beec5a1d
7
- data.tar.gz: f4c6d201ff95b6a1f2e0ebf6c6c447a0047ef72f39257b533420b64d5000573a6f4e58d2f95f5f4e0ba50397a8d8a76e7b08298d5338aff50ebce52bd73cacec
6
+ metadata.gz: 1af517385c88340f64067895363b6e79d2ce15e00415ef5d0110200706b2e264701e6a0eeac9332e2ea8d9c5967989e8e05a9e311291a1e942d1effc5cc15219
7
+ data.tar.gz: c773bd33014ae3a8ccb4f1cd22c2066b375de678fdde702d2d95dcbc78880bd6d19940bb06b8052b06f955bc740834b7761f5c389d21bec56250ee18a4680ce6
data/.releaser_config CHANGED
@@ -1,3 +1,4 @@
1
1
  version_file: VERSION
2
2
  always_from_master: true
3
3
  gem_style: github
4
+ ruby_command: ruby -S
data/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # Change log
2
2
 
3
+ ## 3.0.11 (2021-03-26)
4
+
5
+ * Treat blank string as nil when using `cast_str` option
6
+
7
+ ## 3.0.10 (2021-03-19)
8
+
9
+ * If wrong type is given, report class of wrong type in error message
10
+
11
+ ## 3.0.9 (2021-02-26)
12
+
13
+ * Fix casting of blank strings
14
+
15
+ * Add `allow_blank` option to `String` nodes
16
+
17
+ ## 3.0.8 (2021-02-23)
18
+
19
+ * Fix `object` nodes in hashes with no classes
20
+
21
+ * Document `cast_str` option
22
+
23
+ ## 3.0.7 (2021-02-22)
24
+
25
+ * Adapt schema definitions handling when using Swagger-standard JSON
26
+
3
27
  ## 3.0.6 (2021-02-14)
4
28
 
5
29
  * Remove option `json_format` from {Schemacop::Schema3.as_json as_json} again.
data/README_V3.md CHANGED
@@ -75,12 +75,12 @@ Schemacop can raise the following exceptions:
75
75
  Example:
76
76
 
77
77
  ```ruby
78
- schema = Schemacop::Schema3.new do
78
+ schema = Schemacop::Schema3.new :hash do
79
79
  int! :foo
80
80
  end
81
81
 
82
82
  schema.validate!(foo: 'bar')
83
- # => Schemacop::Exceptions::ValidationError: /foo: Invalid type, expected "integer".
83
+ # => Schemacop::Exceptions::ValidationError: /foo: Invalid type, got type "String", expected "integer".
84
84
  ```
85
85
 
86
86
  * `Schemacop::Exceptions::InvalidSchemaError`: This exception is raised when the
@@ -141,7 +141,7 @@ schema = Schemacop::Schema3.new :string, enum: ['foo', 'bar', 42]
141
141
 
142
142
  schema.validate!('foo') # => "foo"
143
143
  schema.validate!('bar') # => "bar"
144
- schema.validate!(42) # => Schemacop::Exceptions::ValidationError: /: Invalid type, expected "string".
144
+ schema.validate!(42) # => Schemacop::Exceptions::ValidationError: /: Invalid type, got type "Integer", expected "string".
145
145
  ```
146
146
 
147
147
  The enum will also be provided in the json output:
@@ -178,7 +178,7 @@ Note that the default value you use is also validated against the schema:
178
178
  schema = Schemacop::Schema3.new :string, default: 42
179
179
 
180
180
  schema.validate!('foo') # => "foo"
181
- schema.validate!(nil) # => Schemacop::Exceptions::ValidationError: /: Invalid type, expected "string".
181
+ schema.validate!(nil) # => Schemacop::Exceptions::ValidationError: /: Invalid type, got type "Integer", expected "string".
182
182
  ```
183
183
 
184
184
  ## Nodes
@@ -199,14 +199,19 @@ transformed into various types.
199
199
  * `max_length`
200
200
  Defines the (inclusive) maximum required string length
201
201
  * `pattern`
202
- Defines a (ruby) regex pattern the value will be matched against. Must be a
203
- string and should generally start with `^` and end with `$` so as to evaluate
204
- the entire string. It should not be enclosed in `/` characters.
202
+ Defines a (ruby) regex pattern the value will be matched against. Must be either
203
+ a string which should not be enclosed in `/` characters, or a Ruby Regexp.
204
+ The pattern should generally start with `^` and end with `$` so as to evaluate
205
+ the entire string.
205
206
  * `format`
206
207
  The `format` option allows for basic semantic validation on certain kinds of
207
208
  string values that are commonly used. See section *formats* for more
208
209
  information on the available formats. Note that strings with a format are also
209
210
  **casted** into that format.
211
+ * `allow_blank`
212
+ By default, blank strings are allowed and left as they are when casted (e.g.
213
+ the string `''` is valid). If you want to disallow blank strings, set this
214
+ option to `false`.
210
215
 
211
216
  #### Formats
212
217
 
@@ -246,6 +251,38 @@ transformed into various types.
246
251
 
247
252
  #### Examples
248
253
 
254
+ ```ruby
255
+ # Basic example
256
+ schema = Schemacop::Schema3.new :string
257
+ schema.validate!(nil) # => nil
258
+ schema.validate!('') # => ""
259
+ schema.validate!('foo') # => "foo"
260
+ schema.validate!("\n") # => "\n"
261
+ ```
262
+
263
+ With the `required` option:
264
+
265
+ ```ruby
266
+ # Basic example
267
+ schema = Schemacop::Schema3.new :string, required: true
268
+ schema.validate!(nil) # => Schemacop::Exceptions::ValidationError: /: Value must be given.
269
+ schema.validate!('') # => ""
270
+ schema.validate!('foo') # => "foo"
271
+ schema.validate!("\n") # => "\n"
272
+ ```
273
+
274
+ With the `allow_blank` option:
275
+
276
+ ```ruby
277
+ # Basic example
278
+ schema = Schemacop::Schema3.new :string, allow_blank: false
279
+ schema.validate!(nil) # => Schemacop::Exceptions::ValidationError: /: String is blank but must not be blank!
280
+ schema.validate!('') # => Schemacop::Exceptions::ValidationError: /: String is blank but must not be blank!
281
+ schema.validate!('foo') # => "foo"
282
+ schema.validate!("\n") # => Schemacop::Exceptions::ValidationError: /: String is blank but must not be blank!
283
+ ```
284
+ Example of using a `format` option:
285
+
249
286
  ```ruby
250
287
  # By using a format, string values are casted to that respective format
251
288
  schema = Schemacop::Schema3.new(:string, format: :date)
@@ -277,6 +314,10 @@ integer can be done.
277
314
  * `multiple_of`
278
315
  The received number has to be a multiple of the given number for the validation to
279
316
  pass.
317
+ * `cast_str`
318
+ When set to `true`, this node also accepts strings that can be casted to an integer, e.g.
319
+ the values `'-5'` or `'42'`. Please note that you can only validate numbers which
320
+ are in the `Integer` format. Blank strings will be treated equally as `nil`.
280
321
 
281
322
  #### Examples
282
323
 
@@ -287,10 +328,37 @@ schema.validate!(42) # => 42
287
328
  schema.validate!(43) # => Schemacop::Exceptions::ValidationError: /: Value must be a multiple of 2.
288
329
  schema.validate!(-2) # => Schemacop::Exceptions::ValidationError: /: Value must have a minimum of 0.
289
330
  schema.validate!(102) # => Schemacop::Exceptions::ValidationError: /: Value must have a maximum of 100.
290
- schema.validate!(42.1) # => Schemacop::Exceptions::ValidationError: /: Invalid type, expected "integer".
291
- schema.validate!(4r) # => Schemacop::Exceptions::ValidationError: /: Invalid type, expected "integer".
292
- schema.validate!((4 + 0i)) # => Schemacop::Exceptions::ValidationError: /: Invalid type, expected "integer".
293
- schema.validate!(BigDecimal(5)) # => Schemacop::Exceptions::ValidationError: /: Invalid type, expected "integer".
331
+ schema.validate!(42.1) # => Schemacop::Exceptions::ValidationError: /: Invalid type, got type "Float", expected "integer".
332
+ schema.validate!(4r) # => Schemacop::Exceptions::ValidationError: /: Invalid type, got type "Rational", expected "integer".
333
+ schema.validate!((4 + 0i)) # => Schemacop::Exceptions::ValidationError: /: Invalid type, got type "Complex", expected "integer".
334
+ schema.validate!(BigDecimal(5)) # => Schemacop::Exceptions::ValidationError: /: Invalid type, got type "BigDecimal", expected "integer".
335
+ ```
336
+
337
+ With `cast_str` enabled:
338
+
339
+ ```ruby
340
+ # Validates that the input is an even number between 0 and 100 (inclusive)
341
+ schema = Schemacop::Schema3.new(:integer, minimum: 0, maximum: 100, multiple_of: 2, cast_str: true)
342
+ schema.validate!('42') # => 42
343
+ schema.validate!('43') # => Schemacop::Exceptions::ValidationError: /: Matches 0 definitions but should match exactly 1.
344
+ schema.validate!('-2') # => Schemacop::Exceptions::ValidationError: /: Matches 0 definitions but should match exactly 1.
345
+ schema.validate!('102') # => Schemacop::Exceptions::ValidationError: /: Matches 0 definitions but should match exactly 1.
346
+ schema.validate!('42.1') # => Schemacop::Exceptions::ValidationError: /: Matches 0 definitions but should match exactly 1.
347
+ schema.validate!('4r') # => Schemacop::Exceptions::ValidationError: /: Matches 0 definitions but should match exactly 1.
348
+ schema.validate!('(4 + 0i)') # => Schemacop::Exceptions::ValidationError: /: Matches 0 definitions but should match exactly 1.
349
+ schema.validate!(nil) # => nil
350
+ schema.validate!('') # => nil
351
+ ```
352
+
353
+ Please note, that `nil` and blank strings are treated equally when using the `cast_str` option,
354
+ and validating a blank string will return `nil`.
355
+ If you need a value, use the `required` option:
356
+
357
+ ```ruby
358
+ schema = Schemacop::Schema3.new(:integer, minimum: 0, maximum: 100, multiple_of: 2, cast_str: true, required: true)
359
+ schema.validate!('42') # => 42
360
+ schema.validate!(nil) # => Schemacop::Exceptions::ValidationError: /: Value must be given.
361
+ schema.validate!('') # => Schemacop::Exceptions::ValidationError: /: Value must be given.
294
362
  ```
295
363
 
296
364
  ### Number
@@ -327,6 +395,11 @@ With the various available options, validations on the value of the number can b
327
395
  * `multiple_of`
328
396
  The received number has to be a multiple of the given number for the validation to
329
397
  pass.
398
+ * `cast_str`
399
+ When set to `true`, this node also accepts strings that can be casted to a number, e.g.
400
+ the values `'0.1'` or `'3.1415'`. Please note that you can only validate numbers which
401
+ are in the `Integer` or `Float` format, i.e. values like `'1.5r'` or `'(4 + 0i)'` will
402
+ not work. Blank strings will be treated equally as `nil`.
330
403
 
331
404
  #### Examples
332
405
 
@@ -340,7 +413,33 @@ schema.validate!(51) # => Schemacop::Exceptions::ValidationError: /:
340
413
  schema.validate!(42.5) # => 42.5
341
414
  schema.validate!(1.5r) # => (3/2)
342
415
  schema.validate!(BigDecimal(5)) # => 0.5e1
343
- schema.validate!((4 + 0i)) # => Schemacop::Exceptions::ValidationError: /: Invalid type, expected "big_decimal" or "float" or "integer" or "rational".
416
+ schema.validate!((4 + 0i)) # => Schemacop::Exceptions::ValidationError: /: Invalid type, got type "Complex", expected "big_decimal" or "float" or "integer" or "rational"
417
+ ```
418
+
419
+ With `cast_str` enabled:
420
+
421
+ ```ruby
422
+ schema = Schemacop::Schema3.new(:number, cast_str: true, minimum: 0.0, maximum: (50r), multiple_of: BigDecimal('0.5'))
423
+ schema.validate!('42') # => 42
424
+ schema.validate!('42.2') # => Schemacop::Exceptions::ValidationError: /: Matches 0 definitions but should match exactly 1.
425
+ schema.validate!('-2') # => Schemacop::Exceptions::ValidationError: /: Matches 0 definitions but should match exactly 1.
426
+ schema.validate!('51') # => Schemacop::Exceptions::ValidationError: /: Matches 0 definitions but should match exactly 1.
427
+ schema.validate!('42.5') # => 42.5
428
+ schema.validate!('1.5r') # => Schemacop::Exceptions::ValidationError: /: Matches 0 definitions but should match exactly 1.
429
+ schema.validate!('(4 + 0i)') # => Schemacop::Exceptions::ValidationError: /: Matches 0 definitions but should match exactly 1.
430
+ schema.validate!(nil) # => nil
431
+ schema.validate!('') # => nil
432
+ ```
433
+
434
+ Please note, that `nil` and blank strings are treated equally when using the `cast_str` option,
435
+ and validating a blank string will return `nil`.
436
+ If you need a value, use the `required` option:
437
+
438
+ ```ruby
439
+ schema = Schemacop::Schema3.new(:number, cast_str: true, minimum: 0.0, maximum: (50r), multiple_of: BigDecimal('0.5'), require: true)
440
+ schema.validate!('42.5') # => 42.5
441
+ schema.validate!(nil) # => Schemacop::Exceptions::ValidationError: /: Value must be given.
442
+ schema.validate!('') # => Schemacop::Exceptions::ValidationError: /: Value must be given.
344
443
  ```
345
444
 
346
445
  ### Symbol
@@ -350,15 +449,46 @@ DSL: `sym`
350
449
 
351
450
  The symbol type is used to validate elements for the Ruby `Symbol` class.
352
451
 
452
+ #### Options
453
+
454
+ * `cast_str`
455
+ When set to `true`, this node also accepts strings that can be casted to a symbol. Blank strings will be treated equally as `nil`.
456
+
353
457
  #### Examples
354
458
 
355
459
  ```ruby
356
460
  # Validates that the input is a symbol
357
461
  schema = Schemacop::Schema3.new(:symbol)
358
- schema.validate!(:foo) # => :foo
359
- schema.validate!('foo') # => Schemacop::Exceptions::ValidationError: /: Invalid type, expected "Symbol".
360
- schema.validate!(123) # => Schemacop::Exceptions::ValidationError: /: Invalid type, expected "Symbol".
361
- schema.validate!(false) # => Schemacop::Exceptions::ValidationError: /: Invalid type, expected "Symbol".
462
+ schema.validate!(:foo) # => :foo
463
+ schema.validate!('foo') # => Schemacop::Exceptions::ValidationError: /: Invalid type, got type "String", expected "Symbol".
464
+ schema.validate!(123) # => Schemacop::Exceptions::ValidationError: /: Invalid type, got type "Integer", expected "Symbol".
465
+ schema.validate!(false) # => Schemacop::Exceptions::ValidationError: /: Invalid type, got type "FalseClass", expected "Symbol".
466
+ schema.validate!(:false) # => :false
467
+ ```
468
+
469
+ With `cast_str` enabled:
470
+
471
+ ```ruby
472
+ # Validates that the input is a symbol
473
+ schema = Schemacop::Schema3.new(:symbol, cast_str: true)
474
+ schema.validate!(':foo') # => :":foo"
475
+ schema.validate!('foo') # => :foo
476
+ schema.validate!('123') # => :"123"
477
+ schema.validate!('false') # => :false
478
+ schema.validate!(':false') # => :":false"
479
+ schema.validate!(nil) # => nil
480
+ schema.validate!('') # => nil
481
+ ```
482
+
483
+ Please note, that `nil` and blank strings are treated equally when using the `cast_str` option,
484
+ and validating a blank string will return `nil`.
485
+ If you need a value, use the `required` option:
486
+
487
+ ```ruby
488
+ schema = Schemacop::Schema3.new(:symbol, cast_str: true, required: true)
489
+ schema.validate!('foo') # => :foo
490
+ schema.validate!(nil) # => Schemacop::Exceptions::ValidationError: /: Value must be given.
491
+ schema.validate!('') # => Schemacop::Exceptions::ValidationError: /: Value must be given.
362
492
  ```
363
493
 
364
494
  ### Boolean
@@ -368,6 +498,12 @@ DSL: `boo`
368
498
 
369
499
  The boolean type is used to validate Ruby booleans, i.e. the `TrueClass` and `FalseClass`
370
500
 
501
+ #### Options
502
+
503
+ * `cast_str`
504
+ When set to `true`, this node also accepts strings that can be casted to a boolean, i.e.
505
+ the values `'true'` and `'false'`. Blank strings will be treated equally as `nil`.
506
+
371
507
  #### Examples
372
508
 
373
509
  ```ruby
@@ -375,9 +511,33 @@ The boolean type is used to validate Ruby booleans, i.e. the `TrueClass` and `Fa
375
511
  schema = Schemacop::Schema3.new(:boolean)
376
512
  schema.validate!(true) # => true
377
513
  schema.validate!(false) # => false
378
- schema.validate!(:false) # => Schemacop::Exceptions::ValidationError: /: Invalid type, expected "boolean".
379
- schema.validate!('false') # => Schemacop::Exceptions::ValidationError: /: Invalid type, expected "boolean".
380
- schema.validate!(1234) # => Schemacop::Exceptions::ValidationError: /: Invalid type, expected "boolean".
514
+ schema.validate!(:false) # => Schemacop::Exceptions::ValidationError: /: Invalid type, got type "Symbol", expected "boolean".
515
+ schema.validate!('false') # => Schemacop::Exceptions::ValidationError: /: Invalid type, got type "String", expected "boolean".
516
+ schema.validate!(1234) # => Schemacop::Exceptions::ValidationError: /: Invalid type, got type "Integer", expected "boolean".
517
+ ```
518
+
519
+ With `cast_str` enabled:
520
+
521
+ ```ruby
522
+ schema = Schemacop::Schema3.new(:boolean, cast_str: true)
523
+ schema.validate!(true) # => true
524
+ schema.validate!(false) # => false
525
+ schema.validate!(:false) # => Schemacop::Exceptions::ValidationError: /: Matches 0 definitions but should match exactly 1.
526
+ schema.validate!('false') # => false
527
+ schema.validate!(1234) # => Schemacop::Exceptions::ValidationError: /: Matches 0 definitions but should match exactly 1.
528
+ schema.validate!(nil) # => nil
529
+ schema.validate!('') # => nil
530
+ ```
531
+
532
+ Please note, that `nil` and blank strings are treated equally when using the `cast_str` option,
533
+ and validating a blank string will return `nil`.
534
+ If you need a value, use the `required` option:
535
+
536
+ ```ruby
537
+ schema = Schemacop::Schema3.new(:boolean, cast_str: true, required: true)
538
+ schema.validate!('false') # => false
539
+ schema.validate!(nil) # => Schemacop::Exceptions::ValidationError: /: Value must be given.
540
+ schema.validate!('') # => Schemacop::Exceptions::ValidationError: /: Value must be given.
381
541
  ```
382
542
 
383
543
  ### Array
@@ -420,7 +580,7 @@ end
420
580
 
421
581
  schema.validate!([]) # => Schemacop::Exceptions::ValidationError: /: At least one entry must match schema {"type"=>"integer", "minimum"=>5}.
422
582
  schema.validate!([1, 5]) # => [1, 5]
423
- schema.validate!(['foo']) # => Schemacop::Exceptions::ValidationError: /[0]: Invalid type, expected "integer". /: At least one entry must match schema {"type"=>"integer", "minimum"=>5}
583
+ schema.validate!(['foo']) # => Schemacop::Exceptions::ValidationError: /[0]: Invalid type, got type "String", expected "integer". /: At least one entry must match schema {"type"=>"integer", "minimum"=>5}
424
584
  ```
425
585
 
426
586
  You can also use it with the tuple validation (see below), e.g. if you want
@@ -461,10 +621,10 @@ schema = Schemacop::Schema3.new :array do
461
621
  list :integer, minimum: 1, maximum: 5
462
622
  end
463
623
 
464
- schema.validate!([]) # => []
465
- schema.validate!([1, 3]) # => [1, 3]
466
- schema.validate!([0, 6]) # => Schemacop::Exceptions::ValidationError: /[0]: Value must have a minimum of 1. /[1]: Value must have a maximum of 5.
467
- schema.validate! ['foo'] # => Schemacop::Exceptions::ValidationError: /[0]: Invalid type, expected "integer".
624
+ schema.validate!([]) # => []
625
+ schema.validate!([1, 3]) # => [1, 3]
626
+ schema.validate!([0, 6]) # => Schemacop::Exceptions::ValidationError: /[0]: Value must have a minimum of 1. /[1]: Value must have a maximum of 5.
627
+ schema.validate!(['foo']) # => Schemacop::Exceptions::ValidationError: /[0]: Invalid type, got type "String", expected "integer".
468
628
  ```
469
629
 
470
630
  You can also build more complex structures, e.g. an array containing an arbitrary
@@ -479,7 +639,7 @@ end
479
639
 
480
640
  schema.validate!([]) # => []
481
641
  schema.validate!([[1], [2, 3]]) # => [[1], [2, 3]]
482
- schema.validate!([['foo'], [2, 3]]) # => Schemacop::Exceptions::ValidationError: /[0]/[0]: Invalid type, expected "integer".
642
+ schema.validate!([['foo'], [2, 3]]) # => Schemacop::Exceptions::ValidationError: /[0]/[0]: Invalid type, got type "String", expected "integer".
483
643
  ```
484
644
 
485
645
  Please note that you can only specify *one* `list` item:
@@ -541,7 +701,7 @@ end
541
701
 
542
702
  schema.validate!([]) # => Schemacop::Exceptions::ValidationError: /: Array has 0 items but must have exactly 2.
543
703
  schema.validate!([1, 'foo']) # => [1, "foo"]
544
- schema.validate!([1, 'foo', 'bar']) # => Schemacop::Exceptions::ValidationError: /[2]: Invalid type, expected "integer".
704
+ schema.validate!([1, 'foo', 'bar']) # => Schemacop::Exceptions::ValidationError: /[2]: Invalid type, got type "String", expected "integer".
545
705
  schema.validate!([1, 'foo', 2, 3]) # => [1, "foo", 2, 3]
546
706
  ```
547
707
 
@@ -700,7 +860,7 @@ schema = Schemacop::Schema3.new :hash do
700
860
  str? :foo
701
861
  end
702
862
 
703
- schema.validate!({foo: 1}) # => Schemacop::Exceptions::ValidationError: /foo: Invalid type, expected "string".
863
+ schema.validate!({foo: 1}) # => Schemacop::Exceptions::ValidationError: /foo: Invalid type, got type "Integer", expected "string".
704
864
  schema.validate!({foo: 'bar'}) # => {"foo"=>"bar"}
705
865
  ```
706
866
 
@@ -784,7 +944,7 @@ end
784
944
 
785
945
  schema.validate!({id: 1}) # => {"id"=>1}
786
946
  schema.validate!({id: 1, foo: 'bar'}) # => {"id"=>1, "foo"=>"bar"}
787
- schema.validate!({id: 1, foo: 42}) # => Schemacop::Exceptions::ValidationError: /foo: Invalid type, expected "string".
947
+ schema.validate!({id: 1, foo: 42}) # => Schemacop::Exceptions::ValidationError: /foo: Invalid type, got type "Integer", expected "string".
788
948
  ```
789
949
 
790
950
  Using the option `property_names`, you can additionaly specify a pattern that
@@ -808,8 +968,8 @@ end
808
968
 
809
969
  schema.validate!({}) # => {}
810
970
  schema.validate!({foo: [1, 2, 3]}) # => {"foo"=>[1, 2, 3]}
811
- schema.validate!({foo: :bar}) # => Schemacop::Exceptions::ValidationError: /foo: Invalid type, expected "array".
812
- schema.validate!({Foo: :bar}) # => Schemacop::Exceptions::ValidationError: /: Property name :Foo does not match "^[a-z]+$". /Foo: Invalid type, expected "array".
971
+ schema.validate!({foo: :bar}) # => Schemacop::Exceptions::ValidationError: /foo: Invalid type, got type "Symbol", expected "array".
972
+ schema.validate!({Foo: :bar}) # => Schemacop::Exceptions::ValidationError: /: Property name :Foo does not match "^[a-z]+$". /Foo: Invalid type, got type "Symbol", expected "array".
813
973
  ```
814
974
 
815
975
  ##### Dependencies
@@ -883,10 +1043,10 @@ of allowed classes:
883
1043
  schema = Schemacop::Schema3.new :object, classes: [String]
884
1044
 
885
1045
  schema.validate!(nil) # => nil
886
- schema.validate!(true) # => Schemacop::Exceptions::ValidationError: /: Invalid type, expected "String".
887
- schema.validate!(Object.new) # => Schemacop::Exceptions::ValidationError: /: Invalid type, expected "String".
1046
+ schema.validate!(true) # => Schemacop::Exceptions::ValidationError: /: Invalid type, got type "TrueClass", expected "String".
1047
+ schema.validate!(Object.new) # => Schemacop::Exceptions::ValidationError: /: Invalid type, got type "Object", expected "String".
888
1048
  schema.validate!('foo') # => "foo"
889
- schema.validate!('foo'.html_safe) # => Schemacop::Exceptions::ValidationError: /: Invalid type, expected "String".
1049
+ schema.validate!('foo'.html_safe) # => Schemacop::Exceptions::ValidationError: /: Invalid type, got type "ActiveSupport::SafeBuffer", expected "String".
890
1050
  ```
891
1051
 
892
1052
  Here, the node checks if the given value is an instance of any of the given
@@ -898,8 +1058,8 @@ If you want to allow subclasses, you can specify this by using the `strict` opti
898
1058
  schema = Schemacop::Schema3.new :object, classes: [String], strict: false
899
1059
 
900
1060
  schema.validate!(nil) # => nil
901
- schema.validate!(true) # => Schemacop::Exceptions::ValidationError: /: Invalid type, expected "String".
902
- schema.validate!(Object.new) # => Schemacop::Exceptions::ValidationError: /: Invalid type, expected "String".
1061
+ schema.validate!(true) # => Schemacop::Exceptions::ValidationError: /: Invalid type, got type "TrueClass", expected "String".
1062
+ schema.validate!(Object.new) # => Schemacop::Exceptions::ValidationError: /: Invalid type, got type "Object", expected "String".
903
1063
  schema.validate!('foo') # => "foo"
904
1064
  schema.validate!('foo'.html_safe) # => "foo"
905
1065
  ```
@@ -1072,7 +1232,7 @@ schema.validate!({
1072
1232
  shipping_address: 'foo',
1073
1233
  billing_address: 42
1074
1234
  })
1075
- # => Schemacop::Exceptions::ValidationError: /shipping_address: Invalid type, expected "object". /billing_address: Invalid type, expected "object".
1235
+ # => Schemacop::Exceptions::ValidationError: /shipping_address: Invalid type, got type "String", expected "object". /billing_address: Invalid type, got type "Integer", expected "object".
1076
1236
 
1077
1237
  schema.validate!({
1078
1238
  shipping_address: {
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.0.6
1
+ 3.0.11
@@ -19,6 +19,10 @@ module Schemacop
19
19
  default
20
20
  end
21
21
  end
22
+
23
+ def self.allowed_options
24
+ super + %i[cast_str]
25
+ end
22
26
  end
23
27
  end
24
28
  end