schemacop 3.0.23 → 3.0.25

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: bb46676c0434b9f8bf65c4db36b60f246773349c693ff25e6682c520d847f6dc
4
- data.tar.gz: 4de12ae503b4c052ad6ef01922a55f58ca4d70a7103c8d83a5730965bc25f541
3
+ metadata.gz: 6f8c7ab35c69a90c61abae57241a5b2c3e0a2b34e28907527fc017e28edd1d38
4
+ data.tar.gz: 736001d1624fecf2abe1486beaf4f07ea9072cbefb32c5393e1d7382a38ce9ac
5
5
  SHA512:
6
- metadata.gz: 6bfd8e7c8b107fe7c517205d1eb3039d113bd220bed439902d36c27ee17251e3c364e5ba4f8550238d80f7d392a9c08326b4d0af3ebb1644259b501c402e7359
7
- data.tar.gz: 57c30c35fd163caf9cb33cb5e97682a6030ce2bd0db5d66a61b92edd310d87148d3d0871013ccb704e7f0e8b3217b4ae42caa584e51695fda57583a3bd3bba5f
6
+ metadata.gz: 766a3ab0ad94ad6be036ecabe7eb6e8df9e0ed1330c97356e6510e47b6446303f6361e05facec1f353a02f0e4cdea10e704351ec30a539acdc41320227473750
7
+ data.tar.gz: f9ce6508cdf4374cd8e6909db207225932ca79ccaaf1d504cae8c011f90212431c0f11976c0f112cebf2bf3bf96edd23ec09fb4c27bce8da6e99a48147f9ac1b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Change log
2
2
 
3
+ ## 3.0.25 (2023-10-30)
4
+
5
+ * Improve documentation: list validation
6
+
7
+ ## 3.0.24 (2023-05-15)
8
+
9
+ * Add `require_key` option
10
+
3
11
  ## 3.0.23 (2023-05-04)
4
12
 
5
13
  * Improve formatting regular expressions for error messages and OpenAPI
data/README_V3.md CHANGED
@@ -109,6 +109,16 @@ The nodes in Schemacop v3 also support generic keywords, similar to JSON schema:
109
109
  value is not in the array, the validation will fail
110
110
  * `default`: You may provide a default value for items that will be set if the
111
111
  value is not given
112
+ * `require_key`: If set to true, validate that the key of this node is present,
113
+ regardless of the value (including `nil`). This is only validated if the
114
+ schema type is set to `:hash`.
115
+ Example:
116
+ ```ruby
117
+ Schemacop::Schema3.new(:hash) do
118
+ str? :foo, require_key: true
119
+ int? :bar, require_key: true
120
+ end
121
+ ```
112
122
 
113
123
  The three keywords `title`, `description` and `examples` aren't used for validation,
114
124
  but can be used to document the schema. They will be included in the JSON output
@@ -663,10 +673,11 @@ how you specify your array contents.
663
673
 
664
674
  List validation validates a sequence of arbitrary length where each item matches
665
675
  the same schema. Unless you specify a `min_items` count on the array node, an
666
- empty array will also suffice. To specify a list validation, use the `list` DSL
667
- method, and specify the type you want to validate against. Here, you need to
668
- specify the type of the element using the long `type` name (e.g. `integer` and
669
- not `int`).
676
+ empty array will also suffice. If the option `required: true` is not specified,
677
+ a list containing only `nil` values is also valid. To specify a list validation,
678
+ use the `list` DSL method, and specify the type you want to validate against.
679
+ Here, you need to specify the type of the element using the long `type` name
680
+ (e.g. `integer` and not `int`).
670
681
 
671
682
  For example, you can specify that you want an array with only integers between 1 and 5:
672
683
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.0.23
1
+ 3.0.25
@@ -109,6 +109,7 @@ module Schemacop
109
109
  result.in_path(node.name) do
110
110
  next if node.name.is_a?(Regexp)
111
111
 
112
+ result.error "Key #{node.name} must be given." if node.require_key? && !data_hash.include?(node.name)
112
113
  node._validate(data_hash[node.name], result: result)
113
114
  end
114
115
  end
@@ -8,6 +8,7 @@ module Schemacop
8
8
  attr_reader :description
9
9
  attr_reader :options
10
10
  attr_reader :parent
11
+ attr_reader :require_key
11
12
 
12
13
  class_attribute :_supports_children
13
14
  self._supports_children = nil
@@ -50,7 +51,7 @@ module Schemacop
50
51
  end
51
52
 
52
53
  def self.allowed_options
53
- %i[name required default description examples enum parent options title as]
54
+ %i[name required default description examples enum parent options title as require_key]
54
55
  end
55
56
 
56
57
  def self.dsl_methods
@@ -87,6 +88,7 @@ module Schemacop
87
88
  @description = options.delete(:description)
88
89
  @examples = options.delete(:examples)
89
90
  @enum = options.delete(:enum)&.to_set
91
+ @require_key = !!options.delete(:require_key)
90
92
  @parent = options.delete(:parent)
91
93
  @options = options
92
94
  @schemas = {}
@@ -136,6 +138,10 @@ module Schemacop
136
138
  @required
137
139
  end
138
140
 
141
+ def require_key?
142
+ @require_key
143
+ end
144
+
139
145
  def as_json
140
146
  process_json([], {})
141
147
  end
@@ -181,6 +187,7 @@ module Schemacop
181
187
  json[:description] = @description if @description
182
188
  json[:default] = @default unless @default.nil?
183
189
  json[:enum] = @enum.to_a if @enum
190
+ json[:require_key] = @require_key if @require_key
184
191
 
185
192
  return json.as_json
186
193
  end
data/schemacop.gemspec CHANGED
@@ -1,49 +1,37 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: schemacop 3.0.23 ruby lib
2
+ # stub: schemacop 3.0.25 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "schemacop".freeze
6
- s.version = "3.0.23"
6
+ s.version = "3.0.25"
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 = "2023-04-05"
11
+ s.date = "2023-10-30"
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.0.3".freeze
15
+ s.rubygems_version = "3.2.15".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
19
  if s.respond_to? :specification_version then
20
20
  s.specification_version = 4
21
+ end
21
22
 
22
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
23
- s.add_runtime_dependency(%q<activesupport>.freeze, [">= 4.0"])
24
- s.add_runtime_dependency(%q<ruby2_keywords>.freeze, ["= 0.0.4"])
25
- s.add_development_dependency(%q<bundler>.freeze, [">= 0"])
26
- s.add_development_dependency(%q<rake>.freeze, [">= 0"])
27
- s.add_development_dependency(%q<minitest>.freeze, [">= 0"])
28
- s.add_development_dependency(%q<minitest-reporters>.freeze, [">= 0"])
29
- s.add_development_dependency(%q<colorize>.freeze, [">= 0"])
30
- s.add_development_dependency(%q<rubocop>.freeze, ["= 1.24.1"])
31
- s.add_development_dependency(%q<pry>.freeze, [">= 0"])
32
- s.add_development_dependency(%q<byebug>.freeze, [">= 0"])
33
- s.add_development_dependency(%q<simplecov>.freeze, ["= 0.21.2"])
34
- else
35
- s.add_dependency(%q<activesupport>.freeze, [">= 4.0"])
36
- s.add_dependency(%q<ruby2_keywords>.freeze, ["= 0.0.4"])
37
- s.add_dependency(%q<bundler>.freeze, [">= 0"])
38
- s.add_dependency(%q<rake>.freeze, [">= 0"])
39
- s.add_dependency(%q<minitest>.freeze, [">= 0"])
40
- s.add_dependency(%q<minitest-reporters>.freeze, [">= 0"])
41
- s.add_dependency(%q<colorize>.freeze, [">= 0"])
42
- s.add_dependency(%q<rubocop>.freeze, ["= 1.24.1"])
43
- s.add_dependency(%q<pry>.freeze, [">= 0"])
44
- s.add_dependency(%q<byebug>.freeze, [">= 0"])
45
- s.add_dependency(%q<simplecov>.freeze, ["= 0.21.2"])
46
- end
23
+ if s.respond_to? :add_runtime_dependency then
24
+ s.add_runtime_dependency(%q<activesupport>.freeze, [">= 4.0"])
25
+ s.add_runtime_dependency(%q<ruby2_keywords>.freeze, ["= 0.0.4"])
26
+ s.add_development_dependency(%q<bundler>.freeze, [">= 0"])
27
+ s.add_development_dependency(%q<rake>.freeze, [">= 0"])
28
+ s.add_development_dependency(%q<minitest>.freeze, [">= 0"])
29
+ s.add_development_dependency(%q<minitest-reporters>.freeze, [">= 0"])
30
+ s.add_development_dependency(%q<colorize>.freeze, [">= 0"])
31
+ s.add_development_dependency(%q<rubocop>.freeze, ["= 1.24.1"])
32
+ s.add_development_dependency(%q<pry>.freeze, [">= 0"])
33
+ s.add_development_dependency(%q<byebug>.freeze, [">= 0"])
34
+ s.add_development_dependency(%q<simplecov>.freeze, ["= 0.21.2"])
47
35
  else
48
36
  s.add_dependency(%q<activesupport>.freeze, [">= 4.0"])
49
37
  s.add_dependency(%q<ruby2_keywords>.freeze, ["= 0.0.4"])
@@ -1208,6 +1208,33 @@ module Schemacop
1208
1208
  error '/', 'Obsolete property "obsolete_key".'
1209
1209
  end
1210
1210
  end
1211
+
1212
+ def test_schema_required_key
1213
+ @schema = Schemacop::Schema3.new(:hash) do
1214
+ str? :foo, require_key: true
1215
+ str? :ok, require_key: true
1216
+ int? :bar, require_key: true
1217
+ end
1218
+
1219
+ assert_validation({ ok: nil }) do
1220
+ error '/foo', <<~PLAIN.strip
1221
+ Key foo must be given.
1222
+ PLAIN
1223
+ error '/bar', <<~PLAIN.strip
1224
+ Key bar must be given.
1225
+ PLAIN
1226
+ end
1227
+
1228
+ assert_json({
1229
+ properties: {
1230
+ foo: { type: :string, require_key: true },
1231
+ ok: { type: :string, require_key: true },
1232
+ bar: { type: :integer, require_key: true }
1233
+ },
1234
+ additionalProperties: false,
1235
+ type: :object
1236
+ })
1237
+ end
1211
1238
  end
1212
1239
  end
1213
1240
  end
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.23
4
+ version: 3.0.25
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sitrox
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-05 00:00:00.000000000 Z
11
+ date: 2023-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -164,8 +164,8 @@ dependencies:
164
164
  - - '='
165
165
  - !ruby/object:Gem::Version
166
166
  version: 0.21.2
167
- description:
168
- email:
167
+ description:
168
+ email:
169
169
  executables: []
170
170
  extensions: []
171
171
  extra_rdoc_files: []
@@ -277,7 +277,7 @@ homepage: https://github.com/sitrox/schemacop
277
277
  licenses:
278
278
  - MIT
279
279
  metadata: {}
280
- post_install_message:
280
+ post_install_message:
281
281
  rdoc_options: []
282
282
  require_paths:
283
283
  - lib
@@ -292,8 +292,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
292
292
  - !ruby/object:Gem::Version
293
293
  version: '0'
294
294
  requirements: []
295
- rubygems_version: 3.4.6
296
- signing_key:
295
+ rubygems_version: 3.2.15
296
+ signing_key:
297
297
  specification_version: 4
298
298
  summary: Schemacop validates ruby structures consisting of nested hashes and arrays
299
299
  against simple schema definitions.