Class: SoberSwag::Reporting::Input::MergeObjects
- Defined in:
- lib/sober_swag/reporting/input/merge_objects.rb
Overview
Merge two object types together, in an allof stype relationship
Instance Attribute Summary collapse
-
#child ⇒ Interface
readonly
Child type.
-
#parent ⇒ Interface
readonly
Parent type.
Instance Method Summary collapse
- #call(value) ⇒ Object
-
#initialize(parent, child) ⇒ MergeObjects
constructor
A new instance of MergeObjects.
-
#merge_results(par, chi) ⇒ Object
private
rubocop:disable Metrics/MethodLength.
- #swagger_path_schema ⇒ Object
- #swagger_query_schema ⇒ Object
- #swagger_schema ⇒ Object
Methods included from Interface
#add_schema_key, #call!, #described, #enum, #format, #in_range, #list, #mapped, #modify_schema, #multiple_of, #optional, #or, #referenced, #|
Constructor Details
#initialize(parent, child) ⇒ MergeObjects
Returns a new instance of MergeObjects.
7 8 9 10 |
# File 'lib/sober_swag/reporting/input/merge_objects.rb', line 7 def initialize(parent, child) @parent = parent @child = child end |
Instance Attribute Details
#child ⇒ Interface (readonly)
Returns child type.
18 19 20 |
# File 'lib/sober_swag/reporting/input/merge_objects.rb', line 18 def child @child end |
#parent ⇒ Interface (readonly)
Returns parent type.
14 15 16 |
# File 'lib/sober_swag/reporting/input/merge_objects.rb', line 14 def parent @parent end |
Instance Method Details
#call(value) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/sober_swag/reporting/input/merge_objects.rb', line 20 def call(value) parent_attrs = parent.call(value) return parent_attrs if parent_attrs.is_a?(Report::Value) # otherwise, object type, so we want to get a full error report child_attrs = child.call(value) return child_attrs if child_attrs.is_a?(Report::Value) merge_results(parent_attrs, child_attrs) end |
#merge_results(par, chi) ⇒ Object (private)
rubocop:disable Metrics/MethodLength
56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/sober_swag/reporting/input/merge_objects.rb', line 56 def merge_results(par, chi) # rubocop:disable Metrics/MethodLength if par.is_a?(Report::Base) if chi.is_a?(Report::Base) Report::MergedObject.new(par, chi) else par end elsif chi.is_a?(Report::Base) chi else par.to_h.merge(chi.to_h) end end |
#swagger_path_schema ⇒ Object
46 47 48 |
# File 'lib/sober_swag/reporting/input/merge_objects.rb', line 46 def swagger_path_schema parent.swagger_path_schema + child.swagger_path_schema end |
#swagger_query_schema ⇒ Object
50 51 52 |
# File 'lib/sober_swag/reporting/input/merge_objects.rb', line 50 def swagger_query_schema parent.swagger_query_schema + child.swagger_query_schema end |
#swagger_schema ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/sober_swag/reporting/input/merge_objects.rb', line 34 def swagger_schema parent_schema, parent_found = parent.swagger_schema child_schema, child_found = child.swagger_schema [ { allOf: (parent_schema[:allOf] || [parent_schema]) + (child_schema[:allOf] || [child_schema]) }, parent_found.merge(child_found) ] end |