finitio 0.12.1 → 0.12.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 98a5d335829b36e4723c0cd55955fdd9a17125fe86d74e671b87fb3c965ce78e
4
- data.tar.gz: 3c32527c4dddb343f218420943f748b7126f26b3676c7860371feb9d32136efe
3
+ metadata.gz: dba23fcd08948c1ba59360fcedd3deb9eab5b7f92c49ad8849256da1964574c6
4
+ data.tar.gz: eaea92410902208a2c003fe34f3935604d4c464f4917e4bf06f7129fbfc24364
5
5
  SHA512:
6
- metadata.gz: dd1a8adf0cc87610d51397fee2a6c735f1e42ee58d1cb107da7372b1b1eaa158bc6499bfa01a0870c9721431adc59b28c1efc969258e4c3c89ba6bf6b3957474
7
- data.tar.gz: 8cd34bae14c768d99408191b7484cd6620f99e87b1f7e03e4b1df75914da76c9df50f854e564056aaf5c8ed41d556a2634215f43d102da7006cc0b4d0edc265a
6
+ metadata.gz: 890a227df66eef86898513ba4269863f603c3289c65bd65ff68b1cd6372b5d60b6ae726b46fc9d4c5c898dab78dbc50e124b84733bf6df176c5b4401803741a0
7
+ data.tar.gz: db438df7b731247174b40954c050893fba97d7db522e8b423bf5fb62a0075e44d6d3cb96ea5e58144416801e7ccabb8471e23ffdd1071d29ee790f9c5db1047f
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## 0.12.2 - 2025/03/22
2
+
3
+ * Add Heading#allbut and (Multi)TupleType#allbut, to remove some attributes.
4
+
5
+ This actually starts the support for an algebra on types...
6
+
7
+ * Don't generate anyOf with duplicate types in JsonSchema geneation.
8
+
1
9
  ## 0.12.1 - 2025/03/20
2
10
 
3
11
  * Allow Hash as bulttin type recognized by JsonSchema generation.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- finitio (0.12.1)
4
+ finitio (0.12.2)
5
5
  citrus (>= 3.0, < 4.0)
6
6
 
7
7
  GEM
@@ -2,9 +2,10 @@ module Finitio
2
2
  class AdType
3
3
 
4
4
  def to_json_schema(*args, &bl)
5
- {
6
- anyOf: contracts.map{|c| c.infotype.to_json_schema(*args, &bl) }
7
- }
5
+ subtypes = contracts
6
+ .map{|c| c.infotype.to_json_schema(*args, &bl) }
7
+ .uniq
8
+ subtypes.size == 1 ? subtypes.first : { anyOf: subtypes }
8
9
  end
9
10
 
10
11
  end # class AdType
@@ -14,8 +14,10 @@ module Finitio
14
14
  return { type: 'boolean'} if self == BOOLEAN_TYPE
15
15
  return cs.first.to_json_schema(*args, &bl) if cs.size == 1
16
16
 
17
+ subtypes = cs.map{|c| c.to_json_schema(*args, &bl) }.uniq
18
+ return subtypes.first if subtypes.size == 1
17
19
  {
18
- anyOf: cs.map{|c| c.to_json_schema(*args, &bl) }
20
+ anyOf: subtypes
19
21
  }
20
22
  end
21
23
 
@@ -114,6 +114,10 @@ module Finitio
114
114
  Heading.new(attributes.values.map{|a| a.unconstrained }, options)
115
115
  end
116
116
 
117
+ def allbut(attrs)
118
+ Heading.new(attributes.values.reject{|a| attrs.include?(a.name) }.to_a, @options)
119
+ end
120
+
117
121
  private
118
122
 
119
123
  def normalize_attributes(attrs)
@@ -61,6 +61,10 @@ module Finitio
61
61
  uped
62
62
  end
63
63
 
64
+ def allbut(attrs)
65
+ factor(heading.allbut(attrs))
66
+ end
67
+
64
68
  protected
65
69
 
66
70
  def looks_a_tuple?(value)
@@ -29,5 +29,9 @@ module Finitio
29
29
  super(other, TupleType, MultiTupleType)
30
30
  end
31
31
 
32
+ def factor(heading)
33
+ MultiTupleType.new(heading)
34
+ end
35
+
32
36
  end # class MultiTupleType
33
37
  end # module Finitio
@@ -48,5 +48,9 @@ module Finitio
48
48
  super(other, TupleType, MultiTupleType)
49
49
  end
50
50
 
51
+ def factor(heading)
52
+ TupleType.new(heading)
53
+ end
54
+
51
55
  end # class TupleType
52
56
  end # module Finitio
@@ -3,7 +3,7 @@ module Finitio
3
3
 
4
4
  MAJOR = 0
5
5
  MINOR = 12
6
- TINY = 1
6
+ TINY = 2
7
7
 
8
8
  def self.to_s
9
9
  [ MAJOR, MINOR, TINY ].join('.')
@@ -3,10 +3,10 @@ module Finitio
3
3
  describe "AdType" do
4
4
 
5
5
  let(:type) {
6
- type = AdType.new(Color, [rgb_contract, hex_contract])
6
+ type = AdType.new(Color, [rgb_contract, hex_contract, hex_contract])
7
7
  }
8
8
 
9
- it 'works as expected' do
9
+ it 'works as expected and removes duplicates' do
10
10
  expect(type.to_json_schema).to eql({
11
11
  anyOf: [
12
12
  { type: "integer" },
@@ -46,6 +46,18 @@ module Finitio
46
46
  end
47
47
  end
48
48
 
49
+ context 'when used with two yielding the same final type' do
50
+ let(:union_type) {
51
+ UnionType.new([string_type, string_type])
52
+ }
53
+
54
+ it 'works as expected' do
55
+ expect(union_type.to_json_schema).to eql({
56
+ :type => "string"
57
+ })
58
+ end
59
+ end
60
+
49
61
  context 'when used with a |Nil' do
50
62
  let(:union_type) {
51
63
  UnionType.new([string_type, int_type, nil_type])
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+ module Finitio
3
+ describe TupleType, "allbut" do
4
+
5
+ let(:h1){ Heading.new([Attribute.new(:r, intType), Attribute.new(:b, intType)]) }
6
+ let(:h2){ Heading.new([Attribute.new(:b, intType)]) }
7
+
8
+ let(:t1) { TupleType.new(h1) }
9
+ let(:t2) { TupleType.new(h2) }
10
+
11
+ it 'removes unwanted atributes' do
12
+ expect(t1.allbut([:r])).to eql(t2)
13
+ end
14
+
15
+
16
+ end
17
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: finitio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.1
4
+ version: 0.12.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bernard Lambeau
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-03-20 00:00:00.000000000 Z
11
+ date: 2025-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: citrus
@@ -446,6 +446,7 @@ files:
446
446
  - spec/type/sub_type/test_name.rb
447
447
  - spec/type/test_suppremum.rb
448
448
  - spec/type/test_unconstrained.rb
449
+ - spec/type/tuple_type/test_allbut.rb
449
450
  - spec/type/tuple_type/test_default_name.rb
450
451
  - spec/type/tuple_type/test_dress.rb
451
452
  - spec/type/tuple_type/test_equality.rb
@@ -661,6 +662,7 @@ test_files:
661
662
  - spec/type/sub_type/test_name.rb
662
663
  - spec/type/test_suppremum.rb
663
664
  - spec/type/test_unconstrained.rb
665
+ - spec/type/tuple_type/test_allbut.rb
664
666
  - spec/type/tuple_type/test_default_name.rb
665
667
  - spec/type/tuple_type/test_dress.rb
666
668
  - spec/type/tuple_type/test_equality.rb