导入swagger

This commit is contained in:
2025-02-19 11:18:13 +08:00
parent eec0468ca3
commit b800bd7f1d
2 changed files with 24 additions and 3 deletions

View File

@@ -3,6 +3,7 @@ package com.test.test.service.impl;
import java.util.*; import java.util.*;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.JSONObject;
import com.test.common.utils.DateUtils; import com.test.common.utils.DateUtils;
import com.test.common.utils.http.HttpUtils; import com.test.common.utils.http.HttpUtils;
@@ -69,6 +70,7 @@ public class TestApiServiceImpl implements ITestApiService {
AtomicInteger count = new AtomicInteger(); AtomicInteger count = new AtomicInteger();
JSONObject jsonObject = JSONObject.parseObject(HttpUtils.sendGet(url)); JSONObject jsonObject = JSONObject.parseObject(HttpUtils.sendGet(url));
String title = jsonObject.getJSONObject("info").getString("title"); String title = jsonObject.getJSONObject("info").getString("title");
Date createTime = DateUtils.getNowDate();
// 设置顶级节点 // 设置顶级节点
Long parentId = getGroupId(title, 0L); Long parentId = getGroupId(title, 0L);
// 获取Schemas // 获取Schemas
@@ -101,12 +103,22 @@ public class TestApiServiceImpl implements ITestApiService {
} }
} }
// 获取Param // 获取Param
String param = ""; String param = "[]";
JSONObject parameters = json.getJSONObject("parameters"); JSONObject parameters = json.getJSONObject("parameters");
if (parameters != null) { if (parameters != null) {
JSONObject paramsJson = parseParams(parameters, schemas); JSONObject paramsJson = parseParams(parameters, schemas);
param = JSONObject.toJSONString(paramsJson); JSONArray array = new JSONArray();
paramsJson.forEach((key, value) -> {
JSONObject object = new JSONObject();
object.put("key", key);
object.put("value", value);
array.add(object);
});
param = array.toJSONString();
} }
// 获取header
String header = "[]";
TestApi testApi = new TestApi(); TestApi testApi = new TestApi();
testApi.setUri(uri); testApi.setUri(uri);
testApi.setMethod(method); testApi.setMethod(method);
@@ -114,6 +126,8 @@ public class TestApiServiceImpl implements ITestApiService {
testApi.setGroupId(getGroupId(groupName, parentId)); testApi.setGroupId(getGroupId(groupName, parentId));
testApi.setBody(body); testApi.setBody(body);
testApi.setParam(param); testApi.setParam(param);
testApi.setHeader(header);
testApi.setCreateTime(createTime);
count.addAndGet(testApiMapper.insertTestApi(testApi)); count.addAndGet(testApiMapper.insertTestApi(testApi));
}); });

View File

@@ -32,7 +32,14 @@ export default {
submitForm() { submitForm() {
this.$refs["form"].validate(valid => { this.$refs["form"].validate(valid => {
if (valid) { if (valid) {
const loading = this.$loading({
lock: true,
text: 'Loading',
spinner: 'el-icon-loading',
background: 'rgba(0, 0, 0, 0.7)'
});
importApi({url: this.form.url}).then((res) => { importApi({url: this.form.url}).then((res) => {
loading.close();
this.$message.success("导入成功") this.$message.success("导入成功")
this.cancel(); this.cancel();
}) })