rspec_api_documentation 2.0.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/rspec_api_documentation.rb +3 -1
- data/lib/rspec_api_documentation/api_documentation.rb +2 -3
- data/lib/rspec_api_documentation/client_base.rb +4 -0
- data/lib/rspec_api_documentation/configuration.rb +3 -0
- data/lib/rspec_api_documentation/curl.rb +35 -10
- data/lib/rspec_api_documentation/dsl/resource.rb +5 -1
- data/lib/rspec_api_documentation/example.rb +19 -1
- data/lib/rspec_api_documentation/oauth2_mac_client.rb +10 -2
- data/lib/rspec_api_documentation/rack_test_client.rb +23 -0
- data/lib/rspec_api_documentation/views/html_index.rb +1 -1
- data/lib/rspec_api_documentation/views/markup_example.rb +9 -6
- data/lib/rspec_api_documentation/views/markup_index.rb +2 -2
- data/lib/rspec_api_documentation/views/textile_index.rb +1 -1
- data/lib/rspec_api_documentation/writers/append_json_writer.rb +49 -0
- data/lib/rspec_api_documentation/writers/combined_json_writer.rb +1 -1
- data/lib/rspec_api_documentation/writers/combined_text_writer.rb +1 -1
- data/lib/rspec_api_documentation/writers/general_markup_writer.rb +1 -13
- data/lib/rspec_api_documentation/writers/html_writer.rb +0 -2
- data/lib/rspec_api_documentation/writers/{index_writer.rb → index_helper.rb} +1 -1
- data/lib/rspec_api_documentation/writers/json_iodocs_writer.rb +4 -10
- data/lib/rspec_api_documentation/writers/json_writer.rb +24 -24
- data/lib/rspec_api_documentation/writers/textile_writer.rb +0 -2
- data/lib/rspec_api_documentation/writers/writer.rb +25 -0
- data/lib/tasks/docs.rake +6 -0
- data/templates/rspec_api_documentation/html_example.mustache +7 -2
- metadata +50 -76
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7cbc2ff27b6b9f2442e946657e47fc88c2c3e6ee
|
4
|
+
data.tar.gz: a8f1639743ba2ecfed6c625231ecc3506c025d25
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f84d994ca272c1802358f4aa89d0549af42fa03f8fc8abc840e229ac1f74d828cd9758bb8d5e541b6314f75cefe6639390ad2b979ea889469178a040be70c50e
|
7
|
+
data.tar.gz: d3f198afe1676a8abbadf41dfa8de83192128bed0dd293691cfeeded33766b7a0e08fff1fa2188a164c85da86cd218924bc27591e9206048c764c4508f508100
|
@@ -28,12 +28,14 @@ module RspecApiDocumentation
|
|
28
28
|
module Writers
|
29
29
|
extend ActiveSupport::Autoload
|
30
30
|
|
31
|
+
autoload :Writer
|
31
32
|
autoload :GeneralMarkupWriter
|
32
33
|
autoload :HtmlWriter
|
33
34
|
autoload :TextileWriter
|
34
35
|
autoload :JsonWriter
|
36
|
+
autoload :AppendJsonWriter
|
35
37
|
autoload :JsonIodocsWriter
|
36
|
-
autoload :
|
38
|
+
autoload :IndexHelper
|
37
39
|
autoload :CombinedTextWriter
|
38
40
|
autoload :CombinedJsonWriter
|
39
41
|
end
|
@@ -10,10 +10,9 @@ module RspecApiDocumentation
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def clear_docs
|
13
|
-
|
14
|
-
|
13
|
+
writers.each do |writer|
|
14
|
+
writer.clear_docs(docs_dir)
|
15
15
|
end
|
16
|
-
FileUtils.mkdir_p(docs_dir)
|
17
16
|
end
|
18
17
|
|
19
18
|
def document_example(rspec_example)
|
@@ -49,6 +49,10 @@ module RspecApiDocumentation
|
|
49
49
|
|
50
50
|
request_metadata = {}
|
51
51
|
|
52
|
+
if request_content_type =~ /multipart\/form-data/ && respond_to?(:handle_multipart_body, true)
|
53
|
+
request_body = handle_multipart_body(request_headers, request_body)
|
54
|
+
end
|
55
|
+
|
52
56
|
request_metadata[:request_method] = method
|
53
57
|
request_metadata[:request_path] = path
|
54
58
|
request_metadata[:request_body] = request_body.empty? ? nil : request_body
|
@@ -54,10 +54,13 @@ module RspecApiDocumentation
|
|
54
54
|
end
|
55
55
|
}
|
56
56
|
|
57
|
+
add_setting :curl_headers_to_filter, :default => nil
|
57
58
|
add_setting :curl_host, :default => nil
|
58
59
|
add_setting :keep_source_order, :default => false
|
59
60
|
add_setting :api_name, :default => "API Documentation"
|
60
61
|
add_setting :io_docs_protocol, :default => "http"
|
62
|
+
add_setting :request_headers_to_include, :default => nil
|
63
|
+
add_setting :response_headers_to_include, :default => nil
|
61
64
|
|
62
65
|
def client_method=(new_client_method)
|
63
66
|
RspecApiDocumentation::DSL::Resource.module_eval <<-RUBY
|
@@ -1,11 +1,13 @@
|
|
1
1
|
require 'active_support/core_ext/object/to_query'
|
2
|
+
require 'base64'
|
2
3
|
|
3
4
|
module RspecApiDocumentation
|
4
5
|
class Curl < Struct.new(:method, :path, :data, :headers)
|
5
6
|
attr_accessor :host
|
6
7
|
|
7
|
-
def output(config_host)
|
8
|
+
def output(config_host, config_headers_to_filer = nil)
|
8
9
|
self.host = config_host
|
10
|
+
@config_headers_to_filer = Array(config_headers_to_filer)
|
9
11
|
send(method.downcase)
|
10
12
|
end
|
11
13
|
|
@@ -17,6 +19,10 @@ module RspecApiDocumentation
|
|
17
19
|
"curl \"#{url}#{get_data}\" -X GET #{headers}"
|
18
20
|
end
|
19
21
|
|
22
|
+
def head
|
23
|
+
"curl \"#{url}#{get_data}\" -X HEAD #{headers}"
|
24
|
+
end
|
25
|
+
|
20
26
|
def put
|
21
27
|
"curl \"#{url}\" #{post_data} -X PUT #{headers}"
|
22
28
|
end
|
@@ -25,10 +31,6 @@ module RspecApiDocumentation
|
|
25
31
|
"curl \"#{url}\" #{post_data} -X DELETE #{headers}"
|
26
32
|
end
|
27
33
|
|
28
|
-
def head
|
29
|
-
"curl \"#{url}#{get_data}\" -X HEAD #{headers}"
|
30
|
-
end
|
31
|
-
|
32
34
|
def patch
|
33
35
|
"curl \"#{url}\" #{post_data} -X PATCH #{headers}"
|
34
36
|
end
|
@@ -38,8 +40,12 @@ module RspecApiDocumentation
|
|
38
40
|
end
|
39
41
|
|
40
42
|
def headers
|
41
|
-
super.map do |k, v|
|
42
|
-
|
43
|
+
filter_headers(super).map do |k, v|
|
44
|
+
if k =~ /authorization/i && v =~ /^Basic/
|
45
|
+
"\\\n\t-u #{format_auth_header(v)}"
|
46
|
+
else
|
47
|
+
"\\\n\t-H \"#{format_full_header(k, v)}\""
|
48
|
+
end
|
43
49
|
end.join(" ")
|
44
50
|
end
|
45
51
|
|
@@ -53,9 +59,28 @@ module RspecApiDocumentation
|
|
53
59
|
end
|
54
60
|
|
55
61
|
private
|
56
|
-
|
57
|
-
|
58
|
-
|
62
|
+
|
63
|
+
def format_auth_header(value)
|
64
|
+
::Base64.decode64(value.split(' ', 2).last || '')
|
65
|
+
end
|
66
|
+
|
67
|
+
def format_header(header)
|
68
|
+
header.gsub(/^HTTP_/, '').titleize.split.join("-")
|
69
|
+
end
|
70
|
+
|
71
|
+
def format_full_header(header, value)
|
72
|
+
formatted_value = value ? value.gsub(/"/, "\\\"") : ''
|
73
|
+
"#{format_header(header)}: #{formatted_value}"
|
74
|
+
end
|
75
|
+
|
76
|
+
def filter_headers(headers)
|
77
|
+
if !@config_headers_to_filer.empty?
|
78
|
+
headers.reject do |header|
|
79
|
+
@config_headers_to_filer.include?(format_header(header))
|
80
|
+
end
|
81
|
+
else
|
82
|
+
headers
|
83
|
+
end
|
59
84
|
end
|
60
85
|
end
|
61
86
|
end
|
@@ -23,7 +23,11 @@ module RspecApiDocumentation::DSL
|
|
23
23
|
define_action :patch
|
24
24
|
|
25
25
|
def callback(*args, &block)
|
26
|
-
|
26
|
+
begin
|
27
|
+
require 'webmock'
|
28
|
+
rescue LoadError
|
29
|
+
raise "Callbacks require webmock to be installed"
|
30
|
+
end
|
27
31
|
self.send(:include, WebMock::API)
|
28
32
|
|
29
33
|
options = if args.last.is_a?(Hash) then args.pop else {} end
|
@@ -43,7 +43,25 @@ module RspecApiDocumentation
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def requests
|
46
|
-
metadata[:requests] || []
|
46
|
+
filter_headers(metadata[:requests]) || []
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def filter_headers(requests)
|
52
|
+
requests = remap_headers(requests, :request_headers, configuration.request_headers_to_include)
|
53
|
+
requests = remap_headers(requests, :response_headers, configuration.response_headers_to_include)
|
54
|
+
requests
|
55
|
+
end
|
56
|
+
|
57
|
+
def remap_headers(requests, key, headers_to_include)
|
58
|
+
return requests unless headers_to_include
|
59
|
+
requests.each.with_index do |request_hash, index|
|
60
|
+
next unless request_hash.key?(key)
|
61
|
+
headers = request_hash[key]
|
62
|
+
request_hash[key] = headers.select{ |key, _| headers_to_include.include?(key) }
|
63
|
+
requests[index] = request_hash
|
64
|
+
end
|
47
65
|
end
|
48
66
|
end
|
49
67
|
end
|
@@ -3,8 +3,16 @@ begin
|
|
3
3
|
rescue LoadError
|
4
4
|
# ActiveSupport::SecureRandom not provided in activesupport >= 3.2
|
5
5
|
end
|
6
|
-
|
7
|
-
require "
|
6
|
+
begin
|
7
|
+
require "webmock"
|
8
|
+
rescue LoadError
|
9
|
+
raise "Webmock needs to be installed before using the OAuth2MACClient"
|
10
|
+
end
|
11
|
+
begin
|
12
|
+
require "rack/oauth2"
|
13
|
+
rescue LoadError
|
14
|
+
raise "Rack OAuth2 needs to be installed before using the OAuth2MACClient"
|
15
|
+
end
|
8
16
|
|
9
17
|
module RspecApiDocumentation
|
10
18
|
class OAuth2MACClient < ClientBase
|
@@ -42,8 +42,31 @@ module RspecApiDocumentation
|
|
42
42
|
headers_to_env(super)
|
43
43
|
end
|
44
44
|
|
45
|
+
def handle_multipart_body(request_headers, request_body)
|
46
|
+
parsed_parameters = Rack::Request.new({
|
47
|
+
"CONTENT_TYPE" => request_headers["Content-Type"],
|
48
|
+
"rack.input" => StringIO.new(request_body)
|
49
|
+
}).params
|
50
|
+
|
51
|
+
clean_out_uploaded_data(parsed_parameters,request_body)
|
52
|
+
end
|
53
|
+
|
45
54
|
private
|
46
55
|
|
56
|
+
def clean_out_uploaded_data(params,request_body)
|
57
|
+
params.each do |_, value|
|
58
|
+
if value.is_a?(Hash)
|
59
|
+
if value.has_key?(:tempfile)
|
60
|
+
data = value[:tempfile].read
|
61
|
+
request_body = request_body.gsub(data, "[uploaded data]")
|
62
|
+
else
|
63
|
+
request_body = clean_out_uploaded_data(value,request_body)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
request_body
|
68
|
+
end
|
69
|
+
|
47
70
|
def rack_test_session
|
48
71
|
@rack_test_session ||= Struct.new(:app) do
|
49
72
|
begin
|
@@ -6,9 +6,10 @@ module RspecApiDocumentation
|
|
6
6
|
def initialize(example, configuration)
|
7
7
|
@example = example
|
8
8
|
@host = configuration.curl_host
|
9
|
+
@filter_headers = configuration.curl_headers_to_filter
|
9
10
|
self.template_path = configuration.template_path
|
10
11
|
end
|
11
|
-
|
12
|
+
|
12
13
|
def method_missing(method, *args, &block)
|
13
14
|
@example.send(method, *args, &block)
|
14
15
|
end
|
@@ -18,29 +19,31 @@ module RspecApiDocumentation
|
|
18
19
|
end
|
19
20
|
|
20
21
|
def dirname
|
21
|
-
resource_name.downcase.gsub(
|
22
|
+
resource_name.downcase.gsub(/[^0-9a-z.\-]+/, '_')
|
22
23
|
end
|
23
|
-
|
24
|
+
|
24
25
|
def filename
|
25
26
|
basename = description.downcase.gsub(/\s+/, '_').gsub(/[^a-z_]/, '')
|
26
27
|
basename = Digest::MD5.new.update(description).to_s if basename.blank?
|
27
28
|
"#{basename}.#{extension}"
|
28
29
|
end
|
29
|
-
|
30
|
+
|
30
31
|
def requests
|
31
32
|
super.map do |hash|
|
32
33
|
hash[:request_headers_text] = format_hash(hash[:request_headers])
|
33
34
|
hash[:request_query_parameters_text] = format_hash(hash[:request_query_parameters])
|
34
35
|
hash[:response_headers_text] = format_hash(hash[:response_headers])
|
35
36
|
if @host
|
36
|
-
|
37
|
+
if hash[:curl].is_a? RspecApiDocumentation::Curl
|
38
|
+
hash[:curl] = hash[:curl].output(@host, @filter_headers)
|
39
|
+
end
|
37
40
|
else
|
38
41
|
hash[:curl] = nil
|
39
42
|
end
|
40
43
|
hash
|
41
44
|
end
|
42
45
|
end
|
43
|
-
|
46
|
+
|
44
47
|
def extension
|
45
48
|
raise 'Parent class. This method should not be called.'
|
46
49
|
end
|
@@ -8,13 +8,13 @@ module RspecApiDocumentation
|
|
8
8
|
@configuration = configuration
|
9
9
|
self.template_path = configuration.template_path
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
def api_name
|
13
13
|
@configuration.api_name
|
14
14
|
end
|
15
15
|
|
16
16
|
def sections
|
17
|
-
RspecApiDocumentation::Writers::
|
17
|
+
RspecApiDocumentation::Writers::IndexHelper.sections(examples, @configuration)
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'rspec_api_documentation/writers/formatter'
|
2
|
+
|
3
|
+
module RspecApiDocumentation
|
4
|
+
module Writers
|
5
|
+
class AppendJsonWriter < JsonWriter
|
6
|
+
def write
|
7
|
+
index_file = docs_dir.join("index.json")
|
8
|
+
if File.exists?(index_file) && (output = File.read(index_file)).length >= 2
|
9
|
+
existing_index_hash = JSON.parse(output)
|
10
|
+
end
|
11
|
+
File.open(index_file, "w+") do |f|
|
12
|
+
f.write Formatter.to_json(AppendJsonIndex.new(index, configuration, existing_index_hash))
|
13
|
+
end
|
14
|
+
write_examples
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.clear_docs(docs_dir)
|
18
|
+
nil #noop
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class AppendJsonIndex < JsonIndex
|
23
|
+
def initialize(index, configuration, existing_index_hash = nil)
|
24
|
+
@index = index
|
25
|
+
@configuration = configuration
|
26
|
+
@existing_index_hash = clean_index_hash(existing_index_hash)
|
27
|
+
end
|
28
|
+
|
29
|
+
def as_json(opts = nil)
|
30
|
+
sections.inject(@existing_index_hash) do |h, section|
|
31
|
+
h[:resources].push(section_hash(section))
|
32
|
+
h
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def clean_index_hash(existing_index_hash)
|
37
|
+
unless existing_index_hash.is_a?(Hash) && existing_index_hash["resources"].is_a?(Array) #check format
|
38
|
+
existing_index_hash = {:resources => []}
|
39
|
+
end
|
40
|
+
existing_index_hash = existing_index_hash.deep_symbolize_keys
|
41
|
+
existing_index_hash[:resources].map!(&:deep_symbolize_keys).reject! do |resource|
|
42
|
+
resource_names = sections.map{|s| s[:resource_name]}
|
43
|
+
resource_names.include? resource[:name]
|
44
|
+
end
|
45
|
+
existing_index_hash
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -2,7 +2,7 @@ require 'rspec_api_documentation/writers/json_writer'
|
|
2
2
|
|
3
3
|
module RspecApiDocumentation
|
4
4
|
module Writers
|
5
|
-
class CombinedJsonWriter
|
5
|
+
class CombinedJsonWriter < Writer
|
6
6
|
def self.write(index, configuration)
|
7
7
|
File.open(configuration.docs_dir.join("combined.json"), "w+") do |f|
|
8
8
|
examples = []
|
@@ -1,20 +1,8 @@
|
|
1
1
|
module RspecApiDocumentation
|
2
2
|
module Writers
|
3
|
-
class GeneralMarkupWriter
|
4
|
-
attr_accessor :index, :configuration
|
5
|
-
|
3
|
+
class GeneralMarkupWriter < Writer
|
6
4
|
INDEX_FILE_NAME = 'index'
|
7
|
-
|
8
|
-
def initialize(index, configuration)
|
9
|
-
self.index = index
|
10
|
-
self.configuration = configuration
|
11
|
-
end
|
12
5
|
|
13
|
-
def self.write(index, configuration)
|
14
|
-
writer = new(index, configuration)
|
15
|
-
writer.write
|
16
|
-
end
|
17
|
-
|
18
6
|
def write
|
19
7
|
File.open(configuration.docs_dir.join(index_file_name + '.' + extension), "w+") do |f|
|
20
8
|
f.write markup_index_class.new(index, configuration).render
|
@@ -2,7 +2,7 @@ require "active_support/core_ext/enumerable"
|
|
2
2
|
|
3
3
|
module RspecApiDocumentation
|
4
4
|
module Writers
|
5
|
-
module
|
5
|
+
module IndexHelper
|
6
6
|
def sections(examples, configuration)
|
7
7
|
resources = examples.group_by(&:resource_name).inject([]) do |arr, (resource_name, examples)|
|
8
8
|
ordered_examples = configuration.keep_source_order ? examples : examples.sort_by(&:description)
|
@@ -2,21 +2,15 @@ require 'rspec_api_documentation/writers/formatter'
|
|
2
2
|
|
3
3
|
module RspecApiDocumentation
|
4
4
|
module Writers
|
5
|
-
class JsonIodocsWriter
|
6
|
-
attr_accessor :
|
5
|
+
class JsonIodocsWriter < Writer
|
6
|
+
attr_accessor :api_key
|
7
7
|
delegate :docs_dir, :to => :configuration
|
8
8
|
|
9
9
|
def initialize(index, configuration)
|
10
|
-
|
11
|
-
self.configuration = configuration
|
10
|
+
super
|
12
11
|
self.api_key = configuration.api_name.parameterize
|
13
12
|
end
|
14
13
|
|
15
|
-
def self.write(index, configuration)
|
16
|
-
writer = new(index, configuration)
|
17
|
-
writer.write
|
18
|
-
end
|
19
|
-
|
20
14
|
def write
|
21
15
|
File.open(docs_dir.join("apiconfig.json"), "w+") do |file|
|
22
16
|
file.write Formatter.to_json(ApiConfig.new(configuration))
|
@@ -34,7 +28,7 @@ module RspecApiDocumentation
|
|
34
28
|
end
|
35
29
|
|
36
30
|
def sections
|
37
|
-
|
31
|
+
IndexHelper.sections(examples, @configuration)
|
38
32
|
end
|
39
33
|
|
40
34
|
def examples
|
@@ -2,24 +2,17 @@ require 'rspec_api_documentation/writers/formatter'
|
|
2
2
|
|
3
3
|
module RspecApiDocumentation
|
4
4
|
module Writers
|
5
|
-
class JsonWriter
|
6
|
-
attr_accessor :index, :configuration
|
5
|
+
class JsonWriter < Writer
|
7
6
|
delegate :docs_dir, :to => :configuration
|
8
7
|
|
9
|
-
def initialize(index, configuration)
|
10
|
-
self.index = index
|
11
|
-
self.configuration = configuration
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.write(index, configuration)
|
15
|
-
writer = new(index, configuration)
|
16
|
-
writer.write
|
17
|
-
end
|
18
|
-
|
19
8
|
def write
|
20
9
|
File.open(docs_dir.join("index.json"), "w+") do |f|
|
21
10
|
f.write Formatter.to_json(JsonIndex.new(index, configuration))
|
22
11
|
end
|
12
|
+
write_examples
|
13
|
+
end
|
14
|
+
|
15
|
+
def write_examples
|
23
16
|
index.examples.each do |example|
|
24
17
|
json_example = JsonExample.new(example, configuration)
|
25
18
|
FileUtils.mkdir_p(docs_dir.join(json_example.dirname))
|
@@ -37,7 +30,7 @@ module RspecApiDocumentation
|
|
37
30
|
end
|
38
31
|
|
39
32
|
def sections
|
40
|
-
|
33
|
+
IndexHelper.sections(examples, @configuration)
|
41
34
|
end
|
42
35
|
|
43
36
|
def examples
|
@@ -46,25 +39,30 @@ module RspecApiDocumentation
|
|
46
39
|
|
47
40
|
def as_json(opts = nil)
|
48
41
|
sections.inject({:resources => []}) do |h, section|
|
49
|
-
h[:resources].push(
|
50
|
-
:name => section[:resource_name],
|
51
|
-
:examples => section[:examples].map { |example|
|
52
|
-
{
|
53
|
-
:description => example.description,
|
54
|
-
:link => "#{example.dirname}/#{example.filename}",
|
55
|
-
:groups => example.metadata[:document]
|
56
|
-
}
|
57
|
-
}
|
58
|
-
)
|
42
|
+
h[:resources].push(section_hash(section))
|
59
43
|
h
|
60
44
|
end
|
61
45
|
end
|
46
|
+
|
47
|
+
def section_hash(section)
|
48
|
+
{
|
49
|
+
:name => section[:resource_name],
|
50
|
+
:examples => section[:examples].map { |example|
|
51
|
+
{
|
52
|
+
:description => example.description,
|
53
|
+
:link => "#{example.dirname}/#{example.filename}",
|
54
|
+
:groups => example.metadata[:document]
|
55
|
+
}
|
56
|
+
}
|
57
|
+
}
|
58
|
+
end
|
62
59
|
end
|
63
60
|
|
64
61
|
class JsonExample
|
65
62
|
def initialize(example, configuration)
|
66
63
|
@example = example
|
67
64
|
@host = configuration.curl_host
|
65
|
+
@filter_headers = configuration.curl_headers_to_filter
|
68
66
|
end
|
69
67
|
|
70
68
|
def method_missing(method, *args, &block)
|
@@ -99,7 +97,9 @@ module RspecApiDocumentation
|
|
99
97
|
def requests
|
100
98
|
super.map do |hash|
|
101
99
|
if @host
|
102
|
-
|
100
|
+
if hash[:curl].is_a? RspecApiDocumentation::Curl
|
101
|
+
hash[:curl] = hash[:curl].output(@host, @filter_headers)
|
102
|
+
end
|
103
103
|
else
|
104
104
|
hash[:curl] = nil
|
105
105
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module RspecApiDocumentation
|
2
|
+
module Writers
|
3
|
+
class Writer
|
4
|
+
attr_accessor :index, :configuration
|
5
|
+
|
6
|
+
def initialize(index, configuration)
|
7
|
+
self.index = index
|
8
|
+
self.configuration = configuration
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.write(index, configuration)
|
12
|
+
writer = new(index, configuration)
|
13
|
+
writer.write
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.clear_docs(docs_dir)
|
17
|
+
if File.exists?(docs_dir)
|
18
|
+
FileUtils.rm_rf(docs_dir, :secure => true)
|
19
|
+
end
|
20
|
+
FileUtils.mkdir_p(docs_dir)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
data/lib/tasks/docs.rake
CHANGED
@@ -5,3 +5,9 @@ RSpec::Core::RakeTask.new('docs:generate') do |t|
|
|
5
5
|
t.pattern = 'spec/acceptance/**/*_spec.rb'
|
6
6
|
t.rspec_opts = ["--format RspecApiDocumentation::ApiFormatter"]
|
7
7
|
end
|
8
|
+
|
9
|
+
desc 'Generate API request documentation from API specs (ordered)'
|
10
|
+
RSpec::Core::RakeTask.new('docs:generate:ordered') do |t|
|
11
|
+
t.pattern = 'spec/acceptance/**/*_spec.rb'
|
12
|
+
t.rspec_opts = ["--format RspecApiDocumentation::ApiFormatter", "--order default"]
|
13
|
+
end
|
@@ -53,7 +53,12 @@
|
|
53
53
|
{{# parameters }}
|
54
54
|
<tr>
|
55
55
|
<td{{# required }} class="required"{{/ required }}>
|
56
|
-
|
56
|
+
{{# scope }}
|
57
|
+
<span class="name">{{ scope }}[{{ name }}]</span>
|
58
|
+
{{/ scope }}
|
59
|
+
{{^ scope }}
|
60
|
+
<span class="name">{{ name }}</span>
|
61
|
+
{{/ scope }}
|
57
62
|
</td>
|
58
63
|
<td>
|
59
64
|
<span class="description">{{ description }}</span>
|
@@ -85,7 +90,7 @@
|
|
85
90
|
|
86
91
|
{{# curl }}
|
87
92
|
<h4>cURL</h4>
|
88
|
-
<pre class="request">{{ curl }}</pre>
|
93
|
+
<pre class="request curl">{{ curl }}</pre>
|
89
94
|
{{/ curl }}
|
90
95
|
|
91
96
|
{{# response_status }}
|
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec_api_documentation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
5
|
-
prerelease:
|
4
|
+
version: 3.0.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Chris Cahoon
|
@@ -11,216 +10,190 @@ authors:
|
|
11
10
|
autorequire:
|
12
11
|
bindir: bin
|
13
12
|
cert_chain: []
|
14
|
-
date:
|
13
|
+
date: 2014-04-15 00:00:00.000000000 Z
|
15
14
|
dependencies:
|
16
15
|
- !ruby/object:Gem::Dependency
|
17
16
|
name: rspec
|
18
17
|
requirement: !ruby/object:Gem::Requirement
|
19
|
-
none: false
|
20
18
|
requirements:
|
21
|
-
- -
|
19
|
+
- - '>='
|
22
20
|
- !ruby/object:Gem::Version
|
23
21
|
version: 2.14.0
|
24
22
|
type: :runtime
|
25
23
|
prerelease: false
|
26
24
|
version_requirements: !ruby/object:Gem::Requirement
|
27
|
-
none: false
|
28
25
|
requirements:
|
29
|
-
- -
|
26
|
+
- - '>='
|
30
27
|
- !ruby/object:Gem::Version
|
31
28
|
version: 2.14.0
|
32
29
|
- !ruby/object:Gem::Dependency
|
33
30
|
name: activesupport
|
34
31
|
requirement: !ruby/object:Gem::Requirement
|
35
|
-
none: false
|
36
32
|
requirements:
|
37
|
-
- -
|
33
|
+
- - '>='
|
38
34
|
- !ruby/object:Gem::Version
|
39
35
|
version: 3.0.0
|
40
36
|
type: :runtime
|
41
37
|
prerelease: false
|
42
38
|
version_requirements: !ruby/object:Gem::Requirement
|
43
|
-
none: false
|
44
39
|
requirements:
|
45
|
-
- -
|
40
|
+
- - '>='
|
46
41
|
- !ruby/object:Gem::Version
|
47
42
|
version: 3.0.0
|
48
43
|
- !ruby/object:Gem::Dependency
|
49
44
|
name: i18n
|
50
45
|
requirement: !ruby/object:Gem::Requirement
|
51
|
-
none: false
|
52
46
|
requirements:
|
53
|
-
- -
|
47
|
+
- - '>='
|
54
48
|
- !ruby/object:Gem::Version
|
55
49
|
version: 0.1.0
|
56
50
|
type: :runtime
|
57
51
|
prerelease: false
|
58
52
|
version_requirements: !ruby/object:Gem::Requirement
|
59
|
-
none: false
|
60
53
|
requirements:
|
61
|
-
- -
|
54
|
+
- - '>='
|
62
55
|
- !ruby/object:Gem::Version
|
63
56
|
version: 0.1.0
|
64
57
|
- !ruby/object:Gem::Dependency
|
65
58
|
name: mustache
|
66
59
|
requirement: !ruby/object:Gem::Requirement
|
67
|
-
none: false
|
68
60
|
requirements:
|
69
|
-
- -
|
61
|
+
- - '>='
|
70
62
|
- !ruby/object:Gem::Version
|
71
63
|
version: 0.99.4
|
72
64
|
type: :runtime
|
73
65
|
prerelease: false
|
74
66
|
version_requirements: !ruby/object:Gem::Requirement
|
75
|
-
none: false
|
76
67
|
requirements:
|
77
|
-
- -
|
68
|
+
- - '>='
|
78
69
|
- !ruby/object:Gem::Version
|
79
70
|
version: 0.99.4
|
80
|
-
- !ruby/object:Gem::Dependency
|
81
|
-
name: webmock
|
82
|
-
requirement: !ruby/object:Gem::Requirement
|
83
|
-
none: false
|
84
|
-
requirements:
|
85
|
-
- - ! '>='
|
86
|
-
- !ruby/object:Gem::Version
|
87
|
-
version: 1.7.0
|
88
|
-
type: :runtime
|
89
|
-
prerelease: false
|
90
|
-
version_requirements: !ruby/object:Gem::Requirement
|
91
|
-
none: false
|
92
|
-
requirements:
|
93
|
-
- - ! '>='
|
94
|
-
- !ruby/object:Gem::Version
|
95
|
-
version: 1.7.0
|
96
71
|
- !ruby/object:Gem::Dependency
|
97
72
|
name: json
|
98
73
|
requirement: !ruby/object:Gem::Requirement
|
99
|
-
none: false
|
100
74
|
requirements:
|
101
|
-
- -
|
75
|
+
- - '>='
|
102
76
|
- !ruby/object:Gem::Version
|
103
77
|
version: 1.4.6
|
104
78
|
type: :runtime
|
105
79
|
prerelease: false
|
106
80
|
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
none: false
|
108
81
|
requirements:
|
109
|
-
- -
|
82
|
+
- - '>='
|
110
83
|
- !ruby/object:Gem::Version
|
111
84
|
version: 1.4.6
|
112
85
|
- !ruby/object:Gem::Dependency
|
113
86
|
name: fakefs
|
114
87
|
requirement: !ruby/object:Gem::Requirement
|
115
|
-
none: false
|
116
88
|
requirements:
|
117
|
-
- -
|
89
|
+
- - '>='
|
118
90
|
- !ruby/object:Gem::Version
|
119
91
|
version: '0'
|
120
92
|
type: :development
|
121
93
|
prerelease: false
|
122
94
|
version_requirements: !ruby/object:Gem::Requirement
|
123
|
-
none: false
|
124
95
|
requirements:
|
125
|
-
- -
|
96
|
+
- - '>='
|
126
97
|
- !ruby/object:Gem::Version
|
127
98
|
version: '0'
|
128
99
|
- !ruby/object:Gem::Dependency
|
129
100
|
name: sinatra
|
130
101
|
requirement: !ruby/object:Gem::Requirement
|
131
|
-
none: false
|
132
102
|
requirements:
|
133
|
-
- -
|
103
|
+
- - '>='
|
134
104
|
- !ruby/object:Gem::Version
|
135
105
|
version: '0'
|
136
106
|
type: :development
|
137
107
|
prerelease: false
|
138
108
|
version_requirements: !ruby/object:Gem::Requirement
|
139
|
-
none: false
|
140
109
|
requirements:
|
141
|
-
- -
|
110
|
+
- - '>='
|
142
111
|
- !ruby/object:Gem::Version
|
143
112
|
version: '0'
|
144
113
|
- !ruby/object:Gem::Dependency
|
145
114
|
name: aruba
|
146
115
|
requirement: !ruby/object:Gem::Requirement
|
147
|
-
none: false
|
148
116
|
requirements:
|
149
|
-
- -
|
117
|
+
- - '>='
|
150
118
|
- !ruby/object:Gem::Version
|
151
119
|
version: '0'
|
152
120
|
type: :development
|
153
121
|
prerelease: false
|
154
122
|
version_requirements: !ruby/object:Gem::Requirement
|
155
|
-
none: false
|
156
123
|
requirements:
|
157
|
-
- -
|
124
|
+
- - '>='
|
158
125
|
- !ruby/object:Gem::Version
|
159
126
|
version: '0'
|
160
127
|
- !ruby/object:Gem::Dependency
|
161
128
|
name: capybara
|
162
129
|
requirement: !ruby/object:Gem::Requirement
|
163
|
-
none: false
|
164
130
|
requirements:
|
165
|
-
- -
|
131
|
+
- - '>='
|
166
132
|
- !ruby/object:Gem::Version
|
167
133
|
version: '0'
|
168
134
|
type: :development
|
169
135
|
prerelease: false
|
170
136
|
version_requirements: !ruby/object:Gem::Requirement
|
171
|
-
none: false
|
172
137
|
requirements:
|
173
|
-
- -
|
138
|
+
- - '>='
|
174
139
|
- !ruby/object:Gem::Version
|
175
140
|
version: '0'
|
176
141
|
- !ruby/object:Gem::Dependency
|
177
142
|
name: rake
|
178
143
|
requirement: !ruby/object:Gem::Requirement
|
179
|
-
none: false
|
180
144
|
requirements:
|
181
|
-
- -
|
145
|
+
- - '>='
|
182
146
|
- !ruby/object:Gem::Version
|
183
147
|
version: '0'
|
184
148
|
type: :development
|
185
149
|
prerelease: false
|
186
150
|
version_requirements: !ruby/object:Gem::Requirement
|
187
|
-
none: false
|
188
151
|
requirements:
|
189
|
-
- -
|
152
|
+
- - '>='
|
190
153
|
- !ruby/object:Gem::Version
|
191
154
|
version: '0'
|
192
155
|
- !ruby/object:Gem::Dependency
|
193
156
|
name: rack-test
|
194
157
|
requirement: !ruby/object:Gem::Requirement
|
195
|
-
none: false
|
196
158
|
requirements:
|
197
|
-
- -
|
159
|
+
- - '>='
|
198
160
|
- !ruby/object:Gem::Version
|
199
161
|
version: 0.6.2
|
200
162
|
type: :development
|
201
163
|
prerelease: false
|
202
164
|
version_requirements: !ruby/object:Gem::Requirement
|
203
|
-
none: false
|
204
165
|
requirements:
|
205
|
-
- -
|
166
|
+
- - '>='
|
206
167
|
- !ruby/object:Gem::Version
|
207
168
|
version: 0.6.2
|
208
169
|
- !ruby/object:Gem::Dependency
|
209
170
|
name: rack-oauth2
|
210
171
|
requirement: !ruby/object:Gem::Requirement
|
211
|
-
none: false
|
212
172
|
requirements:
|
213
|
-
- -
|
173
|
+
- - '>='
|
214
174
|
- !ruby/object:Gem::Version
|
215
175
|
version: 0.14.4
|
216
176
|
type: :development
|
217
177
|
prerelease: false
|
218
178
|
version_requirements: !ruby/object:Gem::Requirement
|
219
|
-
none: false
|
220
179
|
requirements:
|
221
|
-
- -
|
180
|
+
- - '>='
|
222
181
|
- !ruby/object:Gem::Version
|
223
182
|
version: 0.14.4
|
183
|
+
- !ruby/object:Gem::Dependency
|
184
|
+
name: webmock
|
185
|
+
requirement: !ruby/object:Gem::Requirement
|
186
|
+
requirements:
|
187
|
+
- - '>='
|
188
|
+
- !ruby/object:Gem::Version
|
189
|
+
version: 1.7.0
|
190
|
+
type: :development
|
191
|
+
prerelease: false
|
192
|
+
version_requirements: !ruby/object:Gem::Requirement
|
193
|
+
requirements:
|
194
|
+
- - '>='
|
195
|
+
- !ruby/object:Gem::Version
|
196
|
+
version: 1.7.0
|
224
197
|
description: Generate API docs from your test suite
|
225
198
|
email:
|
226
199
|
- chris@smartlogicsolutions.com
|
@@ -248,14 +221,16 @@ files:
|
|
248
221
|
- lib/rspec_api_documentation/views/textile_index.rb
|
249
222
|
- lib/rspec_api_documentation/views/markup_index.rb
|
250
223
|
- lib/rspec_api_documentation/views/markup_example.rb
|
224
|
+
- lib/rspec_api_documentation/writers/append_json_writer.rb
|
251
225
|
- lib/rspec_api_documentation/writers/textile_writer.rb
|
252
226
|
- lib/rspec_api_documentation/writers/general_markup_writer.rb
|
253
227
|
- lib/rspec_api_documentation/writers/html_writer.rb
|
254
228
|
- lib/rspec_api_documentation/writers/json_iodocs_writer.rb
|
229
|
+
- lib/rspec_api_documentation/writers/index_helper.rb
|
255
230
|
- lib/rspec_api_documentation/writers/json_writer.rb
|
231
|
+
- lib/rspec_api_documentation/writers/writer.rb
|
256
232
|
- lib/rspec_api_documentation/writers/combined_json_writer.rb
|
257
233
|
- lib/rspec_api_documentation/writers/formatter.rb
|
258
|
-
- lib/rspec_api_documentation/writers/index_writer.rb
|
259
234
|
- lib/rspec_api_documentation/writers/combined_text_writer.rb
|
260
235
|
- lib/rspec_api_documentation/configuration.rb
|
261
236
|
- lib/rspec_api_documentation/example.rb
|
@@ -268,28 +243,27 @@ files:
|
|
268
243
|
- templates/rspec_api_documentation/textile_index.mustache
|
269
244
|
- templates/rspec_api_documentation/html_example.mustache
|
270
245
|
homepage: http://smartlogicsolutions.com
|
271
|
-
licenses:
|
246
|
+
licenses:
|
247
|
+
- MIT
|
248
|
+
metadata: {}
|
272
249
|
post_install_message:
|
273
250
|
rdoc_options: []
|
274
251
|
require_paths:
|
275
252
|
- lib
|
276
253
|
required_ruby_version: !ruby/object:Gem::Requirement
|
277
|
-
none: false
|
278
254
|
requirements:
|
279
|
-
- -
|
255
|
+
- - '>='
|
280
256
|
- !ruby/object:Gem::Version
|
281
257
|
version: '0'
|
282
258
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
283
|
-
none: false
|
284
259
|
requirements:
|
285
|
-
- -
|
260
|
+
- - '>='
|
286
261
|
- !ruby/object:Gem::Version
|
287
262
|
version: 1.3.6
|
288
263
|
requirements: []
|
289
264
|
rubyforge_project:
|
290
|
-
rubygems_version:
|
265
|
+
rubygems_version: 2.0.14
|
291
266
|
signing_key:
|
292
|
-
specification_version:
|
267
|
+
specification_version: 4
|
293
268
|
summary: A double black belt for your docs
|
294
269
|
test_files: []
|
295
|
-
has_rdoc:
|