Class: SwaggerYard::Api

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#descriptionObject

Returns the value of attribute description.



3
4
5
# File 'lib/swagger_yard/api.rb', line 3

def description
  @description
end

#pathObject

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.tags.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_namesObject



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

Returns:

  • (Boolean)


45
46
47
# File 'lib/swagger_yard/api.rb', line 45

def ref?(data_type)
  @api_declaration.ref?(data_type)
end

#to_hObject



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