1 | ## 简介
|
2 | * 生成文档do **"c"**
|
3 | * 生成mo **"c"** k server
|
4 | * 校验服务器返回数据**"c"** heck
|
5 |
|
6 | ## 安装
|
7 |
|
8 | ```
|
9 | (sudo) npm install 3c -g
|
10 | ```
|
11 |
|
12 | ## 使用原则
|
13 | 约定大于配置
|
14 | 尽量按照demo书写
|
15 | 否则不保证..
|
16 |
|
17 | ## 使用
|
18 | ### 初始化
|
19 | > 3c -i 或者 3c --init
|
20 |
|
21 | 环境初始化 生成对应的3个目录
|
22 |
|
23 | #### doc: 存放生成的文档
|
24 |
|
25 | 默认是doc/api.md
|
26 |
|
27 | #### schema: 配置文件和接口json-schema文件
|
28 | - config.json: 配置文件
|
29 |
|
30 | ```
|
31 | {
|
32 | "files": ["demo"], //接口 schema 文件位置
|
33 | "format": "format/format", //特殊匹配规则 文件
|
34 | "doc": "doc/api.md", //生成文档位置
|
35 | "port": 1234, //mock server端口
|
36 | "forceError": false, //是否强制mock server请求失败 并 访问失败的数据
|
37 | "errorCode": 500 //mock server请求失败时的http code
|
38 | }
|
39 | ```
|
40 | - demo.js: schema栗子
|
41 |
|
42 | - 简单的schema可以搞定
|
43 | - 暂时不支持比较碉堡的 oneOf allOf $ref..等等
|
44 | - 可以设置默认值 default
|
45 |
|
46 | ```
|
47 | module.exports = [
|
48 | meta: #接口相关基本藐视
|
49 | title: 'test' #接口名称
|
50 | description: 'just for test' #接口描述
|
51 | host: 'http://localhost:1234'
|
52 | uri: '/test'
|
53 | method: 'get'
|
54 |
|
55 | params: #请求参数
|
56 | type: 'object'
|
57 | properties:
|
58 | token:
|
59 | type: 'string'
|
60 | required: ['token']
|
61 |
|
62 | success: #请求成功
|
63 | type: 'object'
|
64 | required: ['array']
|
65 | properties:
|
66 | array:
|
67 | type: 'array'
|
68 | minItems: 8
|
69 | maxItems: 10
|
70 | items:
|
71 | type: 'object'
|
72 | required: ['id','name']
|
73 | properties:
|
74 | id:
|
75 | type: 'integer'
|
76 | description: 'id'
|
77 | name:
|
78 | type: 'string'
|
79 | description: '姓名'
|
80 | default: 'hello world'
|
81 |
|
82 | error: #请求失败
|
83 | type: 'object'
|
84 | properties:
|
85 | code:
|
86 | type: 'integer'
|
87 | msg:
|
88 | type: 'string'
|
89 | required: ['code']
|
90 | ]
|
91 |
|
92 | ```
|
93 |
|
94 |
|
95 | ### 生成文档
|
96 | > 3c -d 或者 3c --doc
|
97 |
|
98 | 按照schema 目录下的配置文件和json-schema文件 生成api文档
|
99 |
|
100 | ### 启动mock server
|
101 |
|
102 | > 3c -m 或者 3c --mock
|
103 |
|
104 | mock server 默认1234端口
|
105 |
|
106 | ### 数据校验
|
107 |
|
108 | > 3c -c 或者 3c --check
|
109 |
|
110 | check server 默认4321端口
|
111 | 浏览器打开 http://localhost:4321
|
112 | 进行校验
|
113 |
|
114 |
|
115 | ## Hava fun!
|