Class: Openapi2ruby::Openapi::Schema::Property
- Inherits:
-
Object
- Object
- Openapi2ruby::Openapi::Schema::Property
- Defined in:
- lib/openapi2ruby/openapi/schema/property.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(content) ⇒ Property
constructor
A new instance of Property.
- #one_of? ⇒ Boolean
- #one_of_refs ⇒ Object
-
#ref ⇒ String
OpenAPI schema ref property name.
-
#ref? ⇒ Boolean
Whether property is ref or not.
-
#ref_class ⇒ String
OpenAPI schema ref property class name.
-
#ref_items? ⇒ Boolean
Whether property has ref array items.
-
#types ⇒ Array[Class]
OpenAPI schema property types.
Constructor Details
#initialize(content) ⇒ Property
Returns a new instance of Property.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/openapi2ruby/openapi/schema/property.rb', line 5 def initialize(content) @name = content[:name] @type = content[:definition]['type'] @items = content[:definition]['items'] @format = content[:definition]['format'] @ref = content[:definition]['$ref'] if content[:definition]['oneOf'] @type = 'oneOf' @one_of_refs = content[:definition]['oneOf'].map do |content| content['$ref'].split('/').last end else @one_of_refs = [] end end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/openapi2ruby/openapi/schema/property.rb', line 3 def name @name end |
Instance Method Details
#one_of? ⇒ Boolean
55 56 57 |
# File 'lib/openapi2ruby/openapi/schema/property.rb', line 55 def one_of? @type == 'oneOf' && !@one_of_refs.empty? end |
#one_of_refs ⇒ Object
59 60 61 |
# File 'lib/openapi2ruby/openapi/schema/property.rb', line 59 def one_of_refs @one_of_refs end |
#ref ⇒ String
OpenAPI schema ref property name
23 24 25 26 |
# File 'lib/openapi2ruby/openapi/schema/property.rb', line 23 def ref return @items['$ref'].split('/').last if ref_items? @ref.split('/').last end |
#ref? ⇒ Boolean
Whether property is ref or not
36 37 38 |
# File 'lib/openapi2ruby/openapi/schema/property.rb', line 36 def ref? !@ref.nil? end |
#ref_class ⇒ String
OpenAPI schema ref property class name
30 31 32 |
# File 'lib/openapi2ruby/openapi/schema/property.rb', line 30 def ref_class ref.camelcase end |
#ref_items? ⇒ Boolean
Whether property has ref array items
42 43 44 |
# File 'lib/openapi2ruby/openapi/schema/property.rb', line 42 def ref_items? @type == 'array' && !@items['$ref'].nil? end |
#types ⇒ Array[Class]
OpenAPI schema property types
48 49 50 51 52 53 |
# File 'lib/openapi2ruby/openapi/schema/property.rb', line 48 def types return [Hash] if one_of? return [ref] if @type.nil? converted_types end |