Class: GrapeOAS::Introspectors::EntityIntrospectorSupport::InheritanceBuilder
- Inherits:
-
Object
- Object
- GrapeOAS::Introspectors::EntityIntrospectorSupport::InheritanceBuilder
- Defined in:
- lib/grape_oas/introspectors/entity_introspector_support/inheritance_builder.rb
Overview
Handles entity inheritance and builds allOf schemas for parent-child entity relationships.
Class Method Summary collapse
-
.find_parent_entity(entity_class) ⇒ Class?
Finds the parent entity class if one exists.
-
.inherits_with_discriminator?(entity_class) ⇒ Boolean
Checks if an entity inherits from a parent that uses discriminator.
Instance Method Summary collapse
-
#build_inherited_schema(parent_entity) ⇒ ApiModel::Schema
Builds an inherited schema using allOf composition.
-
#initialize(entity_class, stack:, registry:) ⇒ InheritanceBuilder
constructor
A new instance of InheritanceBuilder.
Constructor Details
#initialize(entity_class, stack:, registry:) ⇒ InheritanceBuilder
Returns a new instance of InheritanceBuilder.
8 9 10 11 12 |
# File 'lib/grape_oas/introspectors/entity_introspector_support/inheritance_builder.rb', line 8 def initialize(entity_class, stack:, registry:) @entity_class = entity_class @stack = stack @registry = registry end |
Class Method Details
.find_parent_entity(entity_class) ⇒ Class?
Finds the parent entity class if one exists.
18 19 20 |
# File 'lib/grape_oas/introspectors/entity_introspector_support/inheritance_builder.rb', line 18 def self.find_parent_entity(entity_class) EntityIntrospectorSupport.find_parent_entity(entity_class) end |
.inherits_with_discriminator?(entity_class) ⇒ Boolean
Checks if an entity inherits from a parent that uses discriminator.
26 27 28 29 |
# File 'lib/grape_oas/introspectors/entity_introspector_support/inheritance_builder.rb', line 26 def self.inherits_with_discriminator?(entity_class) parent = find_parent_entity(entity_class) parent && DiscriminatorHandler.new(parent).discriminator? end |
Instance Method Details
#build_inherited_schema(parent_entity) ⇒ ApiModel::Schema
Builds an inherited schema using allOf composition.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/grape_oas/introspectors/entity_introspector_support/inheritance_builder.rb', line 35 def build_inherited_schema(parent_entity) # First, ensure parent schema is built parent_schema = GrapeOAS.introspectors.build_schema(parent_entity, stack: @stack, registry: @registry) # Build child-specific properties (excluding inherited ones) child_schema = build_child_only_schema(parent_entity) # Create allOf schema with ref to parent + child properties schema = ApiModel::Schema.new( canonical_name: EntityIntrospectorSupport.resolve_canonical_name(@entity_class), all_of: [parent_schema, child_schema], ) @registry[@entity_class] = schema schema end |