Module: GrapeOAS::Introspectors::Base

Included in:
DryIntrospector, EntityIntrospector
Defined in:
lib/grape_oas/introspectors/base.rb

Overview

Base module that defines the interface for all introspectors. Any introspector (built-in or third-party) must implement these class methods.

Examples:

Implementing a custom introspector

class MyIntrospector
  extend GrapeOAS::Introspectors::Base

  def self.handles?(subject)
    subject.is_a?(Class) && subject < MyResponseModel
  end

  def self.build_schema(subject, stack: [], registry: {})
    # Build and return an ApiModel::Schema
  end
end

# Register the introspector
GrapeOAS.introspectors.register(MyIntrospector)

Instance Method Summary collapse

Instance Method Details

#build_schema(subject, stack: [], registry: {}) ⇒ ApiModel::Schema?

Builds a schema from the given subject.

Parameters:

  • subject (Object)

    The object to introspect

  • stack (Array) (defaults to: [])

    Recursion stack for cycle detection

  • registry (Hash) (defaults to: {})

    Schema registry for caching built schemas

Returns:

Raises:

  • (NotImplementedError)


39
40
41
# File 'lib/grape_oas/introspectors/base.rb', line 39

def build_schema(subject, stack: [], registry: {})
  raise NotImplementedError, "#{self} must implement .build_schema(subject, stack:, registry:)"
end

#handles?(subject) ⇒ Boolean

Checks if this introspector can handle the given subject.

Parameters:

  • subject (Object)

    The object to introspect (e.g., entity class, contract)

Returns:

  • (Boolean)

    true if this introspector can handle the subject

Raises:

  • (NotImplementedError)


29
30
31
# File 'lib/grape_oas/introspectors/base.rb', line 29

def handles?(subject)
  raise NotImplementedError, "#{self} must implement .handles?(subject)"
end