Class: GrapeOAS::TypeResolvers::ArrayResolver
- Inherits:
-
Object
- Object
- GrapeOAS::TypeResolvers::ArrayResolver
- Extended by:
- Base
- Defined in:
- lib/grape_oas/type_resolvers/array_resolver.rb
Overview
Resolves array types like “[String]”, “[Integer]”, “[MyApp::Types::UUID]”.
Grape converts ‘type: [SomeClass]` to the string “[SomeClass]” for documentation. This resolver:
-
Detects the array pattern via regex
-
Extracts the inner type name
-
Attempts to resolve it back to the actual class via Object.const_get
-
If resolved, extracts rich metadata (Dry::Types format, primitive, etc.)
-
Falls back to string-based inference if class not available
Constant Summary collapse
- TYPED_ARRAY_PATTERN =
Constants::TypePatterns::TYPED_ARRAY
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
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/grape_oas/type_resolvers/array_resolver.rb', line 32 def build_schema(type) inner_type_name = extract_inner_type(type) return nil unless inner_type_name # Try to resolve the string to an actual class resolved_class = resolve_class(inner_type_name) items_schema = if resolved_class build_schema_from_class(resolved_class) else build_schema_from_string(inner_type_name) end ApiModel::Schema.new( type: Constants::SchemaTypes::ARRAY, items: items_schema, ) end |
.handles?(type) ⇒ Boolean
26 27 28 29 30 |
# File 'lib/grape_oas/type_resolvers/array_resolver.rb', line 26 def handles?(type) return false unless type.is_a?(String) type.match?(TYPED_ARRAY_PATTERN) end |