api_doc_generation 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5dd65a3e0535829684cdead694989b6925fc4dc8
4
- data.tar.gz: bed4b14919575ffd572bf54cb505ecad836a5c9a
3
+ metadata.gz: efc63e80bddcc349ab44b58451186d2a8cfbad04
4
+ data.tar.gz: e20a6e3d6621ea10514d813512ef744225556a1d
5
5
  SHA512:
6
- metadata.gz: 049c508ad6dfacf37e953a0150cd805046edea284e31c71636de103aa4172b56f456412c1764588cb9bc73a3b51aece45948c24281a9939c28c000928ff872bb
7
- data.tar.gz: 550ae99b642a1bc4558c0e72f13a14eff8ab04197a729110c822c5ff21874fffcfb792a45d0ee92c9b24a76aac361a3c6161a22e164ae8cea36fb46f1d351cbf
6
+ metadata.gz: 21741fec7a85800ac87c17968e6800fe12a89b1d01e5aefb70bdd97173189006fb751cd6e6ad110c28e0da984c0f2dbfeecb4143457eccb26452a3a024f7777f
7
+ data.tar.gz: 41d826effb4a3f52517c2d5193e76e6bcc36a7b59bb8ac9f8cffc84c365f988291631ffaa7e11d513adda0e31c7aeeadb8740b52e178c85994c8a8df0d36e5e6
data/README.md CHANGED
@@ -20,6 +20,40 @@ Or install it yourself as:
20
20
 
21
21
  `rake doc:api [CODES_PATH=app/controllers/api]`
22
22
 
23
+ __代码注释格式:__
24
+
25
+ ```
26
+ class Api::UsersController < class Api::BaseController
27
+ # 取得所有用户
28
+ #
29
+ # Params:
30
+ # page: [Integer] 页数
31
+ # perpage: [Integer] 每页数量
32
+ # Return:
33
+ # count: [Integer] 数据总条数
34
+ # items: [Array] 当前页数据的数组
35
+ def list
36
+ # ...
37
+ end
38
+
39
+ # (api说明)取得一个用户的信息
40
+ #
41
+ # Params:
42
+ # user_id: [String] 用户的id
43
+ # Return:
44
+ # name: [String] xxx
45
+ # Error:
46
+ # info: [String] 自己定义的错误信息
47
+ # other: [String] 如果不设置的,将生成默认的
48
+ def show
49
+ # ...
50
+ end
51
+ end
52
+ ```
53
+
54
+ 上面已经给出了api说明,参数,返回,错误信息,而api地址和请求方法将会自动从Rails中查找出来
55
+
56
+
23
57
  ## Contributing
24
58
 
25
59
  1. Fork it
@@ -1,3 +1,3 @@
1
1
  module ApiDocGeneration
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -54,7 +54,7 @@ module ApiDocGeneration; class ViewHelper
54
54
  end
55
55
 
56
56
 
57
- def format_error_param(param)
57
+ def format_response_param(param)
58
58
  return unless param[:val].to_s =~ /^\s*$/
59
59
 
60
60
  case param[:name]
@@ -108,16 +108,16 @@
108
108
  <div class='action action-<%= i % 2 == 0 ? 'even' : 'odd' %>'
109
109
  id='<%= action_identifer(controller[:klass], action[:name]) %>'>
110
110
 
111
- <strong>功能说明</strong>
112
- <p class='about'><%= action[:desc] %></p>
111
+ <h4>功能说明</h4>
112
+ <p class='about text-info'><%= action[:desc] %></p>
113
113
 
114
- <strong>请求地址</strong>
115
- <p class='about'><%= action[:path] %></p>
114
+ <h4>请求地址</h4>
115
+ <p class='about text-info'><%= action[:path] %></p>
116
116
 
117
- <strong>请求方法</strong>
118
- <p class='about'><%= action[:method] %></p>
117
+ <h4>请求方法</h4>
118
+ <p class='about text-info'><%= action[:method] %></p>
119
119
 
120
- <strong>参数说明</strong>
120
+ <h4>参数说明</h4>
121
121
  <table class='table table-bordered table-striped'>
122
122
  <thead>
123
123
  <th>参数名</th>
@@ -149,7 +149,8 @@
149
149
  </tbody>
150
150
  </table>
151
151
 
152
- <strong>正常返回信息</strong>
152
+ <h4>正常返回信息</h4>
153
+ <p class='about text-info'>正常完成时response.status 为 200.</p>
153
154
  <table class='table table-bordered table-striped'>
154
155
  <thead>
155
156
  <th>参数名</th>
@@ -159,7 +160,7 @@
159
160
 
160
161
  <tbody>
161
162
  <% (action['Return'] || []).each do |param| %>
162
- <% format_error_param(param) %>
163
+ <% format_response_param(param) %>
163
164
 
164
165
  <tr>
165
166
  <% [:name, :type, :val].each do |key| %>
@@ -170,18 +171,27 @@
170
171
  </tbody>
171
172
  </table>
172
173
 
173
- <strong>出错误时信息</strong>
174
- <p class='about'>
175
- 出错时response.status 400.
174
+ <h4>出错误时信息</h4>
175
+ <p class='about text-info'>出错时response.status 为 400.</p>
176
+ <table class='table table-bordered table-striped'>
177
+ <thead>
178
+ <th>参数名</th>
179
+ <th>参数类型</th>
180
+ <th>描述</th>
181
+ </thead>
176
182
 
177
- <table class='table table-bordered table-striped'>
178
- <thead>
179
- <th>参数名</th>
180
- <th>参数类型</th>
181
- <th>描述</th>
182
- </thead>
183
+ <tbody>
184
+ <% if action['Error'] %>
185
+ <% action['Error'].each do |param| %>
186
+ <% format_response_param(param) %>
183
187
 
184
- <tbody>
188
+ <tr>
189
+ <% [:name, :type, :val].each do |key| %>
190
+ <td><%= param[key] %></td>
191
+ <% end %>
192
+ </tr>
193
+ <% end %>
194
+ <% else %>
185
195
  <tr>
186
196
  <td>error</td>
187
197
  <td>String</td>
@@ -193,10 +203,9 @@
193
203
  <td>String</td>
194
204
  <td>错误具体描述</td>
195
205
  </tr>
196
- </tbody>
197
- </table>
198
-
199
- </p>
206
+ <% end %>
207
+ </tbody>
208
+ </table>
200
209
 
201
210
  <br /><hr />
202
211
  </div>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api_doc_generation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - jiangzhi.xie