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
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

#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

#one_of?Boolean

Returns:

  • (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_refsObject



59
60
61
# File 'lib/openapi2ruby/openapi/schema/property.rb', line 59

def one_of_refs
  @one_of_refs
end

#refString

OpenAPI schema ref property name

Returns:

  • (String)


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

Returns:

  • (Boolean)


36
37
38
# File 'lib/openapi2ruby/openapi/schema/property.rb', line 36

def ref?
  !@ref.nil?
end

#ref_classString

OpenAPI schema ref property class name

Returns:

  • (String)


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

Returns:

  • (Boolean)


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

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

#typesArray[Class]

OpenAPI schema property types

Returns:

  • (Array[Class])


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