什么是 postman
postman 是一款 rest 接口调试工具
image.png
什么是rap
RAP是一个可视化接口管理工具 通过分析接口结构,动态生成模拟数据,校验真实接口正确性, 围绕接口定义,通过一系列自动化工具提升我们的协作效率。我们的口号:提高效率,回家吃晚饭!
image.png相关性
postman 是我们开发调试 的一个工具而 rap 可以作为我们团队文档分享的一款工具他们有很多相似之处,作为程序猿懒是必须的,如果太勤奋了就不要做程序了..
下面我们看看怎么将postman 文件转入到rap上面去
开发nodejs命令行工具
#!/usr/bin/env node
let path = process.argv[2];
console.log(path);
const fs = require('fs');
let postMan = JSON.parse(fs.readFileSync(path, "utf-8"));
console.log("加载postman配置文件成功")
let rap = {
"moduleList": [{
"name": "某模块(点击编辑后双击修改)",
"id": 108,
"pageList": [],
"id": 166,
"introduction": ""
}
],
"introduction": ""
};
rap.moduleList[0].name = postMan.info.name;
rap.moduleList[0].introduction = postMan.info.description;
let items = {
"name": "默认",
"description": "未分类",
item: []
};
for (let item of postMan.item) {
if ('request' in item) {
items.item.push(item);
}
}
postMan.item.push(items);
for (let item of postMan.item) {
// 一级
if ('request' in item) {
continue;
}
// 文件夹--- >page
let page = {
"id": 0,
"name": "",
"introduction": "",
actionList: []
};
page.name = item.name;
page.description = item.description;
for (let request of item.item) {
//请求项目
let action = {
"responseParameterList": [],
"responseTemplate": "",
"requestParameterList": [],
"requestType": "2",
"requestUrl": "/restful/leavingMessageProxyService/add",
"name": "01添加留言",
"description": "",
"id": 762
};
action.name = request.name;
action.uri = request.request.url;
let method = 1;
switch (request.request.method) {
// 1.GET 2.POST 3.PUT 4.DELETE
case "GET":
method = 1;
break;
case "POST":
method = 2;
break;
case "PUT":
method = 3;
break;
case "DELETE":
method = 4;
break;
}
action.requestType = method;
// 请求参数
for (let rp of request.request.body.urlencoded) {
let request = {
"identifier": "userId",
"dataType": "string",
"name": "发布者",
"validator": "",
"parameterList": [],
"remark": "",
"id": 13083
};
request.identifier = rp.key;
request.name = rp.description;
action.requestParameterList.push(request)
}
page.actionList.push(action);
}
rap.moduleList[0].pageList.push(page);
}
let b = {"modelJSON": JSON.stringify(rap)};
fs.writeFileSync(path.replace('postman_collection.', ''), JSON.stringify(b), "utf-8")
console.log("导出成功")
导出 postman配置文件
- image.png
- image.png
- 执行上面我们的命令
- 将结果文件导出rap中
网友评论