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
Constant Summary collapse
- MONEY_TYPES =
["Money", "MoneyType", "Currency", "CurrencyAmount"].freeze
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.
Class Method Summary collapse
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.
18 19 20 21 22 |
# File 'lib/generator/resolvers/type_resolver.rb', line 18 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 |
Class Method Details
.money?(name) ⇒ Boolean
13 14 15 |
# File 'lib/generator/resolvers/type_resolver.rb', line 13 def money?(name) MONEY_TYPES.include?(name) end |
Instance Method Details
#generated_type?(name) ⇒ Boolean
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/generator/resolvers/type_resolver.rb', line 34 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 money?(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
24 25 26 27 28 29 30 31 32 |
# File 'lib/generator/resolvers/type_resolver.rb', line 24 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 |