schemacop 3.0.30 → 3.0.31
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +1 -1
- data/CHANGELOG.md +4 -0
- data/Gemfile +0 -1
- data/README.md +1 -0
- data/README_V3.md +6 -0
- data/VERSION +1 -1
- data/lib/schemacop.rb +14 -0
- data/schemacop.gemspec +7 -17
- data/test/lib/test_helper.rb +5 -1
- data/test/unit/schemacop/v3/array_node_test.rb +50 -10
- data/test/unit/schemacop/v3/boolean_node_test.rb +5 -1
- data/test/unit/schemacop/v3/hash_node_test.rb +10 -2
- data/test/unit/schemacop/v3/integer_node_test.rb +10 -2
- data/test/unit/schemacop/v3/is_not_node_test.rb +40 -8
- data/test/unit/schemacop/v3/node_test.rb +20 -4
- data/test/unit/schemacop/v3/number_node_test.rb +10 -2
- data/test/unit/schemacop/v3/object_node_test.rb +15 -3
- data/test/unit/schemacop/v3/string_node_test.rb +111 -2
- data/test/unit/schemacop/v3/symbol_node_test.rb +5 -1
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b921a349115da6b915e956565782f34f0a72596a0e5c3c4c38e62ffc7117655
|
4
|
+
data.tar.gz: 792d6db18eab413e190b6f25a878e8cf832e99bea0ff87039ce54b87fdf682ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 58c5fe39a2a685441a9cddaa88ed32313bfdc1702270c472db56848849028a64976e89d3cb026fab1dd82c2f236b9bb2a7e698d279e938f97c7b6bfede29e061
|
7
|
+
data.tar.gz: a6dde92bccda133ec1ddbae0c8e90e3b91f6abe8a1ab6b6c6fa8d54f7e2511e7a51029dc6fed66a5292fdec0b979759df00beddc9b630dadc9d100289d372e9a
|
data/.github/workflows/ruby.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
data/README_V3.md
CHANGED
@@ -270,6 +270,12 @@ transformed into various types.
|
|
270
270
|
* `symbol`
|
271
271
|
The string can be anything and will be casted to a ruby `Symbol` object.
|
272
272
|
|
273
|
+
* `ipv4`
|
274
|
+
A valid IPv4 address without netmask. No casting is performed.
|
275
|
+
|
276
|
+
* `ipv6`
|
277
|
+
A valid IPv6 address without netmask. No casting is performed.
|
278
|
+
|
273
279
|
#### Custom Formats
|
274
280
|
|
275
281
|
You can also implement your custom formats or override the behavior of the
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.0.
|
1
|
+
3.0.31
|
data/lib/schemacop.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
# External dependencies
|
2
2
|
require 'ruby2_keywords'
|
3
|
+
require 'logger'
|
3
4
|
require 'active_support/all'
|
4
5
|
require 'set'
|
5
6
|
require 'uri'
|
7
|
+
require 'resolv'
|
6
8
|
|
7
9
|
# Schemacop module
|
8
10
|
module Schemacop
|
@@ -96,6 +98,18 @@ module Schemacop
|
|
96
98
|
handler: ->(value) { value.split(',').map { |i| Integer(i, 10) } }
|
97
99
|
)
|
98
100
|
|
101
|
+
register_string_formatter(
|
102
|
+
:ipv4,
|
103
|
+
pattern: Resolv::IPv4::Regex,
|
104
|
+
handler: ->(value) { value }
|
105
|
+
)
|
106
|
+
|
107
|
+
register_string_formatter(
|
108
|
+
:ipv6,
|
109
|
+
pattern: Resolv::IPv6::Regex,
|
110
|
+
handler: ->(value) { value }
|
111
|
+
)
|
112
|
+
|
99
113
|
def self.with_context(context)
|
100
114
|
prev_context = Thread.current[CONTEXT_THREAD_KEY]
|
101
115
|
Thread.current[CONTEXT_THREAD_KEY] = context
|
data/schemacop.gemspec
CHANGED
@@ -1,33 +1,23 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: schemacop 3.0.
|
2
|
+
# stub: schemacop 3.0.31 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.31"
|
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 = "
|
11
|
+
s.date = "2025-02-05"
|
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]
|
15
|
-
s.rubygems_version = "3.
|
15
|
+
s.rubygems_version = "3.4.6".freeze
|
16
16
|
s.summary = "Schemacop validates ruby structures consisting of nested hashes and arrays against simple schema definitions.".freeze
|
17
17
|
s.test_files = ["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]
|
18
18
|
|
19
|
-
|
20
|
-
s.specification_version = 4
|
19
|
+
s.specification_version = 4
|
21
20
|
|
22
|
-
|
23
|
-
|
24
|
-
s.add_runtime_dependency(%q<ruby2_keywords>.freeze, [">= 0.0.4"])
|
25
|
-
else
|
26
|
-
s.add_dependency(%q<activesupport>.freeze, [">= 4.0"])
|
27
|
-
s.add_dependency(%q<ruby2_keywords>.freeze, [">= 0.0.4"])
|
28
|
-
end
|
29
|
-
else
|
30
|
-
s.add_dependency(%q<activesupport>.freeze, [">= 4.0"])
|
31
|
-
s.add_dependency(%q<ruby2_keywords>.freeze, [">= 0.0.4"])
|
32
|
-
end
|
21
|
+
s.add_runtime_dependency(%q<activesupport>.freeze, [">= 4.0"])
|
22
|
+
s.add_runtime_dependency(%q<ruby2_keywords>.freeze, [">= 0.0.4"])
|
33
23
|
end
|
data/test/lib/test_helper.rb
CHANGED
@@ -27,7 +27,6 @@ require 'minitest/autorun'
|
|
27
27
|
require 'minitest/reporters'
|
28
28
|
require 'schemacop'
|
29
29
|
require 'pry'
|
30
|
-
require 'colorize'
|
31
30
|
|
32
31
|
Minitest::Reporters.use! [Minitest::Reporters::DefaultReporter.new(color: true)]
|
33
32
|
|
@@ -57,6 +56,11 @@ class V3Test < SchemacopTest
|
|
57
56
|
@errors[path] ||= []
|
58
57
|
@errors[path] << exp
|
59
58
|
end
|
59
|
+
|
60
|
+
def new_hash_inspect_format?
|
61
|
+
# See https://bugs.ruby-lang.org/issues/20433#note-10
|
62
|
+
Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.4.0')
|
63
|
+
end
|
60
64
|
end
|
61
65
|
|
62
66
|
def setup
|
@@ -597,11 +597,19 @@ module Schemacop
|
|
597
597
|
assert_validation(['foo'])
|
598
598
|
|
599
599
|
assert_validation([]) do
|
600
|
-
|
600
|
+
if new_hash_inspect_format?
|
601
|
+
error '/', 'At least one entry must match schema {"type" => "string"}.'
|
602
|
+
else
|
603
|
+
error '/', 'At least one entry must match schema {"type"=>"string"}.'
|
604
|
+
end
|
601
605
|
end
|
602
606
|
|
603
607
|
assert_validation([234, :foo]) do
|
604
|
-
|
608
|
+
if new_hash_inspect_format?
|
609
|
+
error '/', 'At least one entry must match schema {"type" => "string"}.'
|
610
|
+
else
|
611
|
+
error '/', 'At least one entry must match schema {"type"=>"string"}.'
|
612
|
+
end
|
605
613
|
end
|
606
614
|
end
|
607
615
|
|
@@ -689,10 +697,18 @@ module Schemacop
|
|
689
697
|
|
690
698
|
# These need to fail validation, as they are not in the enum list
|
691
699
|
assert_validation([1, 2, 3]) do
|
692
|
-
|
700
|
+
if new_hash_inspect_format?
|
701
|
+
error '/', 'Value not included in enum [1, 2, "foo", :bar, {qux: 42}, [1, 2], ["a", "b"]].'
|
702
|
+
else
|
703
|
+
error '/', 'Value not included in enum [1, 2, "foo", :bar, {:qux=>42}, [1, 2], ["a", "b"]].'
|
704
|
+
end
|
693
705
|
end
|
694
706
|
assert_validation([]) do
|
695
|
-
|
707
|
+
if new_hash_inspect_format?
|
708
|
+
error '/', 'Value not included in enum [1, 2, "foo", :bar, {qux: 42}, [1, 2], ["a", "b"]].'
|
709
|
+
else
|
710
|
+
error '/', 'Value not included in enum [1, 2, "foo", :bar, {:qux=>42}, [1, 2], ["a", "b"]].'
|
711
|
+
end
|
696
712
|
end
|
697
713
|
end
|
698
714
|
|
@@ -832,10 +848,18 @@ module Schemacop
|
|
832
848
|
|
833
849
|
assert_validation(nil)
|
834
850
|
assert_validation([]) do
|
835
|
-
|
851
|
+
if new_hash_inspect_format?
|
852
|
+
error '/', 'At least one entry must match schema {"type" => "integer", "minimum" => 3}.'
|
853
|
+
else
|
854
|
+
error '/', 'At least one entry must match schema {"type"=>"integer", "minimum"=>3}.'
|
855
|
+
end
|
836
856
|
end
|
837
857
|
assert_validation([1, 2]) do
|
838
|
-
|
858
|
+
if new_hash_inspect_format?
|
859
|
+
error '/', 'At least one entry must match schema {"type" => "integer", "minimum" => 3}.'
|
860
|
+
else
|
861
|
+
error '/', 'At least one entry must match schema {"type"=>"integer", "minimum"=>3}.'
|
862
|
+
end
|
839
863
|
end
|
840
864
|
assert_validation([1, 2, 3])
|
841
865
|
end
|
@@ -860,14 +884,26 @@ module Schemacop
|
|
860
884
|
|
861
885
|
assert_validation(nil)
|
862
886
|
assert_validation([]) do
|
863
|
-
|
887
|
+
if new_hash_inspect_format?
|
888
|
+
error '/', 'At least one entry must match schema {"type" => "integer", "minimum" => 5}.'
|
889
|
+
else
|
890
|
+
error '/', 'At least one entry must match schema {"type"=>"integer", "minimum"=>5}.'
|
891
|
+
end
|
864
892
|
end
|
865
893
|
assert_validation([1]) do
|
866
|
-
|
894
|
+
if new_hash_inspect_format?
|
895
|
+
error '/', 'At least one entry must match schema {"type" => "integer", "minimum" => 5}.'
|
896
|
+
else
|
897
|
+
error '/', 'At least one entry must match schema {"type"=>"integer", "minimum"=>5}.'
|
898
|
+
end
|
867
899
|
error '/[0]', 'Value must have a minimum of 2.'
|
868
900
|
end
|
869
901
|
assert_validation([2]) do
|
870
|
-
|
902
|
+
if new_hash_inspect_format?
|
903
|
+
error '/', 'At least one entry must match schema {"type" => "integer", "minimum" => 5}.'
|
904
|
+
else
|
905
|
+
error '/', 'At least one entry must match schema {"type"=>"integer", "minimum"=>5}.'
|
906
|
+
end
|
871
907
|
end
|
872
908
|
|
873
909
|
assert_validation([2, 3, 5])
|
@@ -914,7 +950,11 @@ module Schemacop
|
|
914
950
|
|
915
951
|
assert_validation(nil)
|
916
952
|
assert_validation(['foo']) do
|
917
|
-
|
953
|
+
if new_hash_inspect_format?
|
954
|
+
error '/', 'At least one entry must match schema {"type" => "string", "format" => "date"}.'
|
955
|
+
else
|
956
|
+
error '/', 'At least one entry must match schema {"type"=>"string", "format"=>"date"}.'
|
957
|
+
end
|
918
958
|
end
|
919
959
|
assert_validation(%w[foo 1990-01-01])
|
920
960
|
|
@@ -133,7 +133,11 @@ module Schemacop
|
|
133
133
|
|
134
134
|
# These need to fail validation, as they are not in the enum list
|
135
135
|
assert_validation(false) do
|
136
|
-
|
136
|
+
if new_hash_inspect_format?
|
137
|
+
error '/', 'Value not included in enum [1, 2, "foo", :bar, {qux: 42}, true].'
|
138
|
+
else
|
139
|
+
error '/', 'Value not included in enum [1, 2, "foo", :bar, {:qux=>42}, true].'
|
140
|
+
end
|
137
141
|
end
|
138
142
|
end
|
139
143
|
|
@@ -499,7 +499,11 @@ module Schemacop
|
|
499
499
|
error '/foo', 'Value must be given.'
|
500
500
|
end
|
501
501
|
assert_validation(foo: 'string') do
|
502
|
-
|
502
|
+
if new_hash_inspect_format?
|
503
|
+
error '/foo', 'Must not match schema: {"type" => "string"}.'
|
504
|
+
else
|
505
|
+
error '/foo', 'Must not match schema: {"type"=>"string"}.'
|
506
|
+
end
|
503
507
|
end
|
504
508
|
end
|
505
509
|
|
@@ -515,7 +519,11 @@ module Schemacop
|
|
515
519
|
assert_validation(foo: { bar: :baz })
|
516
520
|
assert_validation(foo: nil)
|
517
521
|
assert_validation(foo: 'string') do
|
518
|
-
|
522
|
+
if new_hash_inspect_format?
|
523
|
+
error '/foo', 'Must not match schema: {"type" => "string"}.'
|
524
|
+
else
|
525
|
+
error '/foo', 'Must not match schema: {"type"=>"string"}.'
|
526
|
+
end
|
519
527
|
end
|
520
528
|
end
|
521
529
|
|
@@ -307,10 +307,18 @@ module Schemacop
|
|
307
307
|
|
308
308
|
# These need to fail validation, as they are not in the enum list
|
309
309
|
assert_validation(13) do
|
310
|
-
|
310
|
+
if new_hash_inspect_format?
|
311
|
+
error '/', 'Value not included in enum [1, 2, "foo", :bar, {qux: 42}].'
|
312
|
+
else
|
313
|
+
error '/', 'Value not included in enum [1, 2, "foo", :bar, {:qux=>42}].'
|
314
|
+
end
|
311
315
|
end
|
312
316
|
assert_validation(4) do
|
313
|
-
|
317
|
+
if new_hash_inspect_format?
|
318
|
+
error '/', 'Value not included in enum [1, 2, "foo", :bar, {qux: 42}].'
|
319
|
+
else
|
320
|
+
error '/', 'Value not included in enum [1, 2, "foo", :bar, {:qux=>42}].'
|
321
|
+
end
|
314
322
|
end
|
315
323
|
end
|
316
324
|
|
@@ -17,7 +17,11 @@ module Schemacop
|
|
17
17
|
assert_validation(:foo)
|
18
18
|
assert_validation(4)
|
19
19
|
assert_validation(8) do
|
20
|
-
|
20
|
+
if new_hash_inspect_format?
|
21
|
+
error '/', 'Must not match schema: {"type" => "integer", "minimum" => 5}.'
|
22
|
+
else
|
23
|
+
error '/', 'Must not match schema: {"type"=>"integer", "minimum"=>5}.'
|
24
|
+
end
|
21
25
|
end
|
22
26
|
end
|
23
27
|
|
@@ -37,7 +41,11 @@ module Schemacop
|
|
37
41
|
end
|
38
42
|
assert_validation({})
|
39
43
|
assert_validation(8) do
|
40
|
-
|
44
|
+
if new_hash_inspect_format?
|
45
|
+
error '/', 'Must not match schema: {"type" => "integer", "minimum" => 5}.'
|
46
|
+
else
|
47
|
+
error '/', 'Must not match schema: {"type"=>"integer", "minimum"=>5}.'
|
48
|
+
end
|
41
49
|
end
|
42
50
|
end
|
43
51
|
|
@@ -61,11 +69,19 @@ module Schemacop
|
|
61
69
|
# Needs to fail the validation, as the value is included in the enum
|
62
70
|
# and a string (which the not turns into "failing the validation")
|
63
71
|
assert_validation('bar') do
|
64
|
-
|
72
|
+
if new_hash_inspect_format?
|
73
|
+
error '/', 'Must not match schema: {"type" => "string", "enum" => ["bar", "qux", 123, "faz"]}.'
|
74
|
+
else
|
75
|
+
error '/', 'Must not match schema: {"type"=>"string", "enum"=>["bar", "qux", 123, "faz"]}.'
|
76
|
+
end
|
65
77
|
end
|
66
78
|
|
67
79
|
assert_validation('qux') do
|
68
|
-
|
80
|
+
if new_hash_inspect_format?
|
81
|
+
error '/', 'Must not match schema: {"type" => "string", "enum" => ["bar", "qux", 123, "faz"]}.'
|
82
|
+
else
|
83
|
+
error '/', 'Must not match schema: {"type"=>"string", "enum"=>["bar", "qux", 123, "faz"]}.'
|
84
|
+
end
|
69
85
|
end
|
70
86
|
end
|
71
87
|
|
@@ -89,11 +105,19 @@ module Schemacop
|
|
89
105
|
# Needs to fail the validation, as the value is included in the enum
|
90
106
|
# and a string (which the not turns into "failing the validation")
|
91
107
|
assert_validation('bar') do
|
92
|
-
|
108
|
+
if new_hash_inspect_format?
|
109
|
+
error '/', 'Must not match schema: {"type" => "string", "title" => "Short title", "examples" => ["foo"], "description" => "Longer description", "enum" => ["bar", "qux", 123, "faz"]}.'
|
110
|
+
else
|
111
|
+
error '/', 'Must not match schema: {"type"=>"string", "title"=>"Short title", "examples"=>["foo"], "description"=>"Longer description", "enum"=>["bar", "qux", 123, "faz"]}.'
|
112
|
+
end
|
93
113
|
end
|
94
114
|
|
95
115
|
assert_validation('qux') do
|
96
|
-
|
116
|
+
if new_hash_inspect_format?
|
117
|
+
error '/', 'Must not match schema: {"type" => "string", "title" => "Short title", "examples" => ["foo"], "description" => "Longer description", "enum" => ["bar", "qux", 123, "faz"]}.'
|
118
|
+
else
|
119
|
+
error '/', 'Must not match schema: {"type"=>"string", "title"=>"Short title", "examples"=>["foo"], "description"=>"Longer description", "enum"=>["bar", "qux", 123, "faz"]}.'
|
120
|
+
end
|
97
121
|
end
|
98
122
|
|
99
123
|
# rubocop:enable Layout/LineLength
|
@@ -136,12 +160,20 @@ module Schemacop
|
|
136
160
|
|
137
161
|
assert_validation(nil)
|
138
162
|
assert_validation([]) do
|
139
|
-
|
163
|
+
if new_hash_inspect_format?
|
164
|
+
error '/', 'Must not match schema: {"type" => "array", "items" => {"type" => "integer"}}.'
|
165
|
+
else
|
166
|
+
error '/', 'Must not match schema: {"type"=>"array", "items"=>{"type"=>"integer"}}.'
|
167
|
+
end
|
140
168
|
end
|
141
169
|
assert_validation('foo')
|
142
170
|
assert_validation(['foo'])
|
143
171
|
assert_validation([1]) do
|
144
|
-
|
172
|
+
if new_hash_inspect_format?
|
173
|
+
error '/', 'Must not match schema: {"type" => "array", "items" => {"type" => "integer"}}.'
|
174
|
+
else
|
175
|
+
error '/', 'Must not match schema: {"type"=>"array", "items"=>{"type"=>"integer"}}.'
|
176
|
+
end
|
145
177
|
end
|
146
178
|
end
|
147
179
|
|
@@ -30,16 +30,32 @@ module Schemacop
|
|
30
30
|
assert_validation({ qux: 42 })
|
31
31
|
|
32
32
|
assert_validation(3) do
|
33
|
-
|
33
|
+
if new_hash_inspect_format?
|
34
|
+
error '/', 'Value not included in enum [1, 2, "foo", :bar, {qux: 42}].'
|
35
|
+
else
|
36
|
+
error '/', 'Value not included in enum [1, 2, "foo", :bar, {:qux=>42}].'
|
37
|
+
end
|
34
38
|
end
|
35
39
|
assert_validation('bar') do
|
36
|
-
|
40
|
+
if new_hash_inspect_format?
|
41
|
+
error '/', 'Value not included in enum [1, 2, "foo", :bar, {qux: 42}].'
|
42
|
+
else
|
43
|
+
error '/', 'Value not included in enum [1, 2, "foo", :bar, {:qux=>42}].'
|
44
|
+
end
|
37
45
|
end
|
38
46
|
assert_validation(:foo) do
|
39
|
-
|
47
|
+
if new_hash_inspect_format?
|
48
|
+
error '/', 'Value not included in enum [1, 2, "foo", :bar, {qux: 42}].'
|
49
|
+
else
|
50
|
+
error '/', 'Value not included in enum [1, 2, "foo", :bar, {:qux=>42}].'
|
51
|
+
end
|
40
52
|
end
|
41
53
|
assert_validation({ qux: 13 }) do
|
42
|
-
|
54
|
+
if new_hash_inspect_format?
|
55
|
+
error '/', 'Value not included in enum [1, 2, "foo", :bar, {qux: 42}].'
|
56
|
+
else
|
57
|
+
error '/', 'Value not included in enum [1, 2, "foo", :bar, {:qux=>42}].'
|
58
|
+
end
|
43
59
|
end
|
44
60
|
end
|
45
61
|
|
@@ -274,10 +274,18 @@ module Schemacop
|
|
274
274
|
|
275
275
|
# These need to fail validation, as they are not in the enum list
|
276
276
|
assert_validation(0.5) do
|
277
|
-
|
277
|
+
if new_hash_inspect_format?
|
278
|
+
error '/', 'Value not included in enum [1, 2, "foo", :bar, {qux: 42}, 4.2].'
|
279
|
+
else
|
280
|
+
error '/', 'Value not included in enum [1, 2, "foo", :bar, {:qux=>42}, 4.2].'
|
281
|
+
end
|
278
282
|
end
|
279
283
|
assert_validation(4) do
|
280
|
-
|
284
|
+
if new_hash_inspect_format?
|
285
|
+
error '/', 'Value not included in enum [1, 2, "foo", :bar, {qux: 42}, 4.2].'
|
286
|
+
else
|
287
|
+
error '/', 'Value not included in enum [1, 2, "foo", :bar, {:qux=>42}, 4.2].'
|
288
|
+
end
|
281
289
|
end
|
282
290
|
end
|
283
291
|
|
@@ -109,13 +109,25 @@ module Schemacop
|
|
109
109
|
|
110
110
|
# These will fail, as we didn't put them into the enum list
|
111
111
|
assert_validation(1) do
|
112
|
-
|
112
|
+
if new_hash_inspect_format?
|
113
|
+
error '/', 'Value not included in enum [true, "foo", :baz, [], {qux: "123"}].'
|
114
|
+
else
|
115
|
+
error '/', 'Value not included in enum [true, "foo", :baz, [], {:qux=>"123"}].'
|
116
|
+
end
|
113
117
|
end
|
114
118
|
assert_validation(:bar) do
|
115
|
-
|
119
|
+
if new_hash_inspect_format?
|
120
|
+
error '/', 'Value not included in enum [true, "foo", :baz, [], {qux: "123"}].'
|
121
|
+
else
|
122
|
+
error '/', 'Value not included in enum [true, "foo", :baz, [], {:qux=>"123"}].'
|
123
|
+
end
|
116
124
|
end
|
117
125
|
assert_validation({ qux: 42 }) do
|
118
|
-
|
126
|
+
if new_hash_inspect_format?
|
127
|
+
error '/', 'Value not included in enum [true, "foo", :baz, [], {qux: "123"}].'
|
128
|
+
else
|
129
|
+
error '/', 'Value not included in enum [true, "foo", :baz, [], {:qux=>"123"}].'
|
130
|
+
end
|
119
131
|
end
|
120
132
|
end
|
121
133
|
|
@@ -357,6 +357,107 @@ module Schemacop
|
|
357
357
|
assert_cast '01,032', [1, 32]
|
358
358
|
end
|
359
359
|
|
360
|
+
def test_format_ipv4
|
361
|
+
schema :string, format: :ipv4
|
362
|
+
|
363
|
+
assert_json(type: :string, format: :ipv4)
|
364
|
+
|
365
|
+
assert_validation 234 do
|
366
|
+
error '/', StringNodeTest.invalid_type_error(Integer)
|
367
|
+
end
|
368
|
+
|
369
|
+
assert_validation 'sd sfdij soidf' do
|
370
|
+
error '/', 'String does not match format "ipv4".'
|
371
|
+
end
|
372
|
+
|
373
|
+
# Some valid IPv4 addresses
|
374
|
+
assert_validation '0.1.2.3'
|
375
|
+
assert_validation '110.0.217.94'
|
376
|
+
assert_validation '59.1.18.160'
|
377
|
+
assert_validation '83.212.124.74'
|
378
|
+
assert_validation '208.122.67.117'
|
379
|
+
assert_validation '175.186.176.213'
|
380
|
+
|
381
|
+
# Some invalid IPv4 addresses
|
382
|
+
assert_validation '256.1.4.2' do
|
383
|
+
error '/', 'String does not match format "ipv4".'
|
384
|
+
end
|
385
|
+
assert_validation '2.4.522.1' do
|
386
|
+
error '/', 'String does not match format "ipv4".'
|
387
|
+
end
|
388
|
+
assert_validation '1.1.1' do
|
389
|
+
error '/', 'String does not match format "ipv4".'
|
390
|
+
end
|
391
|
+
assert_validation '1' do
|
392
|
+
error '/', 'String does not match format "ipv4".'
|
393
|
+
end
|
394
|
+
|
395
|
+
# CIDR addresses are not allowed
|
396
|
+
assert_validation '247.182.236.127/24' do
|
397
|
+
error '/', 'String does not match format "ipv4".'
|
398
|
+
end
|
399
|
+
|
400
|
+
# And IPv6 isn't allowed as well
|
401
|
+
assert_validation 'd91c:af3e:72f1:f5c3::::ad81' do
|
402
|
+
error '/', 'String does not match format "ipv4".'
|
403
|
+
end
|
404
|
+
end
|
405
|
+
|
406
|
+
def test_format_ipv6
|
407
|
+
schema :string, format: :ipv6
|
408
|
+
|
409
|
+
assert_json(type: :string, format: :ipv6)
|
410
|
+
|
411
|
+
assert_validation 234 do
|
412
|
+
error '/', StringNodeTest.invalid_type_error(Integer)
|
413
|
+
end
|
414
|
+
|
415
|
+
assert_validation 'sd sfdij soidf' do
|
416
|
+
error '/', 'String does not match format "ipv6".'
|
417
|
+
end
|
418
|
+
|
419
|
+
# Some valid IPv6 addresses
|
420
|
+
assert_validation '2001:0db8:85a3:0000:0000:8a2e:0370:7334'
|
421
|
+
assert_validation '::1'
|
422
|
+
assert_validation '2001:db8::ff00:42:8329'
|
423
|
+
|
424
|
+
# Some invalid IPv6 addresses
|
425
|
+
assert_validation '2001:db8:85a3:0000:0000:8a2e:0370:7334:1234' do
|
426
|
+
error '/', 'String does not match format "ipv6".'
|
427
|
+
end
|
428
|
+
assert_validation '2001:db8:85a3::8a2e::7334' do
|
429
|
+
error '/', 'String does not match format "ipv6".'
|
430
|
+
end
|
431
|
+
assert_validation '2001:db8:85a3::g123:4567' do
|
432
|
+
error '/', 'String does not match format "ipv6".'
|
433
|
+
end
|
434
|
+
|
435
|
+
# CIDR addresses are not allowed
|
436
|
+
assert_validation '247.182.236.127/24' do
|
437
|
+
error '/', 'String does not match format "ipv6".'
|
438
|
+
end
|
439
|
+
|
440
|
+
# And IPv4 isn't allowed as well
|
441
|
+
assert_validation '0.1.2.3' do
|
442
|
+
error '/', 'String does not match format "ipv6".'
|
443
|
+
end
|
444
|
+
assert_validation '110.0.217.94' do
|
445
|
+
error '/', 'String does not match format "ipv6".'
|
446
|
+
end
|
447
|
+
assert_validation '59.1.18.160' do
|
448
|
+
error '/', 'String does not match format "ipv6".'
|
449
|
+
end
|
450
|
+
assert_validation '83.212.124.74' do
|
451
|
+
error '/', 'String does not match format "ipv6".'
|
452
|
+
end
|
453
|
+
assert_validation '208.122.67.117' do
|
454
|
+
error '/', 'String does not match format "ipv6".'
|
455
|
+
end
|
456
|
+
assert_validation '175.186.176.213' do
|
457
|
+
error '/', 'String does not match format "ipv6".'
|
458
|
+
end
|
459
|
+
end
|
460
|
+
|
360
461
|
def test_format_custom
|
361
462
|
Schemacop.register_string_formatter(
|
362
463
|
:integer_tuple_list,
|
@@ -535,10 +636,18 @@ module Schemacop
|
|
535
636
|
|
536
637
|
# These need to fail validation, as they are not in the enum list
|
537
638
|
assert_validation('bar') do
|
538
|
-
|
639
|
+
if new_hash_inspect_format?
|
640
|
+
error '/', 'Value not included in enum [1, 2, "foo", :bar, {qux: 42}].'
|
641
|
+
else
|
642
|
+
error '/', 'Value not included in enum [1, 2, "foo", :bar, {:qux=>42}].'
|
643
|
+
end
|
539
644
|
end
|
540
645
|
assert_validation('Lorem ipsum') do
|
541
|
-
|
646
|
+
if new_hash_inspect_format?
|
647
|
+
error '/', 'Value not included in enum [1, 2, "foo", :bar, {qux: 42}].'
|
648
|
+
else
|
649
|
+
error '/', 'Value not included in enum [1, 2, "foo", :bar, {:qux=>42}].'
|
650
|
+
end
|
542
651
|
end
|
543
652
|
end
|
544
653
|
|
@@ -70,7 +70,11 @@ module Schemacop
|
|
70
70
|
|
71
71
|
# These need to fail validation, as they are not in the enum list
|
72
72
|
assert_validation(:foo) do
|
73
|
-
|
73
|
+
if new_hash_inspect_format?
|
74
|
+
error '/', 'Value not included in enum [1, 2, "foo", :bar, {qux: 42}].'
|
75
|
+
else
|
76
|
+
error '/', 'Value not included in enum [1, 2, "foo", :bar, {:qux=>42}].'
|
77
|
+
end
|
74
78
|
end
|
75
79
|
end
|
76
80
|
|
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.31
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sitrox
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-02-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -38,8 +38,8 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 0.0.4
|
41
|
-
description:
|
42
|
-
email:
|
41
|
+
description:
|
42
|
+
email:
|
43
43
|
executables: []
|
44
44
|
extensions: []
|
45
45
|
extra_rdoc_files: []
|
@@ -151,7 +151,7 @@ homepage: https://github.com/sitrox/schemacop
|
|
151
151
|
licenses:
|
152
152
|
- MIT
|
153
153
|
metadata: {}
|
154
|
-
post_install_message:
|
154
|
+
post_install_message:
|
155
155
|
rdoc_options: []
|
156
156
|
require_paths:
|
157
157
|
- lib
|
@@ -166,8 +166,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
166
166
|
- !ruby/object:Gem::Version
|
167
167
|
version: '0'
|
168
168
|
requirements: []
|
169
|
-
rubygems_version: 3.
|
170
|
-
signing_key:
|
169
|
+
rubygems_version: 3.4.6
|
170
|
+
signing_key:
|
171
171
|
specification_version: 4
|
172
172
|
summary: Schemacop validates ruby structures consisting of nested hashes and arrays
|
173
173
|
against simple schema definitions.
|