mirror of
https://github.com/YMFE/yapi.git
synced 2025-04-06 15:00:26 +08:00
opti: swagger 导入自动增加 basePath 到项目配置
This commit is contained in:
parent
2fb5dd9963
commit
25b6682cc6
@ -2,6 +2,7 @@
|
||||
* 改善 swagger 自动导入,不再支持秒级别的 cron 表达式,默认使用 10分钟更新一次的频率
|
||||
* 修复输入空的 swagger地址 ,会发起请求的 bug
|
||||
* 优化 swagger 数据导入,不会导入空的分类,不会使用版本号作为分类名称
|
||||
* swagger 导入自动增加 basePath 到项目配置
|
||||
|
||||
## v1.8.4
|
||||
* 修复 swagger 导入数据时,如果数据格式中缺少 in 的参数,会丢失请求参数
|
||||
|
@ -17,6 +17,11 @@ async function handle(
|
||||
token,
|
||||
port
|
||||
) {
|
||||
|
||||
const taskNotice = _.throttle((index, len)=>{
|
||||
messageSuccess(`正在导入,已执行任务 ${index+1} 个,共 ${len} 个`)
|
||||
}, 3000)
|
||||
|
||||
const handleAddCat = async cats => {
|
||||
let catsObj = {};
|
||||
if (cats && Array.isArray(cats)) {
|
||||
@ -52,12 +57,13 @@ async function handle(
|
||||
return catsObj;
|
||||
};
|
||||
|
||||
const handleAddInterface = async res => {
|
||||
const cats = await handleAddCat(res.cats);
|
||||
const handleAddInterface = async info => {
|
||||
const cats = await handleAddCat(info.cats);
|
||||
if (cats === false) {
|
||||
return;
|
||||
}
|
||||
res = res.apis;
|
||||
|
||||
const res = info.apis;
|
||||
let len = res.length;
|
||||
let count = 0;
|
||||
let successNum = len;
|
||||
@ -67,6 +73,19 @@ async function handle(
|
||||
callback({ showLoading: false });
|
||||
return;
|
||||
}
|
||||
|
||||
if(info.basePath){
|
||||
let projectApiPath = '/api/project/up';
|
||||
if (isNode) {
|
||||
projectApiPath = 'http://127.0.0.1:' + port + projectApiPath;
|
||||
}
|
||||
|
||||
await axios.post(projectApiPath, {
|
||||
id: projectId,
|
||||
basepath: info.basePath
|
||||
})
|
||||
}
|
||||
|
||||
for (let index = 0; index < res.length; index++) {
|
||||
let item = res[index];
|
||||
let data = Object.assign(item, {
|
||||
@ -126,7 +145,10 @@ async function handle(
|
||||
if (count === len) {
|
||||
callback({ showLoading: false });
|
||||
messageSuccess(`成功导入接口 ${successNum} 个, 已存在的接口 ${existNum} 个`);
|
||||
return;
|
||||
}
|
||||
|
||||
taskNotice(index, res.length)
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -79,6 +79,8 @@ const compareVersions = require('compare-versions');
|
||||
res = await handleSwaggerData(res);
|
||||
SwaggerData = res;
|
||||
|
||||
interfaceData.basePath = res.basePath || '';
|
||||
|
||||
if (res.tags && Array.isArray(res.tags)) {
|
||||
res.tags.forEach(tag => {
|
||||
interfaceData.cats.push({
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "yapi-vendor",
|
||||
"version": "1.8.4",
|
||||
"version": "1.8.5",
|
||||
"description": "YAPI",
|
||||
"main": "server/app.js",
|
||||
"scripts": {
|
||||
|
Loading…
x
Reference in New Issue
Block a user