Class: SwaggerYard::Api
- Inherits:
-
Object
- Object
- SwaggerYard::Api
- Defined in:
- lib/swagger_yard/api.rb
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#path ⇒ Object
Returns the value of attribute path.
Class Method Summary collapse
- .from_yard_object(yard_object, api_declaration) ⇒ Object
- .path_from_yard_object(yard_object) ⇒ Object
Instance Method Summary collapse
- #add_operation(yard_object) ⇒ Object
-
#initialize(path, description, api_declaration) ⇒ Api
constructor
A new instance of Api.
- #model_names ⇒ Object
- #ref?(data_type) ⇒ Boolean
- #to_h ⇒ Object
Constructor Details
#initialize(path, description, api_declaration) ⇒ Api
Returns a new instance of Api.
20 21 22 23 24 25 26 |
# File 'lib/swagger_yard/api.rb', line 20 def initialize(path, description, api_declaration) @api_declaration = api_declaration @description = description @path = path @operations = [] end |
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
3 4 5 |
# File 'lib/swagger_yard/api.rb', line 3 def description @description end |
#path ⇒ Object
Returns the value of attribute path.
3 4 5 |
# File 'lib/swagger_yard/api.rb', line 3 def path @path end |
Class Method Details
.from_yard_object(yard_object, api_declaration) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/swagger_yard/api.rb', line 13 def self.from_yard_object(yard_object, api_declaration) path = path_from_yard_object(yard_object) description = yard_object.docstring new(path, description, api_declaration) end |
.path_from_yard_object(yard_object) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/swagger_yard/api.rb', line 5 def self.path_from_yard_object(yard_object) if tag = yard_object..detect {|t| t.tag_name == "path"} tag.text else nil end end |
Instance Method Details
#add_operation(yard_object) ⇒ Object
28 29 30 |
# File 'lib/swagger_yard/api.rb', line 28 def add_operation(yard_object) @operations << Operation.from_yard_object(yard_object, self) end |
#model_names ⇒ Object
40 41 42 43 |
# File 'lib/swagger_yard/api.rb', line 40 def model_names @operations.map(&:model_names).flatten.compact.uniq # @parameters.select {|p| ref?(p['type'])}.map {|p| p['type']}.uniq end |
#ref?(data_type) ⇒ Boolean
45 46 47 |
# File 'lib/swagger_yard/api.rb', line 45 def ref?(data_type) @api_declaration.ref?(data_type) end |
#to_h ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/swagger_yard/api.rb', line 32 def to_h { "path" => path, "description" => description, "operations" => @operations.map(&:to_h) } end |