接口管理工具、yapi、y-api
软件前提:
- mongodb
 - node.js
 
系统准备,不一定需要
# 禁用selinuxvim /etc/selinux/config将SELINUX=enforcing改为SELINUX=disabled重启系统# 关闭防火墙systemctl stop firewalldsystemctl disable firewalld
基础安装
1. 安装,如果下载github失败,可以手动下载,并安装js包 : npm install --productionnpm install -g yapi-cli2. 启动,如果端口9090被占用,先修改config.json里的portyapi server然后根据提示访问ip:9090 进行配置(默认接口)账号名:"tianyunperfect@gmail.com",密码:"ymfe.org"3.配置vim /root/my-yapi/config.json
启动
npm install pm2 -g# 运行js文件pm2 start /home/alvin/my-yapi/vendors/server/app.js
升级
cd {项目目录}yapi ls //查看版本号列表yapi update //升级到最新版本yapi update -v v1.1.0 //升级到指定版本
浏览器插件
使用浏览器插件才能使用接口测试,解决跨域的问题。
下载后,解压,然后在开发模式下安装。
- 3.3版本:yapi-3.3.zip
 - 掘金文章参考
idea插件:EasyYapi
 
参考:
基础安装和使用
1、搜索安装:EasyYapi
2、在controller Generate… ,记得给controller、函数、字段都加上注释,否则就会默认英文名字了。
提示:第一次使用时,会要求填写yapi地址、token。
3、查看效果
**
管理项目配置
方式一:默认每个项目的配置都会在idea 的 **Preferences(Settings) > Other Settings > EasyApi 中配置。
方式二:在项目目录下新建:.easy.api.config ,参考上图中的Recommend
#yapi mockfield.mock=#mock#小数点后两位float_with_two=@natural(0,10000).@natural(0,100)
配置规则
| 名称 | 类型 | 是否必须 | 默认值 | 备注 | 其他信息 | 
|---|---|---|---|---|---|
| rangeInt | integer | 非必须 | mock: @integer(666,999) | ||
| positiveOrZeroFloat | number | 非必须 | mock: @float(0,88888888,6) | ||
| maxInt | integer | 非必须 | mock: @integer(0,999) | ||
| minInt | integer | 非必须 | mock: @integer(666) | ||
| assertFalse | boolean | 非必须 | mock: false | ||
| maxDouble | number | 非必须 | mock: @float(0,999) | ||
| minDouble | number | 非必须 | mock: @float(666) | ||
| positive | integer | 非必须 | mock: @integer(1,88888888) | ||
| positiveOrZero | integer | 非必须 | mock: @integer(0,88888888) | ||
| str | string | 必须 | |||
| negative | integer | 非必须 | mock: @integer(-888888888,-1) | ||
| rangeFloat | number | 非必须 | mock: @float(66,9999,6) | ||
| assertTrue | boolean | 非必须 | mock: true | ||
| negativeOrZero | integer | 非必须 | mock: @integer(-888888888,0) | ||
| positiveFloat | number | 非必须 | mock: @float(0.01,88888888,6) | ||
| string | 非必须 | mock: @email | 
java示例
import lombok.AllArgsConstructor;import lombok.Data;import java.util.List;@Data@AllArgsConstructorpublic class PageResult<T> {/*** 第几页** @mock 1*/private Integer currentPage;/*** 每页数量** @mock 10*/private Integer pageSize;/*** 总数** @mock @integer(9,99)*/private Long total;private List<T> list;}
