Class: Swaggard::Swagger::Definition
- Inherits:
-
Object
- Object
- Swaggard::Swagger::Definition
- Defined in:
- lib/swaggard/swagger/definition.rb
Instance Attribute Summary collapse
-
#description ⇒ Object
writeonly
Sets the attribute description.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#title ⇒ Object
writeonly
Sets the attribute title.
Instance Method Summary collapse
- #add_property(property) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(id) ⇒ Definition
constructor
A new instance of Definition.
- #to_doc ⇒ Object
Constructor Details
#initialize(id) ⇒ Definition
Returns a new instance of Definition.
8 9 10 11 12 13 |
# File 'lib/swaggard/swagger/definition.rb', line 8 def initialize(id) @id = id @title = '' @properties = [] @description = '' end |
Instance Attribute Details
#description=(value) ⇒ Object (writeonly)
Sets the attribute description
6 7 8 |
# File 'lib/swaggard/swagger/definition.rb', line 6 def description=(value) @description = value end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'lib/swaggard/swagger/definition.rb', line 5 def id @id end |
#title=(value) ⇒ Object (writeonly)
Sets the attribute title
6 7 8 |
# File 'lib/swaggard/swagger/definition.rb', line 6 def title=(value) @title = value end |
Instance Method Details
#add_property(property) ⇒ Object
15 16 17 |
# File 'lib/swaggard/swagger/definition.rb', line 15 def add_property(property) @properties << property end |
#empty? ⇒ Boolean
19 20 21 |
# File 'lib/swaggard/swagger/definition.rb', line 19 def empty? @properties.empty? end |
#to_doc ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/swaggard/swagger/definition.rb', line 23 def to_doc {}.tap do |doc| doc['title'] = @title if @title.present? doc['type'] = 'object' doc['description'] = @description if @description.present? doc['properties'] = Hash[@properties.map { |property| [property.id, property.to_doc] }] required_properties = @properties.select(&:required?).map(&:id) doc['required'] = required_properties if required_properties.any? end end |