Class: Openapi2ruby::Openapi::Schema::Property

Inherits:
Object
  • Object
show all
Defined in:
lib/openapi2ruby/openapi/schema/property.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content) ⇒ Property

Returns a new instance of Property.



5
6
7
8
9
10
11
# 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']
end

Instance Attribute Details

#nameObject (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

#refString

OpenAPI schema ref property name

Returns:

  • (String)


15
16
17
18
# File 'lib/openapi2ruby/openapi/schema/property.rb', line 15

def ref
  return @items['$ref'].split('/').last if ref_items?
  @ref.split('/').last
end

#ref?Boolean

Whether property is ref or not

Returns:

  • (Boolean)


28
29
30
# File 'lib/openapi2ruby/openapi/schema/property.rb', line 28

def ref?
  !@ref.nil?
end

#ref_classString

OpenAPI schema ref property class name

Returns:

  • (String)


22
23
24
# File 'lib/openapi2ruby/openapi/schema/property.rb', line 22

def ref_class
  ref.camelcase
end

#ref_items?Boolean

Whether property has ref array items

Returns:

  • (Boolean)


34
35
36
# File 'lib/openapi2ruby/openapi/schema/property.rb', line 34

def ref_items?
  @type == 'array' && !@items['$ref'].nil?
end

#typesArray[Class]

OpenAPI schema property types

Returns:

  • (Array[Class])


40
41
42
43
# File 'lib/openapi2ruby/openapi/schema/property.rb', line 40

def types
  return [ref] if @type.nil?
  converted_types
end