Class: GrapeOAS::Introspectors::DryIntrospector

Inherits:
Object
  • Object
show all
Extended by:
Base
Defined in:
lib/grape_oas/introspectors/dry_introspector.rb

Overview

Introspector for Dry::Validation contracts and Dry::Schema. Extracts an ApiModel schema from contract definitions.

Constant Summary collapse

ConstraintSet =

Re-export ConstraintSet for external use

DryIntrospectorSupport::ConstraintExtractor::ConstraintSet

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Base

build_schema, handles?

Constructor Details

#initialize(contract, stack: [], registry: {}) ⇒ DryIntrospector

Returns a new instance of DryIntrospector.



49
50
51
52
53
# File 'lib/grape_oas/introspectors/dry_introspector.rb', line 49

def initialize(contract, stack: [], registry: {})
  @contract = contract
  @stack = stack
  @registry = registry
end

Class Method Details

.build(contract, stack: [], registry: {}) ⇒ Object

Deprecated.

Use build_schema instead

Legacy class method for backward compatibility.



40
41
42
# File 'lib/grape_oas/introspectors/dry_introspector.rb', line 40

def self.build(contract, stack: [], registry: {})
  build_schema(contract, stack: stack, registry: registry)
end

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

Builds a schema from a Dry contract or schema.

Parameters:

  • subject (Object)

    Contract class, instance, or schema

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

    Recursion stack for cycle detection

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

    Schema registry for caching

Returns:



34
35
36
# File 'lib/grape_oas/introspectors/dry_introspector.rb', line 34

def self.build_schema(subject, stack: [], registry: {})
  new(subject, stack: stack, registry: registry).build
end

.handles?(subject) ⇒ Boolean

Checks if the subject is a Dry contract or schema.

Parameters:

  • subject (Object)

    The object to check

Returns:

  • (Boolean)

    true if subject is a Dry contract/schema



17
18
19
20
21
22
23
24
25
26
# File 'lib/grape_oas/introspectors/dry_introspector.rb', line 17

def self.handles?(subject)
  # Check for Dry::Validation::Contract class
  return true if dry_contract_class?(subject)

  # Check for schema with types (instantiated contract or schema result)
  return true if subject.respond_to?(:schema) && subject.schema.respond_to?(:types)

  # Check for direct schema object
  subject.respond_to?(:types)
end

Instance Method Details

#buildObject



55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/grape_oas/introspectors/dry_introspector.rb', line 55

def build
  return unless contract_resolver.contract_schema.respond_to?(:types)

  # Check registry cache first (like EntityIntrospector does)
  cached = cached_schema
  return cached if cached

  parent_contract = inheritance_handler.find_parent_contract
  return inheritance_handler.build_inherited_schema(parent_contract, type_schema_builder) if parent_contract

  build_flat_schema
end