Class: SwaggerYard::Property

Inherits:
Object
  • Object
show all
Defined in:
lib/swagger_yard/property.rb

Overview

Holds the name and type for a single model property

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, types, description, required) ⇒ Property

Returns a new instance of Property.



16
17
18
19
20
# File 'lib/swagger_yard/property.rb', line 16

def initialize(name, types, description, required)
  @name, @description, @required = name, description, required

  @type = Type.from_type_list(types)
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



6
7
8
# File 'lib/swagger_yard/property.rb', line 6

def description
  @description
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/swagger_yard/property.rb', line 6

def name
  @name
end

Class Method Details

.from_tag(tag) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/swagger_yard/property.rb', line 8

def self.from_tag(tag)
  name, options_string = tag.name.split(/[\(\)]/)

  required = options_string.to_s.split(',').map(&:strip).include?('required')

  new(name, tag.types, tag.text, required)
end

Instance Method Details

#model_nameObject



26
27
28
# File 'lib/swagger_yard/property.rb', line 26

def model_name
  @type.model_name
end

#required?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/swagger_yard/property.rb', line 22

def required?
  @required
end

#to_hObject



30
31
32
33
34
# File 'lib/swagger_yard/property.rb', line 30

def to_h
  result = @type.to_h
  result["description"] = description if description
  result
end