scheming 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +42 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +14 -7
- data/README.md +10 -5
- data/lib/scheming/dsl/data_builder.rb +0 -1
- data/lib/scheming/dsl/tagging.rb +2 -2
- data/lib/scheming/dsl/type_specs.rb +7 -0
- data/lib/scheming/schema/json.rb +11 -1
- data/lib/scheming/type.rb +17 -0
- data/lib/scheming/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c861bcba1706b9ffe842a7d13cb55b047479d57a1c7e44a6e7fa7a934c83819a
|
4
|
+
data.tar.gz: 8837b76f3fa1c0c334387432a8c466085a96064482b4ff1dd00bbabc2b69c1ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c8d822270972cb4abc4837c89fa8084b78132af50acc829e7b610fe74cb5ce6bc517ea579528b489b774daa4aec17dd971704ad7f54c3113589d0fee225b22ed
|
7
|
+
data.tar.gz: 3c72a5b224d4d345ee050045d75f72ae74413e1bb78be6f1203795b4ed015f5327ca2e998a05712e086aef4b5d4925818c09c3afb98c5ffb1ac94ba1b6374296
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,47 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.6.0]
|
4
|
+
|
5
|
+
### Added
|
6
|
+
|
7
|
+
- `Union` type added
|
8
|
+
|
9
|
+
# Example
|
10
|
+
```ruby
|
11
|
+
Order = Scheming.object do
|
12
|
+
attribute :id, Union(String, Integer)
|
13
|
+
end
|
14
|
+
|
15
|
+
Scheming::Schema.json(Order)
|
16
|
+
# =>
|
17
|
+
{
|
18
|
+
oneOf: [
|
19
|
+
{ type: 'string' },
|
20
|
+
{ type: 'integer' }
|
21
|
+
]
|
22
|
+
}
|
23
|
+
```
|
24
|
+
|
25
|
+
### Fixed
|
26
|
+
|
27
|
+
- Incorrect YARD comment tags and syntax.
|
28
|
+
|
29
|
+
### Breaking Change
|
30
|
+
|
31
|
+
- Switch from `json-schema` to `json_schemer`
|
32
|
+
|
33
|
+
> TL;DR
|
34
|
+
required object properties for the JSON schema
|
35
|
+
are now strings instead of symbols
|
36
|
+
|
37
|
+
After doing to research I've found that `json_schemer` is
|
38
|
+
more maintained than what was currently being used. It has
|
39
|
+
a smaller footprint and is much faster at validation.
|
40
|
+
|
41
|
+
As a consequence the `required` properties needed to be
|
42
|
+
changed from symbols to strings in the generated JSON schema.
|
43
|
+
|
44
|
+
|
3
45
|
## [0.5.0] - 2024-05-02
|
4
46
|
|
5
47
|
### Added
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
scheming (0.
|
4
|
+
scheming (0.6.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -16,8 +16,6 @@ GEM
|
|
16
16
|
minitest (>= 5.1)
|
17
17
|
mutex_m
|
18
18
|
tzinfo (~> 2.0)
|
19
|
-
addressable (2.8.6)
|
20
|
-
public_suffix (>= 2.0.2, < 6.0)
|
21
19
|
ast (2.4.2)
|
22
20
|
base64 (0.2.0)
|
23
21
|
bigdecimal (3.1.7)
|
@@ -28,11 +26,16 @@ GEM
|
|
28
26
|
drb (2.2.1)
|
29
27
|
factory_bot (6.4.6)
|
30
28
|
activesupport (>= 5.0.0)
|
29
|
+
hana (1.3.7)
|
31
30
|
i18n (1.14.4)
|
32
31
|
concurrent-ruby (~> 1.0)
|
33
32
|
json (2.7.2)
|
34
|
-
|
35
|
-
|
33
|
+
json_schemer (2.2.1)
|
34
|
+
base64
|
35
|
+
bigdecimal
|
36
|
+
hana (~> 1.3)
|
37
|
+
regexp_parser (~> 2.0)
|
38
|
+
simpleidn (~> 0.2)
|
36
39
|
language_server-protocol (3.17.0.3)
|
37
40
|
method_source (1.1.0)
|
38
41
|
minitest (5.22.3)
|
@@ -44,7 +47,6 @@ GEM
|
|
44
47
|
pry (0.14.2)
|
45
48
|
coderay (~> 1.1)
|
46
49
|
method_source (~> 1.0)
|
47
|
-
public_suffix (5.0.5)
|
48
50
|
racc (1.7.3)
|
49
51
|
rainbow (3.1.1)
|
50
52
|
rake (13.2.1)
|
@@ -77,8 +79,13 @@ GEM
|
|
77
79
|
rubocop-ast (1.31.2)
|
78
80
|
parser (>= 3.3.0.4)
|
79
81
|
ruby-progressbar (1.13.0)
|
82
|
+
simpleidn (0.2.2)
|
83
|
+
unf (~> 0.1.4)
|
80
84
|
tzinfo (2.0.6)
|
81
85
|
concurrent-ruby (~> 1.0)
|
86
|
+
unf (0.1.4)
|
87
|
+
unf_ext
|
88
|
+
unf_ext (0.0.9.1)
|
82
89
|
unicode-display_width (2.5.0)
|
83
90
|
|
84
91
|
PLATFORMS
|
@@ -86,7 +93,7 @@ PLATFORMS
|
|
86
93
|
|
87
94
|
DEPENDENCIES
|
88
95
|
factory_bot (~> 6.4)
|
89
|
-
|
96
|
+
json_schemer
|
90
97
|
pry (~> 0.14.2)
|
91
98
|
rake (~> 13.0)
|
92
99
|
rspec (~> 3.0)
|
data/README.md
CHANGED
@@ -15,7 +15,7 @@ gem 'scheming'
|
|
15
15
|
Definition:
|
16
16
|
```ruby
|
17
17
|
LineItem = Scheming.object do
|
18
|
-
attribute :id, Integer
|
18
|
+
attribute :id, Union(Integer, String)
|
19
19
|
attribute :name, String
|
20
20
|
attribute :taxable, :bool
|
21
21
|
attribute :price, Float
|
@@ -45,16 +45,21 @@ Scheming::Schema.json(Receipt)
|
|
45
45
|
{
|
46
46
|
type: 'object',
|
47
47
|
additionalProperties: false,
|
48
|
-
required: %
|
48
|
+
required: %w[line_items total location],
|
49
49
|
properties: {
|
50
50
|
line_items: {
|
51
51
|
type: 'array',
|
52
52
|
items: {
|
53
53
|
type: 'object',
|
54
54
|
additionalProperties: false,
|
55
|
-
required: %
|
55
|
+
required: %w[id name taxable price],
|
56
56
|
properties: {
|
57
|
-
id: {
|
57
|
+
id: {
|
58
|
+
oneOf: [
|
59
|
+
{ type: 'integer' },
|
60
|
+
{ type: 'string' }
|
61
|
+
]
|
62
|
+
},
|
58
63
|
name: { type: 'string' },
|
59
64
|
taxable: { type: 'boolean' },
|
60
65
|
desc: {
|
@@ -75,7 +80,7 @@ Scheming::Schema.json(Receipt)
|
|
75
80
|
location: {
|
76
81
|
type: 'object',
|
77
82
|
additionalProperties: false,
|
78
|
-
required: %
|
83
|
+
required: %w[x y],
|
79
84
|
properties: {
|
80
85
|
x: { type: 'number' },
|
81
86
|
y: { type: 'number' }
|
data/lib/scheming/dsl/tagging.rb
CHANGED
@@ -10,7 +10,7 @@ class Scheming::DSL::Tagging
|
|
10
10
|
#
|
11
11
|
class Tag
|
12
12
|
# @param name [Symbo]
|
13
|
-
# @data [Hash<Symbol, Object>]
|
13
|
+
# @param data [Hash<Symbol, Object>]
|
14
14
|
def initialize(name, data)
|
15
15
|
@name = name
|
16
16
|
@data = data
|
@@ -29,8 +29,8 @@ class Scheming::DSL::Tagging
|
|
29
29
|
nil
|
30
30
|
end
|
31
31
|
|
32
|
-
# @param taglist [Hash<Symbol, Object>]
|
33
32
|
# @param name [Symbol]
|
33
|
+
# @param data [Hash<Symbol, Object>]
|
34
34
|
# @return [Tag]
|
35
35
|
def tag!(name, data)
|
36
36
|
@tags[name] = Tag.new(name, data)
|
@@ -26,4 +26,11 @@ module Scheming::DSL::TypeSpecs
|
|
26
26
|
type = Scheming::DSL::TypeResolver.resolve(type_spec)
|
27
27
|
Scheming::Type::Nullable.new(type)
|
28
28
|
end
|
29
|
+
|
30
|
+
def Union(*type_specs) # rubocop:disable Naming/MethodName
|
31
|
+
types = type_specs.map do |type_spec|
|
32
|
+
Scheming::DSL::TypeResolver.resolve(type_spec)
|
33
|
+
end
|
34
|
+
Scheming::Type::Union.new(types)
|
35
|
+
end
|
29
36
|
end
|
data/lib/scheming/schema/json.rb
CHANGED
@@ -29,7 +29,10 @@ module Scheming::Schema
|
|
29
29
|
private
|
30
30
|
|
31
31
|
def required
|
32
|
-
attributes
|
32
|
+
attributes
|
33
|
+
.required
|
34
|
+
.map! { |attr| attr.field_name.to_s.freeze }
|
35
|
+
.freeze
|
33
36
|
end
|
34
37
|
|
35
38
|
def properties
|
@@ -39,6 +42,13 @@ module Scheming::Schema
|
|
39
42
|
end
|
40
43
|
end
|
41
44
|
|
45
|
+
refine Scheming::Type::Union do
|
46
|
+
# @!attribute [r] types
|
47
|
+
# @return [Array<Scheming::Type::Base>]
|
48
|
+
|
49
|
+
def schema = { oneOf: types.map(&:schema).freeze }
|
50
|
+
end
|
51
|
+
|
42
52
|
refine Scheming::Type::Nullable do
|
43
53
|
# @!attribute [r] type
|
44
54
|
# @return [Scheming::Type::Base]
|
data/lib/scheming/type.rb
CHANGED
@@ -47,6 +47,23 @@ module Scheming::Type
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
+
# = Union Type Definition
|
51
|
+
#
|
52
|
+
# In cases where a value can be of many different
|
53
|
+
# types a union is how to describe this.
|
54
|
+
#
|
55
|
+
class Union < Base
|
56
|
+
# @return [Array<Scheming::Type::Base>]
|
57
|
+
attr_reader :types
|
58
|
+
|
59
|
+
# @param types [Array<Scheming::Type::Base>]
|
60
|
+
def initialize(types)
|
61
|
+
super()
|
62
|
+
@types = types
|
63
|
+
freeze
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
50
67
|
# = Enumeration Type Definition
|
51
68
|
#
|
52
69
|
# The wrapper that describes a type and holds
|
data/lib/scheming/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scheming
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Falk
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-05-
|
11
|
+
date: 2024-05-04 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Ergonomic Data Design for the Masses
|
14
14
|
email:
|