Class: SwaggerParser

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

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ SwaggerParser

Returns a new instance of SwaggerParser.



6
7
8
9
10
11
# File 'lib/swagger_parser.rb', line 6

def initialize(path)
  @path = path
  @yaml_file = @path.include?('yaml')
  @yaml_file ? @docs = YAML.load_file(path) : @docs = File.read(path)
  @yaml_file ? @parse = @docs : @parse = JSON.parse(@docs)
end

Instance Method Details

#api_endpointsObject



13
14
15
16
17
18
19
20
# File 'lib/swagger_parser.rb', line 13

def api_endpoints
  endpoints = []
    base_path = @parse['basePath']
    @parse['paths'].each do |path|
      endpoints << base_path + path.first.gsub('{', ':').gsub('}', '')
    end
  endpoints
end

#http_requestsObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/swagger_parser.rb', line 22

def http_requests
  request_types_arr = []
  paths_arr = []
  @parse['paths'].each do |path|
    paths_arr << path.first
  end
  paths_arr.each do |path|
    @yaml_file ? req = @parse['paths'] : req = @parse['paths'][path]
    @yaml_file ? req = req[path] : req
    req.each do |type|
      result = (type.first).upcase
      request_types_arr << result
    end
  end
  request_types_arr.sort
end