class Rspec::Swagger::SwaggerLoader
Attributes
resources[R]
root[R]
Public Class Methods
new()
click to toggle source
# File lib/rspec/swagger/swagger_loader.rb, line 4 def initialize @root = JSON.parse(File.read("docs/swagger.json")) @resources = @root["apis"].map do |api| path = "#{api['path']}.json" if File.exists?("docs" + path) JSON.parse(File.read("docs" + path)) else raise "file not found: docs#{path}" end end @root.freeze @resources.freeze end
Public Instance Methods
documented_paths()
click to toggle source
Get a list of routes that are documented. Returns an array of Strings.
# File lib/rspec/swagger/swagger_loader.rb, line 26 def documented_paths @documented_paths ||= begin @resources.inject([]) { |memo, r| memo += r["apis"].map { |api| api["path"] } } end end
operation(verb, path)
click to toggle source
operation()
Get an operation by HTTP verb and path.
Example: @loader.operation(:GET, “/foo”)
# File lib/rspec/swagger/swagger_loader.rb, line 37 def operation(verb, path) @resources.each do |resource| resource["apis"].each do |api| api["operations"].each do |op| return op if op["httpMethod"] == verb.to_s && path == api["path"] end end end end