autodoc 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +2 -1
- data/lib/autodoc/configuration.rb +6 -2
- data/lib/autodoc/document.rb +38 -8
- data/lib/autodoc/version.rb +1 -1
- data/spec/dummy/app/controllers/recipes_controller.rb +1 -1
- data/spec/dummy/doc/entries.md +9 -1
- data/spec/dummy/doc/recipes.md +19 -16
- data/spec/requests/entries_spec.rb +1 -1
- data/spec/requests/recipes_spec.rb +9 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac859dfcddee9d293290317ff4039da04edd3eed
|
4
|
+
data.tar.gz: f752329167fe44b3b7f6db9938bf2f80122239a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af8b5f8a3d932fc51013b591ed3968648f512e0b4365ef96cfc526b57332ccd3f59d1b7e1dce0e64d6cbb9d3e3cdd87f7fe09fa60a969fa881391913e63b0600
|
7
|
+
data.tar.gz: b1f555f70b33527afd368f57ab1127b8ef2a882655240027627643748c1e5837cb3466de5c4960f3533033de42f9241082f7c2e7727a06fc9a1c5f37f32bdeaf
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -49,7 +49,8 @@ end
|
|
49
49
|
You can configure `Autodoc.configuration` to change its behavior:
|
50
50
|
|
51
51
|
* path - [String] location to put files (default: ./doc)
|
52
|
-
*
|
52
|
+
* suppressed_request_header - [Strings] filtered request header keys
|
53
|
+
* suppressed_response_header - [Strings] filtered response header keys
|
53
54
|
* template - [String] ERB template for each document (default: [document.md.erb](https://github.com/r7kamura/autodoc/blob/master/lib/autodoc/templates/document.md.erb))
|
54
55
|
* toc_template - [String] ERB template for ToC (default: [toc.md.erb](https://github.com/r7kamura/autodoc/blob/master/lib/autodoc/templates/toc.md.erb))
|
55
56
|
* toc - [Boolean] whether to generate toc.md (default: false)
|
data/lib/autodoc/document.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "action_dispatch/http/request"
|
2
|
+
require "active_support/core_ext/hash/slice"
|
2
3
|
require "active_support/core_ext/string/strip"
|
3
4
|
require "uri"
|
4
5
|
require "erb"
|
@@ -63,7 +64,9 @@ module Autodoc
|
|
63
64
|
table = request_header_from_fixed_keys
|
64
65
|
table.merge!(request_header_from_http_prefix)
|
65
66
|
table.reject! {|key, value| value.blank? }
|
66
|
-
table.map {|key, value| [key.split(?_).map(&:downcase).map(&:camelize).join(?-), value]
|
67
|
+
table = Hash[table.map {|key, value| [key.split(?_).map(&:downcase).map(&:camelize).join(?-), value] }]
|
68
|
+
table.except!(*Autodoc.configuration.suppressed_request_header)
|
69
|
+
table.map {|key, value| [key, value].join(": ") }.sort.join("\n")
|
67
70
|
end
|
68
71
|
|
69
72
|
def request_header_from_http_prefix
|
@@ -89,11 +92,26 @@ module Autodoc
|
|
89
92
|
end
|
90
93
|
|
91
94
|
def request_body_section
|
92
|
-
"\n\n#{request_body}"
|
95
|
+
"\n\n#{request_body}" if request_body.present?
|
93
96
|
end
|
94
97
|
|
95
98
|
def request_body
|
96
|
-
|
99
|
+
if instance_variable_defined?(:@request_body)
|
100
|
+
@request_body
|
101
|
+
else
|
102
|
+
@request_body = begin
|
103
|
+
if request.headers["Content-Type"].try(:include?, "application/json")
|
104
|
+
request_body_parsed_as_json
|
105
|
+
else
|
106
|
+
request.body.string
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def request_body_parsed_as_json
|
113
|
+
JSON.pretty_generate(JSON.parse(request.body.string))
|
114
|
+
rescue JSON::ParserError
|
97
115
|
end
|
98
116
|
|
99
117
|
def response_http_version
|
@@ -101,7 +119,9 @@ module Autodoc
|
|
101
119
|
end
|
102
120
|
|
103
121
|
def response_header
|
104
|
-
response.headers.
|
122
|
+
table = response.headers.clone
|
123
|
+
table.except!(*Autodoc.configuration.suppressed_response_header)
|
124
|
+
table.map {|key, value| [key, value].join(": ") }.sort.join("\n")
|
105
125
|
end
|
106
126
|
|
107
127
|
def response_header_from_fixed_keys
|
@@ -117,12 +137,22 @@ module Autodoc
|
|
117
137
|
end
|
118
138
|
|
119
139
|
def response_body
|
120
|
-
if
|
121
|
-
|
140
|
+
if instance_variable_defined?(:@response_body)
|
141
|
+
@response_body
|
122
142
|
else
|
123
|
-
|
143
|
+
@response_body = begin
|
144
|
+
if response.header["Content-Type"].try(:include?, "application/json")
|
145
|
+
response_body_parsed_as_json
|
146
|
+
else
|
147
|
+
response.body
|
148
|
+
end
|
149
|
+
end
|
124
150
|
end
|
125
|
-
|
151
|
+
end
|
152
|
+
|
153
|
+
def response_body_parsed_as_json
|
154
|
+
JSON.pretty_generate(JSON.parse(response.body))
|
155
|
+
rescue JSON::ParserError
|
126
156
|
end
|
127
157
|
|
128
158
|
def controller
|
data/lib/autodoc/version.rb
CHANGED
data/spec/dummy/doc/entries.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
## GET /entries
|
2
2
|
Returns entries.
|
3
3
|
|
4
|
-
|
4
|
+
### Example
|
5
5
|
```
|
6
6
|
GET /entries HTTP/1.1
|
7
7
|
Accept: application/json
|
@@ -12,4 +12,12 @@ Host: example.org
|
|
12
12
|
```
|
13
13
|
HTTP/1.1 200
|
14
14
|
Content-Length: 45
|
15
|
+
Content-Type: application/json
|
16
|
+
|
17
|
+
[
|
18
|
+
{
|
19
|
+
"title": "Test Title",
|
20
|
+
"body": "Lorem Ipsum"
|
21
|
+
}
|
22
|
+
]
|
15
23
|
```
|
data/spec/dummy/doc/recipes.md
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
## GET /recipes/:id
|
2
2
|
Returns the recipe.
|
3
3
|
|
4
|
-
|
4
|
+
### Example
|
5
5
|
```
|
6
6
|
GET /recipes/:id HTTP/1.1
|
7
|
-
Accept: application/json
|
8
7
|
Content-Length: 0
|
8
|
+
Content-Type: application/json
|
9
9
|
Host: example.org
|
10
10
|
```
|
11
11
|
|
@@ -14,11 +14,11 @@ HTTP/1.1 200
|
|
14
14
|
Cache-Control: max-age=0, private, must-revalidate
|
15
15
|
Content-Length: 111
|
16
16
|
Content-Type: application/json; charset=utf-8
|
17
|
-
ETag: "
|
17
|
+
ETag: "082bd55a40d73aebcc3f6227e98dcebb"
|
18
18
|
X-Content-Type-Options: nosniff
|
19
19
|
X-Frame-Options: SAMEORIGIN
|
20
|
-
X-Request-Id:
|
21
|
-
X-Runtime: 0.
|
20
|
+
X-Request-Id: 1ced421d-4c76-44cf-bf5b-241358f73311
|
21
|
+
X-Runtime: 0.038226
|
22
22
|
X-UA-Compatible: chrome=1
|
23
23
|
X-XSS-Protection: 1; mode=block
|
24
24
|
|
@@ -26,8 +26,8 @@ X-XSS-Protection: 1; mode=block
|
|
26
26
|
"id": 1,
|
27
27
|
"name": "test",
|
28
28
|
"type": 2,
|
29
|
-
"created_at": "2013-12-
|
30
|
-
"updated_at": "2013-12-
|
29
|
+
"created_at": "2013-12-17T09:17:20.775Z",
|
30
|
+
"updated_at": "2013-12-17T09:17:20.775Z"
|
31
31
|
}
|
32
32
|
```
|
33
33
|
|
@@ -42,15 +42,18 @@ recipe!
|
|
42
42
|
* `name` string (required, except: `["alice", "bob"]`)
|
43
43
|
* `type` integer (only: `1..3`)
|
44
44
|
|
45
|
-
|
45
|
+
### Example
|
46
46
|
```
|
47
47
|
POST /recipes HTTP/1.1
|
48
48
|
Accept: application/json
|
49
|
-
Content-Length:
|
50
|
-
Content-Type: application/
|
49
|
+
Content-Length: 24
|
50
|
+
Content-Type: application/json
|
51
51
|
Host: www.example.com
|
52
52
|
|
53
|
-
|
53
|
+
{
|
54
|
+
"name": "name",
|
55
|
+
"type": 1
|
56
|
+
}
|
54
57
|
```
|
55
58
|
|
56
59
|
```
|
@@ -58,12 +61,12 @@ HTTP/1.1 201
|
|
58
61
|
Cache-Control: max-age=0, private, must-revalidate
|
59
62
|
Content-Length: 111
|
60
63
|
Content-Type: application/json; charset=utf-8
|
61
|
-
ETag: "
|
64
|
+
ETag: "1220735207c1ff5203a3c8975649d37a"
|
62
65
|
Location: http://www.example.com/recipes/1
|
63
66
|
X-Content-Type-Options: nosniff
|
64
67
|
X-Frame-Options: SAMEORIGIN
|
65
|
-
X-Request-Id:
|
66
|
-
X-Runtime: 0.
|
68
|
+
X-Request-Id: b1fded86-bbc2-4442-9fa2-d9536bd55dd4
|
69
|
+
X-Runtime: 0.006243
|
67
70
|
X-UA-Compatible: chrome=1
|
68
71
|
X-XSS-Protection: 1; mode=block
|
69
72
|
|
@@ -71,7 +74,7 @@ X-XSS-Protection: 1; mode=block
|
|
71
74
|
"id": 1,
|
72
75
|
"name": "name",
|
73
76
|
"type": 1,
|
74
|
-
"created_at": "2013-12-
|
75
|
-
"updated_at": "2013-12-
|
77
|
+
"created_at": "2013-12-17T09:17:20.858Z",
|
78
|
+
"updated_at": "2013-12-17T09:17:20.858Z"
|
76
79
|
}
|
77
80
|
```
|
@@ -2,7 +2,7 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe "Recipes" do
|
4
4
|
let(:env) do
|
5
|
-
{ "
|
5
|
+
{ "ACCEPT" => "application/json", "CONTENT_TYPE" => "application/json" }
|
6
6
|
end
|
7
7
|
|
8
8
|
let(:params) do
|
@@ -15,6 +15,10 @@ describe "Recipes" do
|
|
15
15
|
end
|
16
16
|
|
17
17
|
context "with valid condition (using Rack::Test)", :autodoc do
|
18
|
+
before do
|
19
|
+
env["Content-Type"] = "application/json"
|
20
|
+
end
|
21
|
+
|
18
22
|
include Rack::Test::Methods
|
19
23
|
|
20
24
|
it "returns the recipe" do
|
@@ -36,7 +40,7 @@ describe "Recipes" do
|
|
36
40
|
end
|
37
41
|
|
38
42
|
it "returns 400" do
|
39
|
-
post "/recipes", params, env
|
43
|
+
post "/recipes", params.to_json, env
|
40
44
|
response.status.should == 400
|
41
45
|
end
|
42
46
|
end
|
@@ -47,7 +51,7 @@ describe "Recipes" do
|
|
47
51
|
end
|
48
52
|
|
49
53
|
it "returns 400" do
|
50
|
-
post "/recipes", params, env
|
54
|
+
post "/recipes", params.to_json, env
|
51
55
|
response.status.should == 400
|
52
56
|
end
|
53
57
|
end
|
@@ -58,7 +62,7 @@ describe "Recipes" do
|
|
58
62
|
end
|
59
63
|
|
60
64
|
it "creates a new recipe" do
|
61
|
-
post "/recipes", params, env
|
65
|
+
post "/recipes", params.to_json, env
|
62
66
|
response.status.should == 201
|
63
67
|
end
|
64
68
|
end
|
@@ -74,7 +78,7 @@ describe "Recipes" do
|
|
74
78
|
end
|
75
79
|
|
76
80
|
it "creates a new recipe" do
|
77
|
-
post "/recipes", params, env
|
81
|
+
post "/recipes", params.to_json, env
|
78
82
|
response.status.should == 201
|
79
83
|
end
|
80
84
|
end
|