Class: GrapeOAS::TypeResolvers::DryTypeResolver

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

Overview

Resolves standalone Dry::Types (not wrapped in arrays).

Handles types like “MyApp::Types::UUID” which Grape stringifies. Attempts to resolve the string back to the actual Dry::Type class and extract rich metadata:

  • Primitive type (String, Integer, etc.)

  • Format from meta or inferred from name

  • Constraints (if applicable)

Examples:

# Input: "MyApp::Types::UUID" (string from Grape)
# Resolution: Object.const_get -> Dry::Type with primitive=String
# Output: Schema(type: "string", format: "uuid")

Class Method Summary collapse

Methods included from Base

build_schema, handles?, infer_format_from_name, primitive_to_schema_type, resolve_class

Class Method Details

.build_schema(type) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/grape_oas/type_resolvers/dry_type_resolver.rb', line 35

def build_schema(type)
  dry_type = if dry_type?(type)
               type
             else
               resolve_class(type)
             end

  return nil unless dry_type?(dry_type)

  build_dry_type_schema(dry_type)
end

.handles?(type) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
29
30
31
32
33
# File 'lib/grape_oas/type_resolvers/dry_type_resolver.rb', line 23

def handles?(type)
  # Handle actual Dry::Type objects
  return true if dry_type?(type)

  # Handle strings that resolve to Dry::Types
  return false unless type.is_a?(String)
  return false if type.match?(/\A\[.+\]\z/) # Skip arrays, handled by ArrayResolver

  resolved = resolve_class(type)
  dry_type?(resolved)
end