Class: Generator::TypeResolver
- Inherits:
-
Object
- Object
- Generator::TypeResolver
- Defined in:
- lib/generator/resolvers/type_resolver.rb
Overview
Resolves OpenAPI types to Ruby types for code generation
Instance Attribute Summary collapse
-
#api_name ⇒ Object
readonly
Returns the value of attribute api_name.
-
#specification ⇒ Object
readonly
Returns the value of attribute specification.
-
#type_name ⇒ Object
readonly
Returns the value of attribute type_name.
Instance Method Summary collapse
- #generated_type?(name) ⇒ Boolean
-
#initialize(type_name, specification, api_name = nil) ⇒ TypeResolver
constructor
A new instance of TypeResolver.
- #resolve(prop_def, for_comment: false, for_rbs: false, prop_name: nil) ⇒ Object
Constructor Details
#initialize(type_name, specification, api_name = nil) ⇒ TypeResolver
Returns a new instance of TypeResolver.
12 13 14 15 16 |
# File 'lib/generator/resolvers/type_resolver.rb', line 12 def initialize(type_name, specification, api_name = nil) @type_name = type_name @specification = specification @api_name = api_name end |
Instance Attribute Details
#api_name ⇒ Object (readonly)
Returns the value of attribute api_name.
10 11 12 |
# File 'lib/generator/resolvers/type_resolver.rb', line 10 def api_name @api_name end |
#specification ⇒ Object (readonly)
Returns the value of attribute specification.
10 11 12 |
# File 'lib/generator/resolvers/type_resolver.rb', line 10 def specification @specification end |
#type_name ⇒ Object (readonly)
Returns the value of attribute type_name.
10 11 12 |
# File 'lib/generator/resolvers/type_resolver.rb', line 10 def type_name @type_name end |
Instance Method Details
#generated_type?(name) ⇒ Boolean
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/generator/resolvers/type_resolver.rb', line 28 def generated_type?(name) return false if name.nil? return false unless specification && specification["definitions"] type_def = specification["definitions"][name] return false unless type_def # Only object types and allOf compositions get generated as separate files # Money-related types are handled specially # Types with ONLY additionalProperties (no defined properties) are treated as Hash return false if MoneyDetector.money_type?(name) return false if type_def["additionalProperties"] && !type_def["properties"] && !type_def["allOf"] type_def["type"] == "object" || type_def["allOf"] end |
#resolve(prop_def, for_comment: false, for_rbs: false, prop_name: nil) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/generator/resolvers/type_resolver.rb', line 18 def resolve(prop_def, for_comment: false, for_rbs: false, prop_name: nil) return (for_rbs ? "Hash[untyped, untyped]" : "Hash") unless prop_def.is_a?(Hash) if prop_def["$ref"] resolve_ref_type(prop_def["$ref"], for_comment, for_rbs) else resolve_inline_type(prop_def, for_comment, for_rbs, prop_name) end end |