sober_swag 0.21.0 → 0.22.0
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 +4 -4
- data/.rubocop.yml +1 -0
- data/CHANGELOG.md +5 -0
- data/bin/console +30 -10
- data/docs/reporting.md +190 -0
- data/example/Gemfile +2 -2
- data/example/Gemfile.lock +92 -101
- data/example/app/controllers/application_controller.rb +4 -0
- data/example/app/controllers/people_controller.rb +44 -28
- data/example/app/output_objects/identified_output.rb +7 -0
- data/example/app/output_objects/person_output_object.rb +37 -11
- data/example/app/output_objects/post_output_object.rb +0 -4
- data/example/app/output_objects/reporting_post_output.rb +18 -0
- data/example/bin/rspec +29 -0
- data/example/spec/requests/people/create_spec.rb +3 -2
- data/example/spec/requests/people/index_spec.rb +1 -1
- data/lib/sober_swag/compiler/path.rb +3 -1
- data/lib/sober_swag/compiler.rb +58 -12
- data/lib/sober_swag/controller/route.rb +44 -8
- data/lib/sober_swag/controller.rb +18 -5
- data/lib/sober_swag/reporting/compiler.rb +39 -0
- data/lib/sober_swag/reporting/input/base.rb +11 -0
- data/lib/sober_swag/reporting/input/bool.rb +19 -0
- data/lib/sober_swag/reporting/input/converting/bool.rb +24 -0
- data/lib/sober_swag/reporting/input/converting/date.rb +30 -0
- data/lib/sober_swag/reporting/input/converting/date_time.rb +28 -0
- data/lib/sober_swag/reporting/input/converting/decimal.rb +24 -0
- data/lib/sober_swag/reporting/input/converting/integer.rb +19 -0
- data/lib/sober_swag/reporting/input/converting.rb +16 -0
- data/lib/sober_swag/reporting/input/defer.rb +29 -0
- data/lib/sober_swag/reporting/input/described.rb +38 -0
- data/lib/sober_swag/reporting/input/dictionary.rb +37 -0
- data/lib/sober_swag/reporting/input/either.rb +51 -0
- data/lib/sober_swag/reporting/input/enum.rb +44 -0
- data/lib/sober_swag/reporting/input/format.rb +39 -0
- data/lib/sober_swag/reporting/input/interface.rb +87 -0
- data/lib/sober_swag/reporting/input/list.rb +44 -0
- data/lib/sober_swag/reporting/input/mapped.rb +36 -0
- data/lib/sober_swag/reporting/input/merge_objects.rb +72 -0
- data/lib/sober_swag/reporting/input/null.rb +34 -0
- data/lib/sober_swag/reporting/input/number.rb +19 -0
- data/lib/sober_swag/reporting/input/object/property.rb +53 -0
- data/lib/sober_swag/reporting/input/object.rb +100 -0
- data/lib/sober_swag/reporting/input/pattern.rb +46 -0
- data/lib/sober_swag/reporting/input/referenced.rb +38 -0
- data/lib/sober_swag/reporting/input/struct.rb +271 -0
- data/lib/sober_swag/reporting/input/text.rb +42 -0
- data/lib/sober_swag/reporting/input.rb +54 -0
- data/lib/sober_swag/reporting/invalid_schema_error.rb +21 -0
- data/lib/sober_swag/reporting/output/base.rb +25 -0
- data/lib/sober_swag/reporting/output/bool.rb +25 -0
- data/lib/sober_swag/reporting/output/defer.rb +69 -0
- data/lib/sober_swag/reporting/output/described.rb +42 -0
- data/lib/sober_swag/reporting/output/dictionary.rb +46 -0
- data/lib/sober_swag/reporting/output/interface.rb +83 -0
- data/lib/sober_swag/reporting/output/list.rb +54 -0
- data/lib/sober_swag/reporting/output/merge_objects.rb +97 -0
- data/lib/sober_swag/reporting/output/null.rb +25 -0
- data/lib/sober_swag/reporting/output/number.rb +25 -0
- data/lib/sober_swag/reporting/output/object/property.rb +45 -0
- data/lib/sober_swag/reporting/output/object.rb +54 -0
- data/lib/sober_swag/reporting/output/partitioned.rb +77 -0
- data/lib/sober_swag/reporting/output/pattern.rb +50 -0
- data/lib/sober_swag/reporting/output/referenced.rb +42 -0
- data/lib/sober_swag/reporting/output/struct.rb +262 -0
- data/lib/sober_swag/reporting/output/text.rb +25 -0
- data/lib/sober_swag/reporting/output/via_map.rb +67 -0
- data/lib/sober_swag/reporting/output/viewed.rb +72 -0
- data/lib/sober_swag/reporting/output.rb +54 -0
- data/lib/sober_swag/reporting/report/base.rb +57 -0
- data/lib/sober_swag/reporting/report/either.rb +36 -0
- data/lib/sober_swag/reporting/report/error.rb +15 -0
- data/lib/sober_swag/reporting/report/list.rb +28 -0
- data/lib/sober_swag/reporting/report/merged_object.rb +25 -0
- data/lib/sober_swag/reporting/report/object.rb +29 -0
- data/lib/sober_swag/reporting/report/output.rb +14 -0
- data/lib/sober_swag/reporting/report/value.rb +28 -0
- data/lib/sober_swag/reporting/report.rb +16 -0
- data/lib/sober_swag/reporting.rb +11 -0
- data/lib/sober_swag/version.rb +1 -1
- data/lib/sober_swag.rb +1 -0
- metadata +65 -2
@@ -0,0 +1,29 @@
|
|
1
|
+
module SoberSwag
|
2
|
+
module Reporting
|
3
|
+
module Report
|
4
|
+
##
|
5
|
+
# Report on problems with an object.
|
6
|
+
class Object < Base
|
7
|
+
##
|
8
|
+
# @param problems [Hash<Symbol, Report::Base>] the problems with each value.
|
9
|
+
def initialize(problems)
|
10
|
+
@problems = problems
|
11
|
+
end
|
12
|
+
|
13
|
+
##
|
14
|
+
# @return [Hash] the hash being reported on
|
15
|
+
attr_reader :problems
|
16
|
+
|
17
|
+
def each_error
|
18
|
+
return enum_for(:each_error) unless block_given?
|
19
|
+
|
20
|
+
problems.each do |k, v|
|
21
|
+
v.each_error do |nested, err|
|
22
|
+
yield [".#{k}", nested].reject(&:nil?).join(''), err
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module SoberSwag
|
2
|
+
module Reporting
|
3
|
+
module Report
|
4
|
+
##
|
5
|
+
# Output suitable to serialize an instance of {SoberSwag::Reporting::Report::Base} to
|
6
|
+
# a nice key-value thing.
|
7
|
+
Output = SoberSwag::Reporting::Output::Dictionary.of(
|
8
|
+
SoberSwag::Reporting::Output::List.new(
|
9
|
+
SoberSwag::Reporting::Output.text
|
10
|
+
)
|
11
|
+
).via_map(&:path_hash)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module SoberSwag
|
2
|
+
module Reporting
|
3
|
+
module Report
|
4
|
+
##
|
5
|
+
# Report for a single value.
|
6
|
+
# Basically a wrapper around an array of strings.
|
7
|
+
class Value < Base
|
8
|
+
##
|
9
|
+
# @param problems [Array<String>] problems with it
|
10
|
+
def initialize(problems)
|
11
|
+
@problems = problems
|
12
|
+
end
|
13
|
+
|
14
|
+
##
|
15
|
+
# @return [Array<String>] the problems the value had
|
16
|
+
attr_reader :problems
|
17
|
+
|
18
|
+
def each_error
|
19
|
+
return enum_for(:each_error) unless block_given?
|
20
|
+
|
21
|
+
problems.each do |problem|
|
22
|
+
yield nil, problem
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module SoberSwag
|
2
|
+
module Reporting
|
3
|
+
##
|
4
|
+
# Namespace modules for the various "reporters," or things that provide error handling.
|
5
|
+
module Report
|
6
|
+
autoload :Base, 'sober_swag/reporting/report/base'
|
7
|
+
autoload :Either, 'sober_swag/reporting/report/either'
|
8
|
+
autoload :Error, 'sober_swag/reporting/report/error'
|
9
|
+
autoload :Object, 'sober_swag/reporting/report/object'
|
10
|
+
autoload :Output, 'sober_swag/reporting/report/output'
|
11
|
+
autoload :MergedObject, 'sober_swag/reporting/report/merged_object'
|
12
|
+
autoload :Value, 'sober_swag/reporting/report/value'
|
13
|
+
autoload :List, 'sober_swag/reporting/report/list'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module SoberSwag
|
2
|
+
##
|
3
|
+
# A new module for parsers with better error reporting.
|
4
|
+
module Reporting
|
5
|
+
autoload :Input, 'sober_swag/reporting/input'
|
6
|
+
autoload :Report, 'sober_swag/reporting/report'
|
7
|
+
autoload :Output, 'sober_swag/reporting/output'
|
8
|
+
autoload :Compiler, 'sober_swag/reporting/compiler'
|
9
|
+
autoload :InvalidSchemaError, 'sober_swag/reporting/invalid_schema_error'
|
10
|
+
end
|
11
|
+
end
|
data/lib/sober_swag/version.rb
CHANGED
data/lib/sober_swag.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.22.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: 2021-
|
11
|
+
date: 2021-12-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -193,6 +193,7 @@ files:
|
|
193
193
|
- bin/console
|
194
194
|
- bin/rspec
|
195
195
|
- bin/setup
|
196
|
+
- docs/reporting.md
|
196
197
|
- docs/serializers.md
|
197
198
|
- example/.gitignore
|
198
199
|
- example/.rspec
|
@@ -210,12 +211,15 @@ files:
|
|
210
211
|
- example/app/models/concerns/.keep
|
211
212
|
- example/app/models/person.rb
|
212
213
|
- example/app/models/post.rb
|
214
|
+
- example/app/output_objects/identified_output.rb
|
213
215
|
- example/app/output_objects/person_errors_output_object.rb
|
214
216
|
- example/app/output_objects/person_output_object.rb
|
215
217
|
- example/app/output_objects/post_output_object.rb
|
218
|
+
- example/app/output_objects/reporting_post_output.rb
|
216
219
|
- example/bin/bundle
|
217
220
|
- example/bin/rails
|
218
221
|
- example/bin/rake
|
222
|
+
- example/bin/rspec
|
219
223
|
- example/bin/setup
|
220
224
|
- example/bin/spring
|
221
225
|
- example/config.ru
|
@@ -283,6 +287,65 @@ files:
|
|
283
287
|
- lib/sober_swag/output_object/field_syntax.rb
|
284
288
|
- lib/sober_swag/output_object/view.rb
|
285
289
|
- lib/sober_swag/parser.rb
|
290
|
+
- lib/sober_swag/reporting.rb
|
291
|
+
- lib/sober_swag/reporting/compiler.rb
|
292
|
+
- lib/sober_swag/reporting/input.rb
|
293
|
+
- lib/sober_swag/reporting/input/base.rb
|
294
|
+
- lib/sober_swag/reporting/input/bool.rb
|
295
|
+
- lib/sober_swag/reporting/input/converting.rb
|
296
|
+
- lib/sober_swag/reporting/input/converting/bool.rb
|
297
|
+
- lib/sober_swag/reporting/input/converting/date.rb
|
298
|
+
- lib/sober_swag/reporting/input/converting/date_time.rb
|
299
|
+
- lib/sober_swag/reporting/input/converting/decimal.rb
|
300
|
+
- lib/sober_swag/reporting/input/converting/integer.rb
|
301
|
+
- lib/sober_swag/reporting/input/defer.rb
|
302
|
+
- lib/sober_swag/reporting/input/described.rb
|
303
|
+
- lib/sober_swag/reporting/input/dictionary.rb
|
304
|
+
- lib/sober_swag/reporting/input/either.rb
|
305
|
+
- lib/sober_swag/reporting/input/enum.rb
|
306
|
+
- lib/sober_swag/reporting/input/format.rb
|
307
|
+
- lib/sober_swag/reporting/input/interface.rb
|
308
|
+
- lib/sober_swag/reporting/input/list.rb
|
309
|
+
- lib/sober_swag/reporting/input/mapped.rb
|
310
|
+
- lib/sober_swag/reporting/input/merge_objects.rb
|
311
|
+
- lib/sober_swag/reporting/input/null.rb
|
312
|
+
- lib/sober_swag/reporting/input/number.rb
|
313
|
+
- lib/sober_swag/reporting/input/object.rb
|
314
|
+
- lib/sober_swag/reporting/input/object/property.rb
|
315
|
+
- lib/sober_swag/reporting/input/pattern.rb
|
316
|
+
- lib/sober_swag/reporting/input/referenced.rb
|
317
|
+
- lib/sober_swag/reporting/input/struct.rb
|
318
|
+
- lib/sober_swag/reporting/input/text.rb
|
319
|
+
- lib/sober_swag/reporting/invalid_schema_error.rb
|
320
|
+
- lib/sober_swag/reporting/output.rb
|
321
|
+
- lib/sober_swag/reporting/output/base.rb
|
322
|
+
- lib/sober_swag/reporting/output/bool.rb
|
323
|
+
- lib/sober_swag/reporting/output/defer.rb
|
324
|
+
- lib/sober_swag/reporting/output/described.rb
|
325
|
+
- lib/sober_swag/reporting/output/dictionary.rb
|
326
|
+
- lib/sober_swag/reporting/output/interface.rb
|
327
|
+
- lib/sober_swag/reporting/output/list.rb
|
328
|
+
- lib/sober_swag/reporting/output/merge_objects.rb
|
329
|
+
- lib/sober_swag/reporting/output/null.rb
|
330
|
+
- lib/sober_swag/reporting/output/number.rb
|
331
|
+
- lib/sober_swag/reporting/output/object.rb
|
332
|
+
- lib/sober_swag/reporting/output/object/property.rb
|
333
|
+
- lib/sober_swag/reporting/output/partitioned.rb
|
334
|
+
- lib/sober_swag/reporting/output/pattern.rb
|
335
|
+
- lib/sober_swag/reporting/output/referenced.rb
|
336
|
+
- lib/sober_swag/reporting/output/struct.rb
|
337
|
+
- lib/sober_swag/reporting/output/text.rb
|
338
|
+
- lib/sober_swag/reporting/output/via_map.rb
|
339
|
+
- lib/sober_swag/reporting/output/viewed.rb
|
340
|
+
- lib/sober_swag/reporting/report.rb
|
341
|
+
- lib/sober_swag/reporting/report/base.rb
|
342
|
+
- lib/sober_swag/reporting/report/either.rb
|
343
|
+
- lib/sober_swag/reporting/report/error.rb
|
344
|
+
- lib/sober_swag/reporting/report/list.rb
|
345
|
+
- lib/sober_swag/reporting/report/merged_object.rb
|
346
|
+
- lib/sober_swag/reporting/report/object.rb
|
347
|
+
- lib/sober_swag/reporting/report/output.rb
|
348
|
+
- lib/sober_swag/reporting/report/value.rb
|
286
349
|
- lib/sober_swag/serializer.rb
|
287
350
|
- lib/sober_swag/serializer/array.rb
|
288
351
|
- lib/sober_swag/serializer/base.rb
|