Module: GrapeOAS::Introspectors::EntityIntrospectorSupport::NestingMerger
- Defined in:
- lib/grape_oas/introspectors/entity_introspector_support/nesting_merger.rb
Overview
Merges duplicate-key nesting exposure branches into a single schema, preserving properties from all branches.
Constant Summary collapse
- MAX_MERGE_DEPTH =
Grape nesting rarely exceeds 3-4 levels
10
Class Method Summary collapse
-
.merge(accum, current, depth = 0) ⇒ ApiModel::Schema
Merged schema.
Class Method Details
.merge(accum, current, depth = 0) ⇒ ApiModel::Schema
Returns merged schema.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/grape_oas/introspectors/entity_introspector_support/nesting_merger.rb', line 16 def merge(accum, current, depth = 0) return current unless accum return accum if current.equal?(accum) # Unwrap array schemas to merge their items, then re-wrap if array_of_objects?(accum) && array_of_objects?(current) merged_items = merge(accum.items, current.items, depth + 1) merged_array = ApiModel::Schema.new(type: Constants::SchemaTypes::ARRAY, items: merged_items) (merged_array, accum) (merged_array, current) return merged_array end return accum unless current&.type == Constants::SchemaTypes::OBJECT return current unless accum.type == Constants::SchemaTypes::OBJECT merge_object_schemas(accum, current, depth) end |