refacotr(接口测试): swagger 导入创建模块
This commit is contained in:
parent
768ed785a9
commit
7ba3c09a3d
|
@ -11,8 +11,6 @@ import io.metersphere.api.dto.definition.response.HttpResponse;
|
|||
import io.metersphere.api.dto.parse.ApiImport;
|
||||
import io.metersphere.api.dto.scenario.Body;
|
||||
import io.metersphere.api.dto.scenario.KeyValue;
|
||||
import io.metersphere.api.dto.scenario.Scenario;
|
||||
import io.metersphere.api.dto.scenario.request.Request;
|
||||
import io.metersphere.api.dto.scenario.request.RequestType;
|
||||
import io.metersphere.commons.constants.SwaggerParameterType;
|
||||
import io.swagger.models.*;
|
||||
|
@ -48,7 +46,6 @@ public class Swagger2Parser extends ApiImportAbstractParser {
|
|||
}
|
||||
|
||||
private HashMap<String, List<ApiDefinitionResult>> parseRequests(Swagger swagger) {
|
||||
// List<ApiDefinitionResult> results = new LinkedList<>();
|
||||
Map<String, Path> paths = swagger.getPaths();
|
||||
Set<String> pathNames = paths.keySet();
|
||||
|
||||
|
@ -68,7 +65,6 @@ public class Swagger2Parser extends ApiImportAbstractParser {
|
|||
parseParameters(operation, request);
|
||||
apiDefinition.setRequest(JSON.toJSONString(request));
|
||||
apiDefinition.setId(request.getId());
|
||||
// results.add(apiDefinition);
|
||||
apiDefinition.setResponse(JSON.toJSONString(parseResponse(operation.getResponses())));
|
||||
buildResultMap(moduleMap, apiDefinition, operation);
|
||||
}
|
||||
|
@ -91,10 +87,10 @@ public class Swagger2Parser extends ApiImportAbstractParser {
|
|||
list.add(apiDefinition);
|
||||
});
|
||||
} else {
|
||||
List<ApiDefinitionResult> list = moduleMap.get("default");
|
||||
List<ApiDefinitionResult> list = moduleMap.get("#default");
|
||||
if (list == null) {
|
||||
list = new ArrayList<>();
|
||||
moduleMap.put("default", list);
|
||||
moduleMap.put("#default", list);
|
||||
}
|
||||
list.add(apiDefinition);
|
||||
}
|
||||
|
@ -162,9 +158,6 @@ public class Swagger2Parser extends ApiImportAbstractParser {
|
|||
// break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// List<String> responseContentTypes = operation.getProduces();
|
||||
}
|
||||
|
||||
private String getBodyType(Operation operation) {
|
||||
|
|
|
@ -25,6 +25,7 @@ import io.metersphere.commons.utils.ServiceUtils;
|
|||
import io.metersphere.commons.utils.SessionUtils;
|
||||
import io.metersphere.i18n.Translator;
|
||||
import io.metersphere.service.FileService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.ibatis.session.ExecutorType;
|
||||
import org.apache.ibatis.session.SqlSession;
|
||||
import org.apache.ibatis.session.SqlSessionFactory;
|
||||
|
@ -334,24 +335,30 @@ public class ApiDefinitionService {
|
|||
private void importApiTest(ApiTestImportRequest importRequest, ApiDefinitionImport apiImport) {
|
||||
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
|
||||
ApiDefinitionMapper batchMapper = sqlSession.getMapper(ApiDefinitionMapper.class);
|
||||
List<ApiDefinitionResult> data = apiImport.getData();
|
||||
HashMap<String, List<ApiDefinitionResult>> resultMap = apiImport.getResultMap();
|
||||
resultMap.forEach((module, apiDefinition) -> {
|
||||
// apiModuleService
|
||||
// apiModuleService.addNode();
|
||||
Integer batchNum = 1;
|
||||
for (String key : resultMap.keySet()) {
|
||||
List<ApiDefinitionResult> apiDefinitions = resultMap.get(key);
|
||||
ApiModule newModule = apiModuleService.getNewModule(key, importRequest.getProjectId(), 1);
|
||||
newModule.setProtocol(RequestType.HTTP);
|
||||
if (!StringUtils.equals(key, "#default")) {
|
||||
apiModuleService.addNode(newModule);
|
||||
}
|
||||
|
||||
});
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
ApiDefinitionResult item = data.get(i);
|
||||
item.setProjectId(importRequest.getProjectId());
|
||||
item.setModuleId(importRequest.getModuleId());
|
||||
item.setModulePath(importRequest.getModulePath());
|
||||
item.setEnvironmentId(importRequest.getEnvironmentId());
|
||||
item.setUserId(null);
|
||||
createTest(item, batchMapper);
|
||||
if (i % 300 == 0) {
|
||||
apiDefinitions.forEach(item -> {
|
||||
item.setProjectId(importRequest.getProjectId());
|
||||
if (!StringUtils.equals(key, "#default")) {
|
||||
item.setModuleId(newModule.getId());
|
||||
}
|
||||
item.setModulePath(importRequest.getModulePath());
|
||||
item.setEnvironmentId(importRequest.getEnvironmentId());
|
||||
item.setUserId(SessionUtils.getUserId());
|
||||
createTest(item, batchMapper);
|
||||
});
|
||||
if (batchNum % 300 == 0) {
|
||||
sqlSession.flushStatements();
|
||||
}
|
||||
batchNum++;
|
||||
}
|
||||
sqlSession.flushStatements();
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<template>
|
||||
<div>
|
||||
<div v-loading="result.loading">
|
||||
<select-menu
|
||||
:data="projects"
|
||||
:current-data="currentProject"
|
||||
|
@ -116,6 +116,7 @@
|
|||
},
|
||||
data() {
|
||||
return {
|
||||
result: {},
|
||||
options: OPTIONS,
|
||||
protocol: OPTIONS[0].value,
|
||||
httpVisible: false,
|
||||
|
@ -148,7 +149,7 @@
|
|||
if (this.expandedNode.length === 0) {
|
||||
this.expandedNode.push("root");
|
||||
}
|
||||
this.$get("/api/module/list/" + this.currentProject.id + "/" + this.protocol, response => {
|
||||
this.result = this.$get("/api/module/list/" + this.currentProject.id + "/" + this.protocol, response => {
|
||||
if (response.data != undefined && response.data != null) {
|
||||
this.data[1].children = response.data;
|
||||
let moduleOptions = [];
|
||||
|
@ -409,6 +410,7 @@
|
|||
},
|
||||
refresh(data) {
|
||||
this.$emit('refresh', data);
|
||||
this.getApiModuleTree();
|
||||
},
|
||||
saveAsEdit(data) {
|
||||
this.$emit('saveAsEdit', data);
|
||||
|
|
Loading…
Reference in New Issue