class SwaggerParser

Public Class Methods

new(path) click to toggle source
# 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

Public Instance Methods

api_endpoints() click to toggle source
# File lib/swagger_parser.rb, line 13
def api_endpoints
        endpoints = []
                base_path = @parse['basePath']
                if base_path == nil
                        raise "'basePath' not specified in swagger documentation"
                end
                swag_path = ''
                @parse['paths'].each do |path|
                        swag_path = base_path + path.first.gsub('{', ':').gsub('}', '')
                        endpoints << swag_path if swag_path.include?('api')
                end
        endpoints
end
http_requests() click to toggle source
# File lib/swagger_parser.rb, line 27
def http_requests
        request_types_arr = []
        paths_arr = []
        base_path = @parse['basePath']
        if base_path == nil
                raise "'basePath' not specified in swagger documentation"
        end
        @parse['paths'].each do |path|
                if base_path.include?('api')
                        paths_arr << path.first
                else
                        paths_arr << path.first if path.first.include?('api')
                end
        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