apitest 0.1.5 → 0.1.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: 81fc56ffb2514081bf6f44b460f844c922f148b5
4
- data.tar.gz: 002c7eddb0329509034747a287b19ba04cd3fb2d
3
+ metadata.gz: 55299bf0b724cded4b82f817901954e4c1341011
4
+ data.tar.gz: 3d81c1087af86bb04afd07a10d473194846ba83f
5
5
  SHA512:
6
- metadata.gz: 0e4b74aebaeb67a44a9b7bfe8b51c07c8265684bfdc9e4714b32b17e26b5fd16db3f7624c6d1beafcde041af168ce28d451f3ea6f27a3b764536c59f0aeaf63d
7
- data.tar.gz: ef145628b987cab510cf778c7157d5d55dcb63983bfac399b2f338f140b4776a02afdc27d4d53167ab9d219a187405fa283815c6a7e5325158a99a0463fbd4d9
6
+ metadata.gz: f3770091a42849fb7d1b622c657fc2a1b72eff6c96196de1614c90feead7b0100b236e72f8e43393397fa98dd351619ff8d416adaac735f537dfc20c0afe06ca
7
+ data.tar.gz: 0e495fccba5f9f3900398425552ae018f50eda845cf7b32363fe510eaea4ec840f2701251f4b17f905692b7d2d9047c9c0f8d7040e4eea8e62710367c56bafaf
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
  Short description and motivation.
3
3
 
4
4
  ## Version
5
- 0.1.5
5
+ 0.1.6
6
6
 
7
7
  ## Installation
8
8
  添加如下代码到 Gemfile:
@@ -33,23 +33,14 @@ $ brew install lsof #MacOS
33
33
 
34
34
  ## Usage
35
35
 
36
- 约定的api目录如下:
37
- ```shell
38
- ├── controllers
39
- │   ├── api
40
- │   │   └── v1
41
- │   │   ├── foo_controller.rb
42
- │   │   ├── bar_controller.rb
43
- │   │   └── v2
44
- │   │   ├── foobar_controller.rb
45
- │   │   ├── barfoo_controller.rb
46
- ```
47
-
48
36
  在routes.rb 配置apitest 目录,比如:
49
37
 
50
38
  ```ruby
39
+ Rails.application.routes.draw do
40
+
51
41
  apitest_for '/apitest'
52
42
 
43
+ end
53
44
  ```
54
45
 
55
46
  浏览器中访问apitest 的url
@@ -57,32 +48,90 @@ $ brew install lsof #MacOS
57
48
  默认api目录为controllers/api,目录可指定
58
49
 
59
50
  ```ruby
51
+ Rails.application.routes.draw do
52
+
60
53
  apitest_for '/apitest' do
61
54
  Apitest::api_dir 'api'
62
55
  end
56
+
57
+ end
63
58
  ```
64
59
 
65
60
  默认使用blue-theme,可指定theme ,theme使用 AdminLTE,直接指定AdminLTE的theme即可:
66
61
 
67
62
  ``` ruby
63
+ Rails.application.routes.draw do
64
+
68
65
  apitest_for '/apitest' do
69
66
  Apitest::theme 'purple-light'
70
67
  end
68
+
69
+ end
71
70
  ```
72
71
  theme列表如下
73
72
  ```
74
- black-light
75
73
  black
76
- blue-light
74
+ black-light
77
75
  blue
78
- green-light
76
+ blue-light
79
77
  green
80
- purple-light
78
+ green-light
81
79
  purple
82
- red-light
80
+ purple-light
83
81
  red
84
- yellow-light
82
+ red-light
85
83
  yellow
84
+ yellow-light
85
+ ```
86
+
87
+ API层级为4级
88
+ Version -> 分类 -> API组 -> API
89
+ 其中Version 由第一级目录决定
90
+ 分类在API中定义,定义方法如下
91
+
92
+ ```ruby
93
+ class Api::V1::BindingTrayController < Api::V1::ApplicationController
94
+ APIDOC = {
95
+ type: '业务API' ,
96
+ group_name: '绑定托盘' ,
97
+ sort: 2 ,
98
+ apis: {
99
+ scan_sn: { #第一条API
100
+ api_name: '扫描sn' ,
101
+ path: '/api/v1/binding_tray/scan_sn' ,
102
+ method: 'get' ,
103
+ params:{
104
+ barcode: {
105
+ text: 'sn条码' ,
106
+ required: true
107
+ } ,
108
+ detail_id: {
109
+ text: '托盘列表id' ,
110
+ }
111
+ }
112
+ } ,
113
+ ... #第二条API
114
+ }
115
+ }
116
+ def scan_sn
117
+ ... #your code
118
+ end
119
+ ```
120
+
121
+ 默认分类为
122
+ ```ruby
123
+ Apitest::default_types [ '业务API' , '工具API' , '辅助API' ]
124
+ ```
125
+ 默认分类可配置,例如:
126
+
127
+ ```ruby
128
+ Rails.application.routes.draw do
129
+
130
+ apitest_for '/apitest' do
131
+ Apitest::default_types [ '银行业务API' , '企业业务API' ]
132
+ end
133
+
134
+ end
86
135
  ```
87
136
 
88
137
 
@@ -90,8 +139,16 @@ yellow
90
139
  ## TODO
91
140
  - [x] 可自定义api目录
92
141
  - [x] 可自定义theme
142
+ - [x] 可配置分类
143
+ - [ ] 可设定所有API都有的必填项,比如token、客户端类型、客户端版本号
93
144
  - [ ] ERROR类工具
94
- - [ ] APIDOC美化
145
+ - [ ] Apitest Example 网站
146
+ - [ ] 使用前端route
147
+ - [ ] 保存API分类收起展开状态
148
+ - [ ] ERROR log 可选输出
149
+ - [ ] 一个token默认机制
150
+ - [ ] 客户端版本号默认升级实例
151
+ - [ ] 操作录屏gif
95
152
  - [ ] 权限控制
96
153
  - [ ] 测试数据准备,测试用例
97
154
  - [ ] 测试中心
@@ -26,13 +26,6 @@ module Apitest
26
26
  @root_url = main_app.root_url[0,main_app.root_url.length - 1]
27
27
  end
28
28
 
29
- def docs_base
30
- {
31
- '业务API' => [] ,
32
- '工具API' => [] ,
33
- '辅助API' => []
34
- }
35
- end
36
29
  def get_doc(path_root = nil)
37
30
  path_root ||= "app/controllers/#{Apitest.api_dir}/"
38
31
  Dir.glob("#{path_root}*").each do |path|
@@ -41,7 +34,7 @@ module Apitest
41
34
  end
42
35
 
43
36
  def get_version_doc(path_root)
44
- docs = docs_base
37
+ docs = Apitest::default_types.clone
45
38
  Dir.glob("#{path_root}/*").each do |path|
46
39
  if File.directory?(path)
47
40
  docs = docs.merge get_version_doc(path)
@@ -1,3 +1,3 @@
1
1
  module Apitest
2
- VERSION = '0.1.5'
2
+ VERSION = '0.1.6'
3
3
  end
data/lib/apitest.rb CHANGED
@@ -12,6 +12,7 @@ require 'websocket-eventmachine-server'
12
12
  module Apitest
13
13
  @api_dir
14
14
  @theme
15
+ @default_types
15
16
 
16
17
  def self.api_dir(dir = nil)
17
18
  @api_dir = dir if dir
@@ -22,7 +23,14 @@ module Apitest
22
23
  @theme = theme if theme
23
24
  @theme
24
25
  end
25
-
26
+
27
+ def self.default_types(default_types = [])
28
+ @default_types ||= {}
29
+ default_types.each do |type|
30
+ @default_types[type] = []
31
+ end
32
+ @default_types
33
+ end
26
34
  def self.start_server_log_listen
27
35
  Process.detach(
28
36
  fork do
@@ -64,8 +72,9 @@ module ActionDispatch::Routing
64
72
  class Mapper
65
73
  def apitest_for(path , &block)
66
74
  mount Apitest::Engine => path
67
- Apitest::api_dir 'api'
68
- Apitest::theme 'blue-light'
75
+ Apitest::api_dir 'api'
76
+ Apitest::theme 'blue-light'
77
+ # Apitest::default_types [ '业务API' , '工具API' , '辅助API' ]
69
78
  block.call
70
79
  end
71
80
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apitest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kyuubi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-21 00:00:00.000000000 Z
11
+ date: 2017-04-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails