sober_swag 0.23.0 → 0.24.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/example/Gemfile +1 -1
- data/example/Gemfile.lock +26 -26
- data/lib/sober_swag/input_object.rb +1 -0
- data/lib/sober_swag/output_object/field_syntax.rb +2 -0
- data/lib/sober_swag/reporting/input/struct.rb +1 -0
- data/lib/sober_swag/reporting/output/in_range.rb +64 -0
- data/lib/sober_swag/reporting/output/interface.rb +9 -0
- data/lib/sober_swag/reporting/output/struct.rb +40 -15
- data/lib/sober_swag/reporting/output.rb +1 -0
- data/lib/sober_swag/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da652c96f55ead0e8113b6113381da0fef7be7f0fcbeb807764dd62cf9b9e7c1
|
4
|
+
data.tar.gz: 87be8dd13b0501e69bac77907bc2db755ff0ede1f5c78a87834549a5e62202a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6cefa38497b4f3d6a4769afdf8bffd5d35c44db3b4a1733402d9bf231675693c0efc9195a68285d5f07e93e621f7d2757ec5405e95f50942e97c04a4bf71a930
|
7
|
+
data.tar.gz: 3b0dbf95a6ce1960d04788f7260722ff37d94786ccc50afbd5db60a0f34bb03ef4888c6c0884d9c9ee93db4fd2503df05ba43b430f1feacc242a43b316df7bc1
|
data/example/Gemfile
CHANGED
@@ -8,7 +8,7 @@ gem 'actionpack', '>= 6.0.3.2'
|
|
8
8
|
# Use sqlite3 as the database for Active Record
|
9
9
|
gem 'sqlite3', '~> 1.4'
|
10
10
|
# Use Puma as the app server
|
11
|
-
gem 'puma', '~> 5.
|
11
|
+
gem 'puma', '~> 5.6'
|
12
12
|
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
|
13
13
|
# gem 'jbuilder', '~> 2.7'
|
14
14
|
# Use Active Model has_secure_password
|
data/example/Gemfile.lock
CHANGED
@@ -64,14 +64,14 @@ GEM
|
|
64
64
|
minitest (~> 5.1)
|
65
65
|
tzinfo (~> 1.1)
|
66
66
|
zeitwerk (~> 2.2, >= 2.2.2)
|
67
|
-
bootsnap (1.
|
68
|
-
msgpack (~> 1.
|
67
|
+
bootsnap (1.11.1)
|
68
|
+
msgpack (~> 1.2)
|
69
69
|
builder (3.2.4)
|
70
70
|
byebug (11.1.3)
|
71
71
|
coderay (1.1.3)
|
72
|
-
concurrent-ruby (1.1.
|
72
|
+
concurrent-ruby (1.1.10)
|
73
73
|
crass (1.0.6)
|
74
|
-
diff-lcs (1.
|
74
|
+
diff-lcs (1.5.0)
|
75
75
|
dry-configurable (0.13.0)
|
76
76
|
concurrent-ruby (~> 1.0)
|
77
77
|
dry-core (~> 0.6)
|
@@ -98,16 +98,16 @@ GEM
|
|
98
98
|
dry-types (>= 0.8.1)
|
99
99
|
rails (>= 3)
|
100
100
|
erubi (1.10.0)
|
101
|
-
ffi (1.15.
|
101
|
+
ffi (1.15.5)
|
102
102
|
globalid (1.0.0)
|
103
103
|
activesupport (>= 5.0)
|
104
|
-
i18n (1.
|
104
|
+
i18n (1.10.0)
|
105
105
|
concurrent-ruby (~> 1.0)
|
106
106
|
ice_nine (0.11.2)
|
107
|
-
listen (3.7.
|
107
|
+
listen (3.7.1)
|
108
108
|
rb-fsevent (~> 0.10, >= 0.10.3)
|
109
109
|
rb-inotify (~> 0.9, >= 0.9.10)
|
110
|
-
loofah (2.
|
110
|
+
loofah (2.16.0)
|
111
111
|
crass (~> 1.0.2)
|
112
112
|
nokogiri (>= 1.5.9)
|
113
113
|
mail (2.7.1)
|
@@ -115,17 +115,17 @@ GEM
|
|
115
115
|
marcel (1.0.2)
|
116
116
|
method_source (1.0.0)
|
117
117
|
mini_mime (1.1.2)
|
118
|
-
mini_portile2 (2.
|
119
|
-
minitest (5.
|
120
|
-
msgpack (1.
|
118
|
+
mini_portile2 (2.8.0)
|
119
|
+
minitest (5.15.0)
|
120
|
+
msgpack (1.5.1)
|
121
121
|
nio4r (2.5.8)
|
122
|
-
nokogiri (1.
|
123
|
-
mini_portile2 (~> 2.
|
122
|
+
nokogiri (1.13.4)
|
123
|
+
mini_portile2 (~> 2.8.0)
|
124
124
|
racc (~> 1.4)
|
125
125
|
pry (0.14.1)
|
126
126
|
coderay (~> 1.1)
|
127
127
|
method_source (~> 1.0)
|
128
|
-
puma (5.
|
128
|
+
puma (5.6.4)
|
129
129
|
nio4r (~> 2.0)
|
130
130
|
racc (1.6.0)
|
131
131
|
rack (2.2.3)
|
@@ -158,18 +158,18 @@ GEM
|
|
158
158
|
rake (>= 0.8.7)
|
159
159
|
thor (>= 0.20.3, < 2.0)
|
160
160
|
rake (13.0.6)
|
161
|
-
rb-fsevent (0.11.
|
161
|
+
rb-fsevent (0.11.1)
|
162
162
|
rb-inotify (0.10.1)
|
163
163
|
ffi (~> 1.0)
|
164
|
-
rspec-core (3.
|
165
|
-
rspec-support (~> 3.
|
166
|
-
rspec-expectations (3.
|
164
|
+
rspec-core (3.11.0)
|
165
|
+
rspec-support (~> 3.11.0)
|
166
|
+
rspec-expectations (3.11.0)
|
167
167
|
diff-lcs (>= 1.2.0, < 2.0)
|
168
|
-
rspec-support (~> 3.
|
169
|
-
rspec-mocks (3.
|
168
|
+
rspec-support (~> 3.11.0)
|
169
|
+
rspec-mocks (3.11.1)
|
170
170
|
diff-lcs (>= 1.2.0, < 2.0)
|
171
|
-
rspec-support (~> 3.
|
172
|
-
rspec-rails (5.
|
171
|
+
rspec-support (~> 3.11.0)
|
172
|
+
rspec-rails (5.1.2)
|
173
173
|
actionpack (>= 5.2)
|
174
174
|
activesupport (>= 5.2)
|
175
175
|
railties (>= 5.2)
|
@@ -177,7 +177,7 @@ GEM
|
|
177
177
|
rspec-expectations (~> 3.10)
|
178
178
|
rspec-mocks (~> 3.10)
|
179
179
|
rspec-support (~> 3.10)
|
180
|
-
rspec-support (3.
|
180
|
+
rspec-support (3.11.0)
|
181
181
|
spring (2.1.1)
|
182
182
|
spring-watcher-listen (2.0.1)
|
183
183
|
listen (>= 2.7, < 4.0)
|
@@ -190,14 +190,14 @@ GEM
|
|
190
190
|
activesupport (>= 5.2)
|
191
191
|
sprockets (>= 3.0.0)
|
192
192
|
sqlite3 (1.4.2)
|
193
|
-
thor (1.1
|
193
|
+
thor (1.2.1)
|
194
194
|
thread_safe (0.3.6)
|
195
195
|
tzinfo (1.2.9)
|
196
196
|
thread_safe (~> 0.1)
|
197
197
|
websocket-driver (0.7.5)
|
198
198
|
websocket-extensions (>= 0.1.0)
|
199
199
|
websocket-extensions (0.1.5)
|
200
|
-
zeitwerk (2.5.
|
200
|
+
zeitwerk (2.5.4)
|
201
201
|
|
202
202
|
PLATFORMS
|
203
203
|
ruby
|
@@ -209,7 +209,7 @@ DEPENDENCIES
|
|
209
209
|
dry-types-rails
|
210
210
|
listen (>= 3.0.5, < 3.8)
|
211
211
|
pry
|
212
|
-
puma (~> 5.
|
212
|
+
puma (~> 5.6)
|
213
213
|
rails (~> 6.0.2, >= 6.0.2.2)
|
214
214
|
rspec-rails
|
215
215
|
sober_swag!
|
@@ -42,6 +42,7 @@ module SoberSwag
|
|
42
42
|
# @param type the attribute type
|
43
43
|
def attribute(key, parent = SoberSwag::InputObject, &block)
|
44
44
|
raise ArgumentError, "parent class #{parent} is not an input object type!" unless valid_field_def?(parent, block)
|
45
|
+
raise ArgumentError, "cannot mix reporting and non-reporting types at attribute #{key}" if parent.is_a?(SoberSwag::Reporting::Input::Interface)
|
45
46
|
|
46
47
|
super(key, parent, &block)
|
47
48
|
end
|
@@ -11,6 +11,8 @@ module SoberSwag
|
|
11
11
|
# @param from [Symbol] method name to extract this field from, for convenience.
|
12
12
|
# @param block [Proc] optional way to extract this field.
|
13
13
|
def field(name, serializer, from: nil, &block)
|
14
|
+
raise ArgumentError, "do not mix reporting and non-reporting outputs (at key #{name})" if serializer.is_a?(SoberSwag::Reporting::Output::Interface)
|
15
|
+
|
14
16
|
add_field!(Field.new(name, serializer, from: from, &block))
|
15
17
|
end
|
16
18
|
|
@@ -76,6 +76,7 @@ module SoberSwag
|
|
76
76
|
#
|
77
77
|
def add_attribute!(name, input, required:, description: nil)
|
78
78
|
raise ArgumentError, 'name must be a symbol' unless name.is_a?(Symbol)
|
79
|
+
raise ArgumentError, 'input type must be a SoberSwag::Reporting::Input::Interface' unless input.is_a?(Interface)
|
79
80
|
|
80
81
|
define_attribute(name) # defines an instance method to access this attribute
|
81
82
|
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module SoberSwag
|
2
|
+
module Reporting
|
3
|
+
module Output
|
4
|
+
##
|
5
|
+
# Specify that an output will be within a certain range.
|
6
|
+
# This gets translated to `minimum` and `maximum` keys in swagger.
|
7
|
+
class InRange < Base
|
8
|
+
def initialize(output, range)
|
9
|
+
@output = output
|
10
|
+
@range = range
|
11
|
+
end
|
12
|
+
|
13
|
+
##
|
14
|
+
# @return [Interface]
|
15
|
+
attr_reader :output
|
16
|
+
|
17
|
+
##
|
18
|
+
# @return [Range]
|
19
|
+
attr_reader :range
|
20
|
+
|
21
|
+
def call(value)
|
22
|
+
output.call(value)
|
23
|
+
end
|
24
|
+
|
25
|
+
def serialize_report(value)
|
26
|
+
rep = output.serialize_report(value)
|
27
|
+
|
28
|
+
return rep if rep.is_a?(Report::Base)
|
29
|
+
|
30
|
+
return Report::Value.new(['was not in minimum/maximum range']) unless range.member?(rep)
|
31
|
+
|
32
|
+
rep
|
33
|
+
end
|
34
|
+
|
35
|
+
def swagger_schema
|
36
|
+
schema, found = output.swagger_schema
|
37
|
+
|
38
|
+
merged =
|
39
|
+
if schema.key?(:$ref)
|
40
|
+
{ allOf: [schema] }
|
41
|
+
else
|
42
|
+
schema
|
43
|
+
end.merge(maximum_portion).merge(minimum_portion)
|
44
|
+
|
45
|
+
[merged, found]
|
46
|
+
end
|
47
|
+
|
48
|
+
def maximum_portion
|
49
|
+
return {} unless range.end
|
50
|
+
|
51
|
+
res = { maximum: range.end }
|
52
|
+
res[:exclusiveMaximum] = true if range.exclude_end?
|
53
|
+
res
|
54
|
+
end
|
55
|
+
|
56
|
+
def minimum_portion
|
57
|
+
return {} unless range.begin
|
58
|
+
|
59
|
+
{ minimum: range.begin }
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -40,6 +40,15 @@ module SoberSwag
|
|
40
40
|
Referenced.new(self, name)
|
41
41
|
end
|
42
42
|
|
43
|
+
##
|
44
|
+
# @return [SoberSwag::Reporting::Output::InRange]
|
45
|
+
# Constrained values: must be within the given range.
|
46
|
+
def in_range(range)
|
47
|
+
raise ArgumentError, 'need a range' unless range.is_a?(Range)
|
48
|
+
|
49
|
+
InRange.new(self, range)
|
50
|
+
end
|
51
|
+
|
43
52
|
def list
|
44
53
|
List.new(self)
|
45
54
|
end
|
@@ -20,6 +20,8 @@ module SoberSwag
|
|
20
20
|
#
|
21
21
|
# You can access other methods from this method.
|
22
22
|
def field(name, output, description: nil, &extract)
|
23
|
+
raise ArgumentError, "output of field #{name} is not a SoberSwag::Reporting::Output::Interface" unless output.is_a?(Interface)
|
24
|
+
|
23
25
|
define_field(name, extract)
|
24
26
|
|
25
27
|
object_fields[name] = Object::Property.new(
|
@@ -158,22 +160,20 @@ module SoberSwag
|
|
158
160
|
# @param name [Symbol] name of this view.
|
159
161
|
# @yieldself [self] a block in which you can add more fields to the view.
|
160
162
|
# @return [Class]
|
161
|
-
def define_view(name, &block)
|
162
|
-
|
163
|
-
|
164
|
-
classy_name = name.to_s.classify
|
163
|
+
def define_view(name, &block)
|
164
|
+
define_view_with_parent(name, self, block)
|
165
|
+
end
|
165
166
|
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
end
|
167
|
+
##
|
168
|
+
# Defines a view for this object, which "inherits" another view.
|
169
|
+
# @see #define_view for how views behave.
|
170
|
+
#
|
171
|
+
# @param name [Symbol] name of this view
|
172
|
+
# @param inherits [Symbol] name of the view this view inherits
|
173
|
+
# @yieldself [self] a block in which you can add more fields to this view
|
174
|
+
# @return [Class]
|
175
|
+
def define_inherited_view(name, inherits:, &block)
|
176
|
+
define_view_with_parent(name, view_class(inherits), block)
|
177
177
|
end
|
178
178
|
|
179
179
|
##
|
@@ -199,6 +199,16 @@ module SoberSwag
|
|
199
199
|
view_map.fetch(name).view(:base)
|
200
200
|
end
|
201
201
|
|
202
|
+
##
|
203
|
+
# Equivalent to .view, but returns the raw view class.
|
204
|
+
#
|
205
|
+
# @return [Class]
|
206
|
+
def view_class(name)
|
207
|
+
return self if name == :base
|
208
|
+
|
209
|
+
view_map.fetch(name)
|
210
|
+
end
|
211
|
+
|
202
212
|
attr_accessor :parent_struct
|
203
213
|
|
204
214
|
##
|
@@ -226,6 +236,21 @@ module SoberSwag
|
|
226
236
|
|
227
237
|
private
|
228
238
|
|
239
|
+
def define_view_with_parent(name, parent, block)
|
240
|
+
raise ArgumentError, "duplicate view #{name}" if name == :base || views.include?(name)
|
241
|
+
|
242
|
+
classy_name = name.to_s.classify
|
243
|
+
us = self # grab this so its identifier doesn't get nested under whatever parent it inherits from, since its our view
|
244
|
+
|
245
|
+
Class.new(parent).tap do |c|
|
246
|
+
c.instance_eval(&block)
|
247
|
+
c.define_singleton_method(:define_view) { |*| raise ArgumentError, 'no nesting views' }
|
248
|
+
c.define_singleton_method(:identifier) { [us.identifier, classy_name.gsub('::', '.')].join('.') }
|
249
|
+
const_set(classy_name, c)
|
250
|
+
view_map[name] = c
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
229
254
|
def identified_view_map
|
230
255
|
view_map.transform_values(&:identified_without_base).merge(base: inherited_output)
|
231
256
|
end
|
@@ -10,6 +10,7 @@ module SoberSwag
|
|
10
10
|
autoload(:Defer, 'sober_swag/reporting/output/defer')
|
11
11
|
autoload(:Described, 'sober_swag/reporting/output/described')
|
12
12
|
autoload(:Dictionary, 'sober_swag/reporting/output/dictionary')
|
13
|
+
autoload(:InRange, 'sober_swag/reporting/output/in_range')
|
13
14
|
autoload(:Interface, 'sober_swag/reporting/output/interface')
|
14
15
|
autoload(:List, 'sober_swag/reporting/output/list')
|
15
16
|
autoload(:MergeObjects, 'sober_swag/reporting/output/merge_objects')
|
data/lib/sober_swag/version.rb
CHANGED
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.
|
4
|
+
version: 0.24.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: 2022-
|
11
|
+
date: 2022-05-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -326,6 +326,7 @@ files:
|
|
326
326
|
- lib/sober_swag/reporting/output/described.rb
|
327
327
|
- lib/sober_swag/reporting/output/dictionary.rb
|
328
328
|
- lib/sober_swag/reporting/output/enum.rb
|
329
|
+
- lib/sober_swag/reporting/output/in_range.rb
|
329
330
|
- lib/sober_swag/reporting/output/interface.rb
|
330
331
|
- lib/sober_swag/reporting/output/list.rb
|
331
332
|
- lib/sober_swag/reporting/output/merge_objects.rb
|