Module: GrapeOAS::Introspectors::EntityIntrospectorSupport

Defined in:
lib/grape_oas/introspectors/entity_introspector_support.rb,
lib/grape_oas/introspectors/entity_introspector_support/cycle_tracker.rb,
lib/grape_oas/introspectors/entity_introspector_support/nesting_merger.rb,
lib/grape_oas/introspectors/entity_introspector_support/exposure_processor.rb,
lib/grape_oas/introspectors/entity_introspector_support/property_extractor.rb,
lib/grape_oas/introspectors/entity_introspector_support/inheritance_builder.rb,
lib/grape_oas/introspectors/entity_introspector_support/type_schema_resolver.rb,
lib/grape_oas/introspectors/entity_introspector_support/discriminator_handler.rb

Overview

Shared helpers used by multiple classes within EntityIntrospectorSupport. These are module-level methods to avoid copy-pasting the same logic across ExposureProcessor, DiscriminatorHandler, and InheritanceBuilder.

Defined Under Namespace

Modules: NestingMerger Classes: CycleTracker, DiscriminatorHandler, ExposureProcessor, InheritanceBuilder, PropertyExtractor, TypeSchemaResolver

Class Method Summary collapse

Class Method Details

.exposures(entity_class) ⇒ Object

Returns the raw exposure list for an entity class. Reads root_exposures via internal Grape::Entity ivars, which is unavoidable given Grape does not expose a stable public API for this.



12
13
14
15
16
17
18
19
20
# File 'lib/grape_oas/introspectors/entity_introspector_support.rb', line 12

def self.exposures(entity_class)
  return [] unless entity_class.respond_to?(:root_exposures)

  root = entity_class.root_exposures
  list = root.instance_variable_get(:@exposures) || []
  Array(list)
rescue NoMethodError
  []
end

.find_parent_entity(entity_class) ⇒ Object

Finds the parent entity class if one exists in the Grape::Entity hierarchy.



47
48
49
50
51
52
53
54
# File 'lib/grape_oas/introspectors/entity_introspector_support.rb', line 47

def self.find_parent_entity(entity_class)
  return nil unless defined?(Grape::Entity)

  parent = entity_class.superclass
  return nil unless parent && parent < Grape::Entity && parent != Grape::Entity

  parent
end

.resolve_canonical_name(entity_class) ⇒ Object

Resolves the canonical name for an entity class, preferring entity_name when defined on the class itself (via def self. or extend) and non-blank, falling back to the Ruby class name. Inherited entity_name is ignored to avoid collisions between parent and child schemas.



26
27
28
29
30
31
32
33
# File 'lib/grape_oas/introspectors/entity_introspector_support.rb', line 26

def self.resolve_canonical_name(entity_class)
  if defines_own_entity_name?(entity_class)
    name = entity_class.entity_name
    name.is_a?(String) && !name.strip.empty? ? name : entity_class.name
  else
    entity_class.name
  end
end