Class: GrapeOAS::Introspectors::DryIntrospector
- Inherits:
-
Object
- Object
- GrapeOAS::Introspectors::DryIntrospector
- 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
-
.build(contract, stack: [], registry: {}) ⇒ Object
deprecated
Deprecated.
Use build_schema instead
-
.build_schema(subject, stack: [], registry: {}) ⇒ ApiModel::Schema?
Builds a schema from a Dry contract or schema.
-
.handles?(subject) ⇒ Boolean
Checks if the subject is a Dry contract or schema.
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(contract, stack: [], registry: {}) ⇒ DryIntrospector
constructor
A new instance of DryIntrospector.
Methods included from Base
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.
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.
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
#build ⇒ Object
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 |