sober_swag 0.2.0 → 0.3.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: bb2b4cc3cb2635010c4c3c0950e6ce87272046bf2e4cdbf08cf2e299518444b0
4
- data.tar.gz: c407225c2c1c5abfadc3e074e5aba98ffb929dc47dda16f5f32293a73669c444
3
+ metadata.gz: c404cf1bad19f06280ce4c8a2002899ed37e9e68e0fc910d270b4e14dc38dab6
4
+ data.tar.gz: 29333042d89f5f3de762143ef60566bbbb45640a948c8b5720c4563b236a1d64
5
5
  SHA512:
6
- metadata.gz: 3dbeeaec1ac6280e3029d779b31490a1661e436e87f833b4e5dce4c3eef96031e18988148aa48ebd1d849fe85353e93c1308f64a013c25d03424ad5b81041c8e
7
- data.tar.gz: 51d0d80744d371cc51a2ba5497a9e8942d26a3e96a97625069476b12b612562fff00a0e371441c7851662e2f181a5ff9e33f0d4dcaecb92c233d6a8c4c07f66f
6
+ metadata.gz: 1b84c508452f4dfd1250e0b6255d11173e2eb8382669adb75d3356f842a9ce7e6155410f5c233c6a8eae00697db0a561b3e466cfa9704996fb8de76c164f9c6b
7
+ data.tar.gz: 45f28285e80a666f45f6b8ef3b598fb68c321da83022ee3d13b8532bf97cc9b2fe3eaed36ca3d670fe75b44a37263d349ce76dde44f4ed80bdb5583bb4e7f342
@@ -38,7 +38,13 @@ jobs:
38
38
  bundle config path vendor/bundle
39
39
  bundle install
40
40
  - name: Run tests
41
- run: bundle exec rake
41
+ run: COVERAGE=1 bundle exec rake
42
+ - name: Upload Coverage
43
+ uses: actions/upload-artifact@master
44
+ if: always()
45
+ with:
46
+ name: coverage-report
47
+ path: coverage
42
48
  - uses: actions/cache@v2
43
49
  with:
44
50
  path: example/vendor/bundle
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sober_swag (0.1.0)
4
+ sober_swag (0.2.0)
5
5
  activesupport
6
6
  dry-struct (~> 1.0)
7
7
  dry-types (~> 1.2)
@@ -9,7 +9,7 @@ PATH
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- activesupport (6.0.3.1)
12
+ activesupport (6.0.3.2)
13
13
  concurrent-ruby (~> 1.0, >= 1.0.2)
14
14
  i18n (>= 0.7, < 2)
15
15
  minitest (~> 5.1)
@@ -18,9 +18,9 @@ GEM
18
18
  ast (2.4.1)
19
19
  coderay (1.1.2)
20
20
  concurrent-ruby (1.1.6)
21
- diff-lcs (1.3)
21
+ diff-lcs (1.4.4)
22
22
  docile (1.3.2)
23
- dry-configurable (0.11.3)
23
+ dry-configurable (0.11.6)
24
24
  concurrent-ruby (~> 1.0)
25
25
  dry-core (~> 0.4, >= 0.4.7)
26
26
  dry-equalizer (~> 0.2)
@@ -47,7 +47,7 @@ GEM
47
47
  dry-equalizer (~> 0.3)
48
48
  dry-inflector (~> 0.1, >= 0.1.2)
49
49
  dry-logic (~> 1.0, >= 1.0.2)
50
- i18n (1.8.2)
50
+ i18n (1.8.3)
51
51
  concurrent-ruby (~> 1.0)
52
52
  ice_nine (0.11.2)
53
53
  method_source (0.9.2)
@@ -66,15 +66,15 @@ GEM
66
66
  rspec-core (~> 3.9.0)
67
67
  rspec-expectations (~> 3.9.0)
68
68
  rspec-mocks (~> 3.9.0)
69
- rspec-core (3.9.1)
70
- rspec-support (~> 3.9.1)
71
- rspec-expectations (3.9.0)
69
+ rspec-core (3.9.2)
70
+ rspec-support (~> 3.9.3)
71
+ rspec-expectations (3.9.2)
72
72
  diff-lcs (>= 1.2.0, < 2.0)
73
73
  rspec-support (~> 3.9.0)
74
74
  rspec-mocks (3.9.1)
75
75
  diff-lcs (>= 1.2.0, < 2.0)
76
76
  rspec-support (~> 3.9.0)
77
- rspec-support (3.9.2)
77
+ rspec-support (3.9.3)
78
78
  rubocop (0.88.0)
79
79
  parallel (~> 1.10)
80
80
  parser (>= 2.7.1.1)
@@ -97,7 +97,7 @@ GEM
97
97
  tzinfo (1.2.7)
98
98
  thread_safe (~> 0.1)
99
99
  unicode-display_width (1.7.0)
100
- zeitwerk (2.3.0)
100
+ zeitwerk (2.4.0)
101
101
 
102
102
  PLATFORMS
103
103
  ruby
data/README.md CHANGED
@@ -3,8 +3,6 @@
3
3
  ![Ruby Test Status](https://github.com/SonderMindOrg/sober_swag/workflows/Ruby/badge.svg?branch=master)
4
4
  ![Linters Status](https://github.com/SonderMindOrg/sober_swag/workflows/Linters/badge.svg?branch=master)
5
5
 
6
- ***NOTE: THIS GEM IS HIGHLY EXPERIMENTAL AND PROBABLY SHOULD NOT YET BE USED IN PRODUCTION***.
7
-
8
6
  SoberSwag is a combination of [Dry-Types](https://dry-rb.org/gems/dry-types/1.2/) and [Swagger](https://swagger.io/) that makes your Rails APIs more awesome.
9
7
  Other tools generate documenation from a DSL.
10
8
  This generates documentation from *types*, which (conveniently) also lets you get supercharged strong-params-on-steroids.
@@ -51,7 +49,7 @@ You define the type of parameters you accept, and we reject anything that doesn'
51
49
  ### Typed Responses
52
50
 
53
51
  Want to go further and type your responses too?
54
- Use SoberSwag blueprints, a serializer library heavily inspired by [OutputObjecter](https://github.com/procore/blueprinter)
52
+ Use SoberSwag output objects, a serializer library heavily inspired by [Blueprinter](https://github.com/procore/blueprinter)
55
53
 
56
54
  ```ruby
57
55
  PersonOutputObject = SoberSwag::OutputObject.define do
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- sober_swag (0.1.0)
4
+ sober_swag (0.2.0)
5
5
  activesupport
6
6
  dry-struct (~> 1.0)
7
7
  dry-types (~> 1.2)
@@ -22,6 +22,8 @@ module SoberSwag
22
22
  end
23
23
 
24
24
  def primitive_def(value)
25
+ value = value.primitive if value.is_a?(Dry::Types::Nominal)
26
+
25
27
  return nil unless value.is_a?(Class)
26
28
 
27
29
  if (name = primitive_name(value))
@@ -129,7 +131,7 @@ module SoberSwag
129
131
  when Dry::Types::Sum
130
132
  { oneOf: normalize(parsed_type).elements.map { |t| self.class.new(t.value).schema_stub } }
131
133
  else
132
- raise ArgumentError, "Cannot generate a schema stub for #{type} (#{type.class})"
134
+ raise SoberSwag::Compiler::Error, "Cannot generate a schema stub for #{type} (#{type.class})"
133
135
  end
134
136
  end
135
137
 
@@ -239,6 +241,8 @@ module SoberSwag
239
241
  def ensure_uncomplicated(key, value)
240
242
  return if value[:type]
241
243
 
244
+ return value[:oneOf].each { |member| ensure_uncomplicated(key, member) } if value[:oneOf]
245
+
242
246
  raise TooComplicatedError, <<~ERROR
243
247
  Property #{key} has object-schema #{value}, but this type of param should be simple (IE a primitive of some kind)
244
248
  ERROR
@@ -47,7 +47,11 @@ module SoberSwag
47
47
  end
48
48
 
49
49
  def lazy_type
50
- left.lazy_type | right.lazy_type
50
+ if left.lazy_type == right.lazy_type
51
+ left.lazy_type
52
+ else
53
+ left.lazy_type | right.lazy_type
54
+ end
51
55
  end
52
56
 
53
57
  def lazy_type?
@@ -8,7 +8,9 @@ module SoberSwag
8
8
  @map_f = map_f
9
9
  end
10
10
 
11
- def serialize(object, options)
11
+ attr_reader :base, :map_f
12
+
13
+ def serialize(object, options = {})
12
14
  @base.serialize(@map_f.call(object), options)
13
15
  end
14
16
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SoberSwag
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sober_swag
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anthony Super
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-16 00:00:00.000000000 Z
11
+ date: 2020-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport