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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b21c99fc59c9fe7da35644b47be93b2d6bba2f13f4ef814008a64c92f2235323
4
- data.tar.gz: c0ff8026a852f0b8e4c91bf86aa4a172502a12b3c89dcd693527863dc7cf58aa
3
+ metadata.gz: c861bcba1706b9ffe842a7d13cb55b047479d57a1c7e44a6e7fa7a934c83819a
4
+ data.tar.gz: 8837b76f3fa1c0c334387432a8c466085a96064482b4ff1dd00bbabc2b69c1ae
5
5
  SHA512:
6
- metadata.gz: 93fa8e2cd04de2c77495754fe04aa2cbd84070a862835c83ef535a7830b6e41337b401f2e35dbf297434397523e24b50c8cb97063745fe58d61f881114187424
7
- data.tar.gz: 61c3cf8462b6d9075e593d00fa76921bbb7958e1ac2590f2a4683ff5c2aeac40b28209e579270eff279cea0261d6d1ea8194a0a87d2ebd3b56f93f8bfc8a2966
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
@@ -6,7 +6,7 @@ source 'https://rubygems.org'
6
6
  gemspec
7
7
 
8
8
  gem 'factory_bot', '~> 6.4'
9
- gem 'json-schema', '~> 4.3'
9
+ gem 'json_schemer'
10
10
  gem 'pry', '~> 0.14.2'
11
11
  gem 'rake', '~> 13.0'
12
12
  gem 'rspec', '~> 3.0'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- scheming (0.5.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
- json-schema (4.3.0)
35
- addressable (>= 2.8)
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
- json-schema (~> 4.3)
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: %i[line_items total location],
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: %i[id name taxable price],
55
+ required: %w[id name taxable price],
56
56
  properties: {
57
- id: { type: 'integer' },
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: %i[x y],
83
+ required: %w[x y],
79
84
  properties: {
80
85
  x: { type: 'number' },
81
86
  y: { type: 'number' }
@@ -12,7 +12,6 @@ class Scheming::DSL::DataBuilder
12
12
 
13
13
  # @param field_name [Symbol]
14
14
  # @param type_spec [Object]
15
- # @param null [Boolean]
16
15
  # @return [void]
17
16
  def attribute(field_name, type_spec)
18
17
  @builder = @builder.attribute(
@@ -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
@@ -29,7 +29,10 @@ module Scheming::Schema
29
29
  private
30
30
 
31
31
  def required
32
- attributes.required.map!(&:field_name).freeze
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Scheming
4
- VERSION = '0.5.0'
4
+ VERSION = '0.6.0'
5
5
  end
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.5.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-03 00:00:00.000000000 Z
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: