autodoc 0.2.8 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/autodoc.gemspec +1 -0
- data/lib/autodoc/document.rb +59 -29
- data/lib/autodoc/templates/document.md.erb +7 -7
- data/lib/autodoc/version.rb +1 -1
- data/spec/dummy/doc/entries.md +8 -12
- data/spec/dummy/doc/recipes.md +47 -20
- data/spec/requests/recipes_spec.rb +9 -0
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7205ed893f52f005d0dd0da6f6ce4e4791bdcdc6
|
4
|
+
data.tar.gz: 8bdb613feb1e8063aa1f859d0d7ab0d09f2229bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 366c405aaf5bd5413ac7bf06683770f345cdd9e5dcceadda5f7ff168c02a474b453019d8d051d8332bb9e3a52bdcbfe922ab8a0fe8e33f7ffba2054454464f39
|
7
|
+
data.tar.gz: 42a6d8a5717c00d7b3bdb51147d7a3583b33e491cd4d2b46f098b2730d9c5e717bae950e1745c2a552f44d259df882e539325387273df77f222c68ce3819fe38
|
data/CHANGELOG.md
CHANGED
data/autodoc.gemspec
CHANGED
@@ -17,6 +17,7 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
18
|
spec.require_paths = ["lib"]
|
19
19
|
|
20
|
+
spec.add_dependency "activesupport", ">= 3.0.0"
|
20
21
|
spec.add_dependency "actionpack"
|
21
22
|
spec.add_dependency "rspec"
|
22
23
|
spec.add_development_dependency "bundler", "~> 1.3"
|
data/lib/autodoc/document.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "action_dispatch/http/request"
|
2
|
+
require "active_support/core_ext/string/strip"
|
2
3
|
require "uri"
|
3
4
|
require "erb"
|
4
5
|
require "pathname"
|
@@ -58,24 +59,70 @@ module Autodoc
|
|
58
59
|
request.method
|
59
60
|
end
|
60
61
|
|
62
|
+
def request_header
|
63
|
+
table = request_header_from_fixed_keys
|
64
|
+
table.merge!(request_header_from_http_prefix)
|
65
|
+
table.reject! {|key, value| value.blank? }
|
66
|
+
table.map {|key, value| [key.split(?_).map(&:downcase).map(&:camelize).join(?-), value].join(": ") }.sort.join("\n")
|
67
|
+
end
|
68
|
+
|
69
|
+
def request_header_from_http_prefix
|
70
|
+
request.headers.inject({}) do |table, (key, value)|
|
71
|
+
if key.start_with?("HTTP_")
|
72
|
+
table.merge(key.gsub(/^HTTP_/, "") => value)
|
73
|
+
else
|
74
|
+
table
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def request_header_from_fixed_keys
|
80
|
+
request.headers.env.slice("CONTENT_TYPE", "CONTENT_LENGTH", "LOCATION")
|
81
|
+
end
|
82
|
+
|
83
|
+
def request_http_version
|
84
|
+
request.env["HTTP_VERSION"] || "HTTP/1.1"
|
85
|
+
end
|
86
|
+
|
61
87
|
def request_query
|
62
88
|
"?#{URI.unescape(request.query_string)}" unless request.query_string.empty?
|
63
89
|
end
|
64
90
|
|
91
|
+
def request_body_section
|
92
|
+
"\n\n#{request_body}" unless request_body.empty?
|
93
|
+
end
|
94
|
+
|
65
95
|
def request_body
|
66
96
|
request.body.string
|
67
97
|
end
|
68
98
|
|
69
|
-
def
|
70
|
-
response.
|
99
|
+
def response_http_version
|
100
|
+
response.env["HTTP_VERSION"] || "HTTP/1.1"
|
101
|
+
end
|
102
|
+
|
103
|
+
def response_header
|
104
|
+
response.headers.map {|key, value| [key, value].join(": ") }.sort.join("\n")
|
105
|
+
end
|
106
|
+
|
107
|
+
def response_header_from_fixed_keys
|
108
|
+
response.headers.env.slice("CONTENT_TYPE", "CONTENT_LENGTH", "LOCATION")
|
109
|
+
end
|
110
|
+
|
111
|
+
def response_http_version
|
112
|
+
response.header["HTTP_VERSION"] || "HTTP/1.1"
|
71
113
|
end
|
72
114
|
|
73
|
-
def
|
74
|
-
|
115
|
+
def response_body_section
|
116
|
+
"\n\n#{response_body}" if response_body.present?
|
75
117
|
end
|
76
118
|
|
77
|
-
def
|
78
|
-
response.
|
119
|
+
def response_body
|
120
|
+
if response.header["Content-Type"].include?("application/json")
|
121
|
+
JSON.pretty_generate(JSON.parse(response.body))
|
122
|
+
else
|
123
|
+
response.body
|
124
|
+
end
|
125
|
+
rescue
|
79
126
|
end
|
80
127
|
|
81
128
|
def controller
|
@@ -95,27 +142,20 @@ module Autodoc
|
|
95
142
|
end
|
96
143
|
|
97
144
|
def description
|
98
|
-
|
145
|
+
if @context.respond_to?(:description)
|
146
|
+
@context.description.strip_heredoc
|
147
|
+
else
|
148
|
+
"#{@context.example.description.capitalize}."
|
149
|
+
end
|
99
150
|
end
|
100
151
|
|
101
152
|
def path
|
102
153
|
@context.example.full_description[%r<(GET|POST|PUT|DELETE) ([^ ]+)>, 2]
|
103
154
|
end
|
104
155
|
|
105
|
-
def response_body
|
106
|
-
"\n" + JSON.pretty_generate(JSON.parse(response_body_raw))
|
107
|
-
rescue JSON::ParserError
|
108
|
-
end
|
109
|
-
|
110
|
-
def request_body_section
|
111
|
-
if has_request_body?
|
112
|
-
"\n```\n#{request_body}\n```\n"
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
156
|
def parameters_section
|
117
157
|
if has_validators? && parameters.present?
|
118
|
-
"\n###
|
158
|
+
"\n### Parameters\n#{parameters}\n"
|
119
159
|
end
|
120
160
|
end
|
121
161
|
|
@@ -123,10 +163,6 @@ module Autodoc
|
|
123
163
|
validators.map {|validator| Parameter.new(validator) }.join("\n")
|
124
164
|
end
|
125
165
|
|
126
|
-
def has_request_body?
|
127
|
-
request_body.present?
|
128
|
-
end
|
129
|
-
|
130
166
|
def has_validators?
|
131
167
|
!!(defined?(WeakParameters) && validators)
|
132
168
|
end
|
@@ -135,12 +171,6 @@ module Autodoc
|
|
135
171
|
WeakParameters.stats[controller][action].try(:validators)
|
136
172
|
end
|
137
173
|
|
138
|
-
def response_headers
|
139
|
-
Autodoc.configuration.headers.map do |header|
|
140
|
-
"\n#{header}: #{response_header(header)}" if response_header(header)
|
141
|
-
end.compact.join
|
142
|
-
end
|
143
|
-
|
144
174
|
class Parameter
|
145
175
|
attr_reader :validator
|
146
176
|
|
@@ -2,13 +2,13 @@
|
|
2
2
|
## <%= title %>
|
3
3
|
<%= description %>
|
4
4
|
<%= parameters_section %>
|
5
|
-
###
|
5
|
+
### Example
|
6
6
|
```
|
7
|
-
<%= method %> <%= path %><%= request_query %>
|
7
|
+
<%= method %> <%= path %><%= request_query %> <%= request_http_version %>
|
8
|
+
<%= request_header %><%= request_body_section %>
|
8
9
|
```
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
response: <%= response_body %>
|
10
|
+
|
11
|
+
```
|
12
|
+
<%= response_http_version %> <%= response.status %>
|
13
|
+
<%= response_header %><%= response_body_section %>
|
14
14
|
```
|
data/lib/autodoc/version.rb
CHANGED
data/spec/dummy/doc/entries.md
CHANGED
@@ -1,19 +1,15 @@
|
|
1
1
|
## GET /entries
|
2
2
|
Returns entries.
|
3
3
|
|
4
|
-
|
4
|
+
## Example
|
5
5
|
```
|
6
|
-
GET /entries
|
6
|
+
GET /entries HTTP/1.1
|
7
|
+
Accept: application/json
|
8
|
+
Content-Length: 0
|
9
|
+
Host: example.org
|
7
10
|
```
|
8
11
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
response:
|
13
|
-
[
|
14
|
-
{
|
15
|
-
"title": "Test Title",
|
16
|
-
"body": "Lorem Ipsum"
|
17
|
-
}
|
18
|
-
]
|
12
|
+
```
|
13
|
+
HTTP/1.1 200
|
14
|
+
Content-Length: 45
|
19
15
|
```
|
data/spec/dummy/doc/recipes.md
CHANGED
@@ -1,50 +1,77 @@
|
|
1
1
|
## GET /recipes/:id
|
2
2
|
Returns the recipe.
|
3
3
|
|
4
|
-
|
4
|
+
## Example
|
5
5
|
```
|
6
|
-
GET /recipes/:id
|
6
|
+
GET /recipes/:id HTTP/1.1
|
7
|
+
Accept: application/json
|
8
|
+
Content-Length: 0
|
9
|
+
Host: example.org
|
7
10
|
```
|
8
11
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
12
|
+
```
|
13
|
+
HTTP/1.1 200
|
14
|
+
Cache-Control: max-age=0, private, must-revalidate
|
15
|
+
Content-Length: 111
|
16
|
+
Content-Type: application/json; charset=utf-8
|
17
|
+
ETag: "349ed81d084907a8583a84c1643c4f26"
|
18
|
+
X-Content-Type-Options: nosniff
|
19
|
+
X-Frame-Options: SAMEORIGIN
|
20
|
+
X-Request-Id: 52ca31ee-4b32-4bdd-ae9e-fed8badaa9b7
|
21
|
+
X-Runtime: 0.023516
|
22
|
+
X-UA-Compatible: chrome=1
|
23
|
+
X-XSS-Protection: 1; mode=block
|
24
|
+
|
13
25
|
{
|
14
26
|
"id": 1,
|
15
27
|
"name": "test",
|
16
28
|
"type": 2,
|
17
|
-
"created_at": "2013-12-
|
18
|
-
"updated_at": "2013-12-
|
29
|
+
"created_at": "2013-12-17T08:32:27.415Z",
|
30
|
+
"updated_at": "2013-12-17T08:32:27.415Z"
|
19
31
|
}
|
20
32
|
```
|
21
33
|
|
22
34
|
## POST /recipes
|
23
|
-
Creates
|
35
|
+
Creates
|
36
|
+
a
|
37
|
+
new
|
38
|
+
recipe!
|
24
39
|
|
25
|
-
|
40
|
+
|
41
|
+
### Parameters
|
26
42
|
* `name` string (required, except: `["alice", "bob"]`)
|
27
43
|
* `type` integer (only: `1..3`)
|
28
44
|
|
29
|
-
|
30
|
-
```
|
31
|
-
POST /recipes
|
45
|
+
## Example
|
32
46
|
```
|
47
|
+
POST /recipes HTTP/1.1
|
48
|
+
Accept: application/json
|
49
|
+
Content-Length: 16
|
50
|
+
Content-Type: application/x-www-form-urlencoded
|
51
|
+
Host: www.example.com
|
33
52
|
|
34
|
-
```
|
35
53
|
name=name&type=1
|
36
54
|
```
|
37
55
|
|
38
|
-
|
39
|
-
|
40
|
-
|
56
|
+
```
|
57
|
+
HTTP/1.1 201
|
58
|
+
Cache-Control: max-age=0, private, must-revalidate
|
59
|
+
Content-Length: 111
|
60
|
+
Content-Type: application/json; charset=utf-8
|
61
|
+
ETag: "fca9b8e000ef821607eda6104ceec86b"
|
41
62
|
Location: http://www.example.com/recipes/1
|
42
|
-
|
63
|
+
X-Content-Type-Options: nosniff
|
64
|
+
X-Frame-Options: SAMEORIGIN
|
65
|
+
X-Request-Id: 27e3eef6-2d84-479c-999e-a1142f7ecc74
|
66
|
+
X-Runtime: 0.005600
|
67
|
+
X-UA-Compatible: chrome=1
|
68
|
+
X-XSS-Protection: 1; mode=block
|
69
|
+
|
43
70
|
{
|
44
71
|
"id": 1,
|
45
72
|
"name": "name",
|
46
73
|
"type": 1,
|
47
|
-
"created_at": "2013-12-
|
48
|
-
"updated_at": "2013-12-
|
74
|
+
"created_at": "2013-12-17T08:32:27.475Z",
|
75
|
+
"updated_at": "2013-12-17T08:32:27.475Z"
|
49
76
|
}
|
50
77
|
```
|
@@ -64,6 +64,15 @@ describe "Recipes" do
|
|
64
64
|
end
|
65
65
|
|
66
66
|
context "with valid condition", :autodoc do
|
67
|
+
let(:description) do
|
68
|
+
<<-EOS
|
69
|
+
Creates
|
70
|
+
a
|
71
|
+
new
|
72
|
+
recipe!
|
73
|
+
EOS
|
74
|
+
end
|
75
|
+
|
67
76
|
it "creates a new recipe" do
|
68
77
|
post "/recipes", params, env
|
69
78
|
response.status.should == 201
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: autodoc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryo Nakamura
|
@@ -10,6 +10,20 @@ bindir: bin
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2013-12-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.0.0
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: actionpack
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|