schemacop 3.0.0.rc5 → 3.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +24 -0
- data/LICENSE +1 -1
- data/README.md +1 -1
- data/README_V3.md +14 -4
- data/VERSION +1 -1
- data/lib/schemacop/railtie.rb +7 -0
- data/lib/schemacop/v3/boolean_node.rb +8 -0
- data/lib/schemacop/v3/context.rb +4 -0
- data/lib/schemacop/v3/node.rb +1 -1
- data/lib/schemacop/v3/string_node.rb +3 -0
- data/schemacop.gemspec +4 -4
- data/test/unit/schemacop/v3/boolean_node_test.rb +16 -0
- data/test/unit/schemacop/v3/string_node_test.rb +17 -0
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b28a407ae498b94fa8c7897895d052c1bea34ebeee991ab992b4a86aa94f7ab
|
4
|
+
data.tar.gz: 7bd4dbd4f0a51ac591a7ff6189fd98e803597c0487f8a16e43c78774dc75c5e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b40fb214b50815f65f87f978052f0c6bc38018340d00eeeddb68e392dfb44106e0d6ebeb5e908172113dadc57cd0f88bbdf1d230d38cd5dab31382f8d217f34a
|
7
|
+
data.tar.gz: cf87908ded44c22bd53b824e732f7447ade01608104cb55a844879fb7f17b2172b78c13b47adb0f373abbba3a90f75d353cf0f63ec5d74b16128eee780743db6
|
data/CHANGELOG.md
CHANGED
@@ -10,6 +10,30 @@
|
|
10
10
|
### Changes
|
11
11
|
-->
|
12
12
|
|
13
|
+
## 3.0.4 (2021-02-15)
|
14
|
+
|
15
|
+
* Add `examples_keyword` to context which allows to customize the name of the
|
16
|
+
`examples` attribute in JSON output
|
17
|
+
|
18
|
+
## 3.0.3 (2021-02-15)
|
19
|
+
|
20
|
+
* Fix boolean node casting
|
21
|
+
|
22
|
+
## 3.0.2 (2021-02-14)
|
23
|
+
|
24
|
+
* Fix #15 Code to ignore Zeitwerk fails when Zeitwerk is disabled
|
25
|
+
|
26
|
+
## 3.0.1 (2021-02-11)
|
27
|
+
|
28
|
+
* Add format `symbol` to strings
|
29
|
+
|
30
|
+
## 3.0.0 (2021-02-08)
|
31
|
+
|
32
|
+
* Setup Zeitwerk ignores for Rails applications
|
33
|
+
|
34
|
+
* Read previous `3.0.0.rcX` entries for all changes included
|
35
|
+
in this stable release
|
36
|
+
|
13
37
|
## 3.0.0.rc5 (2021-02-05)
|
14
38
|
|
15
39
|
* Use `ruby2_keywords` for compatibility with ruby `2.6.2`
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -16,7 +16,7 @@ Schemacop is tested with the following ruby versions:
|
|
16
16
|
* 2.7.1
|
17
17
|
* 3.0.0
|
18
18
|
|
19
|
-
|
19
|
+
Other ruby versions might work but are not covered by our Travis tests.
|
20
20
|
|
21
21
|
## Basic example
|
22
22
|
|
data/README_V3.md
CHANGED
@@ -241,6 +241,9 @@ transformed into various types.
|
|
241
241
|
* `number`
|
242
242
|
The string must be a number and will be casted to a ruby `Float` object.
|
243
243
|
|
244
|
+
* `symbol`
|
245
|
+
The string can be anything and will be casted to a ruby `Symbol` object.
|
246
|
+
|
244
247
|
#### Examples
|
245
248
|
|
246
249
|
```ruby
|
@@ -1191,14 +1194,17 @@ local schemas > context schemas > global schemas
|
|
1191
1194
|
|
1192
1195
|
Where:
|
1193
1196
|
|
1194
|
-
* local schemas: Defined by using the DSL method
|
1197
|
+
* local schemas: Defined by using the DSL method `scm`
|
1195
1198
|
* context schemas: Defined in the current context using `context.schema`
|
1196
1199
|
* global schemas: Defined in a ruby file in the load path
|
1197
1200
|
|
1198
1201
|
### Rails applications
|
1199
1202
|
|
1200
|
-
In Rails applications, your schemas are automatically eager-
|
1201
|
-
path `'app/schemas'` when your application is started
|
1203
|
+
In Rails applications, your schemas are automatically eager-loaded from the load
|
1204
|
+
path `'app/schemas'` when your application is started, unless your application
|
1205
|
+
is running in the `DEVELOPMENT` environment. In the `DEVELOPMENT` environment,
|
1206
|
+
schemas are loaded each time when they are used, and as such you can make changes
|
1207
|
+
to your external schemas without having to restart the server each time.
|
1202
1208
|
|
1203
1209
|
After starting your application, you can reference them like normally defined
|
1204
1210
|
reference schemas, with the name being relative to the load path.
|
@@ -1246,8 +1252,12 @@ schema.validate!({usr: {first_name: 'Joe', last_name: 'Doe', groups: [{name: 'fo
|
|
1246
1252
|
### Non-Rails applications
|
1247
1253
|
|
1248
1254
|
Usage in non-Rails applications is the same as with usage in Rails applications,
|
1249
|
-
however you need to eager load the schemas yourself:
|
1255
|
+
however you might need to eager load the schemas yourself:
|
1250
1256
|
|
1251
1257
|
```ruby
|
1252
1258
|
Schemacop::V3::GlobalContext.eager_load!
|
1253
1259
|
```
|
1260
|
+
|
1261
|
+
As mentioned before, you can also use the external schemas without having to
|
1262
|
+
eager-load them, but if you use the schemas multiple times, it might be better
|
1263
|
+
to eager-load them on start of your application / script.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.0.
|
1
|
+
3.0.4
|
data/lib/schemacop/railtie.rb
CHANGED
@@ -5,6 +5,13 @@ module Schemacop
|
|
5
5
|
unless Rails.env.development?
|
6
6
|
V3::GlobalContext.eager_load!
|
7
7
|
end
|
8
|
+
|
9
|
+
# Tell Zeitwerk to ignore the files in our load path
|
10
|
+
if defined?(Rails) && defined?(Zeitwerk) && Rails.autoloaders.zeitwerk_enabled?
|
11
|
+
Schemacop.load_paths.each do |load_path|
|
12
|
+
Rails.autoloaders.main.ignore(Rails.root.join(load_path))
|
13
|
+
end
|
14
|
+
end
|
8
15
|
end
|
9
16
|
end
|
10
17
|
end
|
data/lib/schemacop/v3/context.rb
CHANGED
@@ -2,9 +2,13 @@ module Schemacop
|
|
2
2
|
module V3
|
3
3
|
class Context
|
4
4
|
attr_accessor :schemas
|
5
|
+
attr_accessor :examples_keyword
|
6
|
+
|
7
|
+
DEFAULT_EXAMPLES_KEYWORD = :examples
|
5
8
|
|
6
9
|
def initialize
|
7
10
|
@schemas = {}.with_indifferent_access.freeze
|
11
|
+
@examples_keyword = DEFAULT_EXAMPLES_KEYWORD
|
8
12
|
end
|
9
13
|
|
10
14
|
def schema(name, type = :hash, **options, &block)
|
data/lib/schemacop/v3/node.rb
CHANGED
@@ -170,7 +170,7 @@ module Schemacop
|
|
170
170
|
end
|
171
171
|
|
172
172
|
json[:title] = @title if @title
|
173
|
-
json[
|
173
|
+
json[Schemacop.context.examples_keyword] = @examples if @examples
|
174
174
|
json[:description] = @description if @description
|
175
175
|
json[:default] = @default if @default
|
176
176
|
json[:enum] = @enum.to_a if @enum
|
@@ -16,6 +16,7 @@ module Schemacop
|
|
16
16
|
email: URI::MailTo::EMAIL_REGEXP,
|
17
17
|
boolean: /^(true|false)$/,
|
18
18
|
binary: nil,
|
19
|
+
symbol: nil,
|
19
20
|
integer: /^-?[0-9]+$/,
|
20
21
|
number: /^-?[0-9]+(\.[0-9]+)?$/
|
21
22
|
}.freeze
|
@@ -87,6 +88,8 @@ module Schemacop
|
|
87
88
|
return Integer(to_cast)
|
88
89
|
when :number
|
89
90
|
return Float(to_cast)
|
91
|
+
when :symbol
|
92
|
+
return to_cast.to_sym
|
90
93
|
else
|
91
94
|
return to_cast
|
92
95
|
end
|
data/schemacop.gemspec
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: schemacop 3.0.
|
2
|
+
# stub: schemacop 3.0.4 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.4"
|
7
7
|
|
8
|
-
s.required_rubygems_version = Gem::Requirement.new("
|
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-02-
|
11
|
+
s.date = "2021-02-15"
|
12
12
|
s.files = [".gitignore".freeze, ".releaser_config".freeze, ".rubocop.yml".freeze, ".travis.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]
|
@@ -120,6 +120,22 @@ module Schemacop
|
|
120
120
|
]
|
121
121
|
})
|
122
122
|
end
|
123
|
+
|
124
|
+
def test_cast
|
125
|
+
schema :boolean
|
126
|
+
|
127
|
+
assert_cast(true, true)
|
128
|
+
assert_cast(false, false)
|
129
|
+
assert_cast(nil, nil)
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_cast_default
|
133
|
+
schema :boolean, default: true
|
134
|
+
|
135
|
+
assert_cast(true, true)
|
136
|
+
assert_cast(false, false)
|
137
|
+
assert_cast(nil, true)
|
138
|
+
end
|
123
139
|
end
|
124
140
|
end
|
125
141
|
end
|
@@ -165,6 +165,23 @@ module Schemacop
|
|
165
165
|
assert_cast('john.doe@example.com', 'john.doe@example.com')
|
166
166
|
end
|
167
167
|
|
168
|
+
def test_format_symbol
|
169
|
+
schema :string, format: :symbol
|
170
|
+
|
171
|
+
assert_json(type: :string, format: :symbol)
|
172
|
+
|
173
|
+
assert_validation 'foobar'
|
174
|
+
assert_validation ''
|
175
|
+
|
176
|
+
assert_validation 234 do
|
177
|
+
error '/', 'Invalid type, expected "string".'
|
178
|
+
end
|
179
|
+
|
180
|
+
assert_cast(nil, nil)
|
181
|
+
assert_cast('foobar', :foobar)
|
182
|
+
assert_cast('039n23$g- sfk3/', :'039n23$g- sfk3/')
|
183
|
+
end
|
184
|
+
|
168
185
|
def test_enum
|
169
186
|
schema :string, enum: ['foo', 'some string', 'some other string', 42]
|
170
187
|
|
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.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sitrox
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-02-
|
11
|
+
date: 2021-02-15 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
|
@@ -288,12 +288,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
288
288
|
version: '0'
|
289
289
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
290
290
|
requirements:
|
291
|
-
- - "
|
291
|
+
- - ">="
|
292
292
|
- !ruby/object:Gem::Version
|
293
|
-
version:
|
293
|
+
version: '0'
|
294
294
|
requirements: []
|
295
|
-
rubygems_version: 3.
|
296
|
-
signing_key:
|
295
|
+
rubygems_version: 3.1.4
|
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.
|