Class: Swaggard::Swagger::Property

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, type, description = '', required = false, options = []) ⇒ Property

Returns a new instance of Property.



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

def initialize(name, type, description = '', required = false, options = [])
  @id = name
  @type = type
  @description = description
  @required = required
  @options = options
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



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

def description
  @description
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#typeObject (readonly)

Returns the value of attribute type.



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

def type
  @type
end

Instance Method Details

#required?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/swaggard/swagger/property.rb', line 16

def required?
  @required
end

#to_docObject



20
21
22
23
24
25
# File 'lib/swaggard/swagger/property.rb', line 20

def to_doc
  result = @type.to_doc
  result['description'] = @description if @description.present?
  result['enum'] = @options if @options.present?
  result
end