class Rspec::Autoswagger::DocPart

Attributes

example[R]
request[R]
rspec_core_obj[R]

Public Class Methods

new(rspec_core_obj, example) click to toggle source
# File lib/rspec/autoswagger/doc_part.rb, line 12
def initialize(rspec_core_obj, example)
  @rspec_core_obj = rspec_core_obj
  @request = rspec_core_obj.request
  @example = example
end

Public Instance Methods

create_definition(output_path = nil) click to toggle source
# File lib/rspec/autoswagger/doc_part.rb, line 62
def create_definition(output_path = nil)
  definition = Parts::Definition.new(rspec_core_obj.response.body, response_name, output_path)
  definition.generate_definitions
end
create_path() click to toggle source
# File lib/rspec/autoswagger/doc_part.rb, line 57
def create_path
  path = Parts::Path.new(rspec_core_obj, example, response_name)
  path.generate_hash
end
get_converted_path(path) click to toggle source
# File lib/rspec/autoswagger/doc_part.rb, line 45
def get_converted_path(path)
  path.split("/").map do |path_element|
    if Util.detect_uuid(path_element)
      ":id"
    elsif Util.detect_uuid(path_element)
      ":id"
    else
      path_element
    end
  end.join("/")
end
response_name() click to toggle source
# File lib/rspec/autoswagger/doc_part.rb, line 18
def response_name
  status = rspec_core_obj.response.status.to_s
  if status == '200'
    path = example.full_description[%r<(GET|POST|PATCH|PUT|DELETE) ([^ ]+)>, 2]
    if path.blank?
      path = request.path.gsub(Rspec::Autoswagger::API_BASE_PATH, '')
      path = get_converted_path(path)
    end
    if request.method == "GET"
      path.gsub(/\/|:/, '').camelize
    else
      path.gsub(/\/|:/, '').camelize + request.method.downcase.camelize
    end
  else
    path = example.full_description[%r<(GET|POST|PATCH|PUT|DELETE) ([^ ]+)>, 2]
    if path.blank?
      path = request.path.gsub(Rspec::Autoswagger::API_BASE_PATH, '')
      path = get_converted_path(path)
    end
    if request.method == "GET"
      path.gsub(/\/|:/, '').camelize + status
    else
      path.gsub(/\/|:/, '').camelize + status + request.method.downcase.camelize
    end
  end
end