fix: 接口导入modulePath 不正确 (#1881)
Co-authored-by: chenjianxing <jianxing.chen@fit2cloud.com> Co-authored-by: jianxing <41557596+AgAngle@users.noreply.github.com>
This commit is contained in:
parent
cc1cecc18b
commit
722b6d123e
|
@ -13,10 +13,10 @@ import java.util.List;
|
|||
public class ApiScenarioImportUtil {
|
||||
|
||||
public static ApiScenarioModule getSelectModule(String moduleId) {
|
||||
ApiScenarioModuleService apiModuleService = CommonBeanFactory.getBean(ApiScenarioModuleService.class);
|
||||
ApiScenarioModuleService apiScenarioModuleService = CommonBeanFactory.getBean(ApiScenarioModuleService.class);
|
||||
if (StringUtils.isNotBlank(moduleId) && !StringUtils.equals("root", moduleId)) {
|
||||
ApiScenarioModule module = new ApiScenarioModule();
|
||||
ApiScenarioModuleDTO moduleDTO = apiModuleService.getNode(moduleId);
|
||||
ApiScenarioModuleDTO moduleDTO = apiScenarioModuleService.getNode(moduleId);
|
||||
if (moduleDTO != null) {
|
||||
BeanUtils.copyBean(module, moduleDTO);
|
||||
}
|
||||
|
@ -25,6 +25,17 @@ public class ApiScenarioImportUtil {
|
|||
return null;
|
||||
}
|
||||
|
||||
public static String getSelectModulePath(String path, String pid) {
|
||||
ApiScenarioModuleService apiScenarioModuleService = CommonBeanFactory.getBean(ApiScenarioModuleService.class);
|
||||
if (StringUtils.isNotBlank(pid)) {
|
||||
ApiScenarioModuleDTO moduleDTO = apiScenarioModuleService.getNode(pid);
|
||||
if (moduleDTO != null) {
|
||||
return getSelectModulePath(moduleDTO.getName() + "/" + path, moduleDTO.getParentId());
|
||||
}
|
||||
}
|
||||
return "/" + path;
|
||||
}
|
||||
|
||||
public static ApiScenarioModule buildModule(ApiScenarioModule parentModule, String name, String projectId) {
|
||||
ApiScenarioModuleService apiModuleService = CommonBeanFactory.getBean(ApiScenarioModuleService.class);
|
||||
ApiScenarioModule module;
|
||||
|
|
|
@ -18,6 +18,7 @@ import io.metersphere.commons.exception.MSException;
|
|||
import io.metersphere.commons.utils.CommonBeanFactory;
|
||||
import io.metersphere.commons.utils.LogUtil;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
|
@ -62,16 +63,20 @@ public class HarScenarioParser extends HarScenarioAbstractParser<ScenarioImport>
|
|||
}
|
||||
|
||||
private void parseScenarioWithBLOBs(List<ApiScenarioWithBLOBs> scenarioWithBLOBsList, MsScenario msScenario, ApiTestImportRequest request) {
|
||||
ApiScenarioModule module = ApiScenarioImportUtil.getSelectModule(request.getModuleId());
|
||||
if (module == null) {
|
||||
ApiScenarioModuleService apiModuleService = CommonBeanFactory.getBean(ApiScenarioModuleService.class);
|
||||
module = apiModuleService.getNewModule(msScenario.getName(), projectId, 1);
|
||||
ApiScenarioModule selectModule = null;
|
||||
if (StringUtils.isNotBlank(request.getModuleId())) {
|
||||
selectModule = ApiScenarioImportUtil.getSelectModule(request.getModuleId());
|
||||
}
|
||||
|
||||
ApiScenarioModule module = ApiScenarioImportUtil.buildModule(selectModule, msScenario.getName(), this.projectId);
|
||||
ApiScenarioWithBLOBs scenarioWithBLOBs = parseScenario(msScenario);
|
||||
if (module != null) {
|
||||
scenarioWithBLOBs.setApiScenarioModuleId(module.getId());
|
||||
scenarioWithBLOBs.setModulePath("/" + module.getName());
|
||||
if (selectModule != null) {
|
||||
String selectModulePath = ApiScenarioImportUtil.getSelectModulePath(selectModule.getName(), selectModule.getParentId());
|
||||
scenarioWithBLOBs.setModulePath(selectModulePath + "/" + module.getName());
|
||||
} else {
|
||||
scenarioWithBLOBs.setModulePath("/" + module.getName());
|
||||
}
|
||||
}
|
||||
scenarioWithBLOBsList.add(scenarioWithBLOBs);
|
||||
}
|
||||
|
|
|
@ -112,7 +112,15 @@ public class MsJmeterParser extends ApiImportAbstractParser<ScenarioImport> {
|
|||
private List<ApiScenarioWithBLOBs> paseObj(MsScenario msScenario, ApiTestImportRequest request) {
|
||||
List<ApiScenarioWithBLOBs> scenarioWithBLOBsList = new ArrayList<>();
|
||||
ApiScenarioWithBLOBs scenarioWithBLOBs = new ApiScenarioWithBLOBs();
|
||||
ApiScenarioModule module = ApiScenarioImportUtil.buildModule(ApiScenarioImportUtil.getSelectModule(request.getModuleId()), msScenario.getName(), this.projectId);
|
||||
ApiScenarioModule selectModule = null;
|
||||
String selectModulePath = null;
|
||||
if (StringUtils.isNotBlank(request.getModuleId())) {
|
||||
selectModule = ApiScenarioImportUtil.getSelectModule(request.getModuleId());
|
||||
if (selectModule != null) {
|
||||
selectModulePath = ApiScenarioImportUtil.getSelectModulePath(selectModule.getName(), selectModule.getParentId());
|
||||
}
|
||||
}
|
||||
ApiScenarioModule module = ApiScenarioImportUtil.buildModule(selectModule, msScenario.getName(), this.projectId);
|
||||
scenarioWithBLOBs.setName(msScenario.getName());
|
||||
scenarioWithBLOBs.setProjectId(request.getProjectId());
|
||||
if (msScenario != null && CollectionUtils.isNotEmpty(msScenario.getHashTree())) {
|
||||
|
@ -120,7 +128,11 @@ public class MsJmeterParser extends ApiImportAbstractParser<ScenarioImport> {
|
|||
}
|
||||
if (module != null) {
|
||||
scenarioWithBLOBs.setApiScenarioModuleId(module.getId());
|
||||
scenarioWithBLOBs.setModulePath("/" + module.getName());
|
||||
if (StringUtils.isNotBlank(selectModulePath)) {
|
||||
scenarioWithBLOBs.setModulePath(selectModulePath + "/" + module.getName());
|
||||
} else {
|
||||
scenarioWithBLOBs.setModulePath("/" + module.getName());
|
||||
}
|
||||
}
|
||||
scenarioWithBLOBs.setId(UUID.randomUUID().toString());
|
||||
scenarioWithBLOBs.setScenarioDefinition(JSON.toJSONString(msScenario));
|
||||
|
|
|
@ -17,11 +17,23 @@ import java.util.*;
|
|||
|
||||
public class MsScenarioParser extends MsAbstractParser<ScenarioImport> {
|
||||
|
||||
private ApiScenarioModule selectModule;
|
||||
|
||||
private String selectModulePath;
|
||||
|
||||
@Override
|
||||
public ScenarioImport parse(InputStream source, ApiTestImportRequest request) {
|
||||
String testStr = getApiTestStr(source);
|
||||
this.projectId = request.getProjectId();
|
||||
JSONObject testObject = JSONObject.parseObject(testStr, Feature.OrderedField);
|
||||
|
||||
if (StringUtils.isNotBlank(request.getModuleId())) {
|
||||
this.selectModule = ApiScenarioImportUtil.getSelectModule(request.getModuleId());
|
||||
if (this.selectModule != null) {
|
||||
this.selectModulePath = ApiScenarioImportUtil.getSelectModulePath(this.selectModule.getName(), this.selectModule.getParentId());
|
||||
}
|
||||
}
|
||||
|
||||
if (testObject.get("projectName") != null || testObject.get("projectId") != null ) {
|
||||
return parseMsFormat(testStr, request);
|
||||
} else {
|
||||
|
@ -73,13 +85,19 @@ public class MsScenarioParser extends MsAbstractParser<ScenarioImport> {
|
|||
modulePath = modulePath.substring(0, modulePath.length() - 1);
|
||||
}
|
||||
List<String> modules = Arrays.asList(modulePath.split("/"));
|
||||
ApiScenarioModule parent = ApiScenarioImportUtil.getSelectModule(importRequest.getModuleId());
|
||||
ApiScenarioModule parent = this.selectModule;
|
||||
Iterator<String> iterator = modules.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
String item = iterator.next();
|
||||
parent = ApiScenarioImportUtil.buildModule(parent, item, this.projectId);
|
||||
if (!iterator.hasNext()) {
|
||||
apiScenarioWithBLOBs.setApiScenarioModuleId(parent.getId());
|
||||
String path = apiScenarioWithBLOBs.getModulePath() == null ? "" : apiScenarioWithBLOBs.getModulePath();
|
||||
if (StringUtils.isNotBlank(this.selectModulePath)) {
|
||||
apiScenarioWithBLOBs.setModulePath(this.selectModulePath + path);
|
||||
} else if (StringUtils.isBlank(importRequest.getModuleId())) {
|
||||
apiScenarioWithBLOBs.setModulePath("/默认模块" + path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,11 +46,18 @@ public class PostmanScenarioParser extends PostmanAbstractParserParser<ScenarioI
|
|||
}
|
||||
|
||||
private void parseScenarioWithBLOBs(List<ApiScenarioWithBLOBs> scenarioWithBLOBsList, MsScenario msScenario, ApiTestImportRequest request) {
|
||||
ApiScenarioModule module = ApiScenarioImportUtil.buildModule(ApiScenarioImportUtil.getSelectModule(request.getModuleId()), msScenario.getName(), this.projectId);
|
||||
ApiScenarioModule selectModule = ApiScenarioImportUtil.getSelectModule(request.getModuleId());
|
||||
|
||||
ApiScenarioModule module = ApiScenarioImportUtil.buildModule(selectModule, msScenario.getName(), this.projectId);
|
||||
ApiScenarioWithBLOBs scenarioWithBLOBs = parseScenario(msScenario);
|
||||
if (module != null) {
|
||||
scenarioWithBLOBs.setApiScenarioModuleId(module.getId());
|
||||
scenarioWithBLOBs.setModulePath("/" + module.getName());
|
||||
if (selectModule != null) {
|
||||
String selectModulePath = ApiScenarioImportUtil.getSelectModulePath(selectModule.getName(), selectModule.getParentId());
|
||||
scenarioWithBLOBs.setModulePath(selectModulePath + "/" + module.getName());
|
||||
} else {
|
||||
scenarioWithBLOBs.setModulePath("/" + module.getName());
|
||||
}
|
||||
}
|
||||
scenarioWithBLOBsList.add(scenarioWithBLOBs);
|
||||
}
|
||||
|
|
|
@ -26,6 +26,24 @@ public class ApiDefinitionImportUtil {
|
|||
return null;
|
||||
}
|
||||
|
||||
public static String getSelectModulePath(String path, String pid) {
|
||||
ApiModuleService apiModuleService = CommonBeanFactory.getBean(ApiModuleService.class);
|
||||
if (StringUtils.isNotBlank(pid)) {
|
||||
ApiModuleDTO moduleDTO = apiModuleService.getNode(pid);
|
||||
if (moduleDTO != null) {
|
||||
return getSelectModulePath(moduleDTO.getName() + "/" + path, moduleDTO.getParentId());
|
||||
}
|
||||
}
|
||||
return "/" + path;
|
||||
}
|
||||
|
||||
public static ApiModule getNodeTree(String projectId) {
|
||||
ApiModuleService apiModuleService = CommonBeanFactory.getBean(ApiModuleService.class);
|
||||
List<ApiModuleDTO> nodeTrees = apiModuleService.getNodeTreeByProjectId(projectId, RequestType.HTTP);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static ApiModule buildModule(ApiModule parentModule, String name, String projectId) {
|
||||
ApiModuleService apiModuleService = CommonBeanFactory.getBean(ApiModuleService.class);
|
||||
ApiModule module;
|
||||
|
|
|
@ -1,27 +1,10 @@
|
|||
package io.metersphere.api.dto.definition.parse;
|
||||
|
||||
|
||||
import io.metersphere.api.parse.ApiImportAbstractParser;
|
||||
import io.metersphere.base.domain.ApiDefinitionWithBLOBs;
|
||||
import io.metersphere.base.domain.ApiModule;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author song.tianyang
|
||||
* @Date 2021/3/10 11:15 上午
|
||||
* @Description
|
||||
*/
|
||||
public abstract class HarAbstractParser extends ApiImportAbstractParser<ApiDefinitionImport> {
|
||||
|
||||
protected void buildModule(ApiModule parentModule, ApiDefinitionWithBLOBs apiDefinition, List<String> tags) {
|
||||
if (tags != null) {
|
||||
tags.forEach(tag -> {
|
||||
ApiModule module = ApiDefinitionImportUtil.buildModule(parentModule, tag, this.projectId);
|
||||
apiDefinition.setModuleId(module.getId());
|
||||
});
|
||||
}else {
|
||||
apiDefinition.setModuleId(parentModule.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,7 +61,15 @@ public class HarParser extends HarAbstractParser {
|
|||
private List<ApiDefinitionWithBLOBs> parseRequests(Har har, ApiTestImportRequest importRequest) {
|
||||
List<ApiDefinitionWithBLOBs> results = new ArrayList<>();
|
||||
|
||||
ApiModule parentNode = ApiDefinitionImportUtil.getSelectModule(importRequest.getModuleId());
|
||||
ApiModule selectModule = null;
|
||||
String selectModulePath = null;
|
||||
if (StringUtils.isNotBlank(importRequest.getModuleId())) {
|
||||
selectModule = ApiDefinitionImportUtil.getSelectModule(importRequest.getModuleId());
|
||||
if (selectModule != null) {
|
||||
selectModulePath = ApiDefinitionImportUtil.getSelectModulePath(selectModule.getName(), selectModule.getParentId());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
List<HarEntry> harEntryList = new ArrayList<>();
|
||||
if (har.log != null && har.log.entries != null) {
|
||||
|
@ -103,7 +111,17 @@ public class HarParser extends HarAbstractParser {
|
|||
addBodyHeader(request);
|
||||
apiDefinition.setRequest(JSON.toJSONString(request));
|
||||
apiDefinition.setResponse(JSON.toJSONString(parseResponse(entry.response)));
|
||||
buildModule(parentNode, apiDefinition, null);
|
||||
if (selectModule == null) {
|
||||
apiDefinition.setModuleId("default-module");
|
||||
|
||||
} else {
|
||||
apiDefinition.setModuleId(selectModule.getId());
|
||||
}
|
||||
if (StringUtils.isNotBlank(selectModulePath)) {
|
||||
apiDefinition.setModulePath(selectModulePath);
|
||||
} else {
|
||||
apiDefinition.setModulePath("/默认模块");
|
||||
}
|
||||
results.add(apiDefinition);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,11 +19,22 @@ import java.util.*;
|
|||
|
||||
public class MsDefinitionParser extends MsAbstractParser<ApiDefinitionImport> {
|
||||
|
||||
private ApiModule selectModule;
|
||||
|
||||
private String selectModulePath;
|
||||
|
||||
@Override
|
||||
public ApiDefinitionImport parse(InputStream source, ApiTestImportRequest request) {
|
||||
String testStr = getApiTestStr(source);
|
||||
JSONObject testObject = JSONObject.parseObject(testStr, Feature.OrderedField);
|
||||
this.projectId = request.getProjectId();
|
||||
if (StringUtils.isNotBlank(request.getModuleId())) {
|
||||
this.selectModule = ApiDefinitionImportUtil.getSelectModule(request.getModuleId());
|
||||
if (this.selectModule != null) {
|
||||
this.selectModulePath = ApiDefinitionImportUtil.getSelectModulePath(this.selectModule.getName(), this.selectModule.getParentId());
|
||||
}
|
||||
}
|
||||
|
||||
if (testObject.get("projectName") != null || testObject.get("projectId") != null ) {// metersphere 格式导入
|
||||
return parseMsFormat(testStr, request);
|
||||
} else { // chrome 插件录制格式导入
|
||||
|
@ -40,7 +51,7 @@ public class MsDefinitionParser extends MsAbstractParser<ApiDefinitionImport> {
|
|||
testObject.keySet().forEach(tag -> {
|
||||
String moduleId = null;
|
||||
if (isCreateModule) {
|
||||
moduleId = ApiDefinitionImportUtil.buildModule(ApiDefinitionImportUtil.getSelectModule(importRequest.getModuleId()), tag, this.projectId).getId();
|
||||
moduleId = ApiDefinitionImportUtil.buildModule(this.selectModule, tag, this.projectId).getId();
|
||||
}
|
||||
List<MsHTTPSamplerProxy> msHTTPSamplerProxies = parseMsHTTPSamplerProxy(testObject, tag);
|
||||
for (MsHTTPSamplerProxy msHTTPSamplerProxy : msHTTPSamplerProxies) {
|
||||
|
@ -113,13 +124,19 @@ public class MsDefinitionParser extends MsAbstractParser<ApiDefinitionImport> {
|
|||
modulePath = modulePath.substring(0, modulePath.length() - 1);
|
||||
}
|
||||
List<String> modules = Arrays.asList(modulePath.split("/"));
|
||||
ApiModule parent = ApiDefinitionImportUtil.getSelectModule(importRequest.getModuleId());
|
||||
ApiModule parent = this.selectModule;
|
||||
Iterator<String> iterator = modules.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
String item = iterator.next();
|
||||
parent = ApiDefinitionImportUtil.buildModule(parent, item, this.projectId);
|
||||
if (!iterator.hasNext()) {
|
||||
apiDefinition.setModuleId(parent.getId());
|
||||
String path = apiDefinition.getModulePath() == null ? "" : apiDefinition.getModulePath();
|
||||
if (StringUtils.isNotBlank(this.selectModulePath)) {
|
||||
apiDefinition.setModulePath(this.selectModulePath + path);
|
||||
} else if (StringUtils.isBlank(importRequest.getModuleId())){
|
||||
apiDefinition.setModulePath("/默认模块" + path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import io.metersphere.api.dto.parse.postman.PostmanKeyValue;
|
|||
import io.metersphere.api.parse.PostmanAbstractParserParser;
|
||||
import io.metersphere.base.domain.ApiDefinitionWithBLOBs;
|
||||
import io.metersphere.base.domain.ApiModule;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import io.metersphere.base.domain.ApiTestCaseWithBLOBs;
|
||||
import io.metersphere.base.domain.Project;
|
||||
import io.metersphere.base.mapper.ProjectMapper;
|
||||
|
@ -20,6 +21,10 @@ import java.util.*;
|
|||
|
||||
public class PostmanDefinitionParser extends PostmanAbstractParserParser<ApiDefinitionImport> {
|
||||
|
||||
private ApiModule selectModule;
|
||||
|
||||
private String selectModulePath;
|
||||
|
||||
@Override
|
||||
public ApiDefinitionImport parse(InputStream source, ApiTestImportRequest request) {
|
||||
String testStr = getApiTestStr(source);
|
||||
|
@ -28,26 +33,31 @@ public class PostmanDefinitionParser extends PostmanAbstractParserParser<ApiDefi
|
|||
List<PostmanKeyValue> variables = postmanCollection.getVariable();
|
||||
ApiDefinitionImport apiImport = new ApiDefinitionImport();
|
||||
List<ApiDefinitionWithBLOBs> results = new ArrayList<>();
|
||||
this.selectModule = ApiDefinitionImportUtil.getSelectModule(request.getModuleId());
|
||||
if (this.selectModule != null) {
|
||||
this.selectModulePath = ApiDefinitionImportUtil.getSelectModulePath(this.selectModule.getName(), this.selectModule.getParentId());
|
||||
}
|
||||
|
||||
ApiModule apiModule = ApiDefinitionImportUtil.buildModule(this.selectModule, postmanCollection.getInfo().getName(), this.projectId);
|
||||
List<ApiTestCaseWithBLOBs> cases = new ArrayList<>();
|
||||
Map<String, String> repeatMap = new HashMap();
|
||||
ProjectMapper projectMapper = CommonBeanFactory.getBean(ProjectMapper.class);
|
||||
Project project = projectMapper.selectByPrimaryKey(request.getProjectId());
|
||||
parseItem(postmanCollection.getItem(), variables, results,
|
||||
ApiDefinitionImportUtil.buildModule(ApiDefinitionImportUtil.getSelectModule(request.getModuleId()),
|
||||
postmanCollection.getInfo().getName(), this.projectId), cases, repeatMap, project.getRepeatable());
|
||||
apiModule, apiModule.getName(), cases, repeatMap, project.getRepeatable());
|
||||
apiImport.setData(results);
|
||||
apiImport.setCases(cases);
|
||||
return apiImport;
|
||||
}
|
||||
|
||||
protected void parseItem(List<PostmanItem> items, List<PostmanKeyValue> variables, List<ApiDefinitionWithBLOBs> results,
|
||||
ApiModule parentModule, List<ApiTestCaseWithBLOBs> cases, Map<String, String> repeatMap, Boolean repeatable) {
|
||||
ApiModule parentModule, String path, List<ApiTestCaseWithBLOBs> cases, Map<String, String> repeatMap, Boolean repeatable) {
|
||||
for (PostmanItem item : items) {
|
||||
List<PostmanItem> childItems = item.getItem();
|
||||
if (childItems != null) {
|
||||
ApiModule module = null;
|
||||
module = ApiDefinitionImportUtil.buildModule(parentModule, item.getName(), this.projectId);
|
||||
parseItem(childItems, variables, results, module, cases, repeatMap, repeatable);
|
||||
parseItem(childItems, variables, results, module, path + "/" + module.getName(), cases, repeatMap, repeatable);
|
||||
} else {
|
||||
MsHTTPSamplerProxy msHTTPSamplerProxy = parsePostman(item);
|
||||
ApiDefinitionWithBLOBs request = buildApiDefinition(msHTTPSamplerProxy.getId(), msHTTPSamplerProxy.getName(),
|
||||
|
@ -56,6 +66,11 @@ public class PostmanDefinitionParser extends PostmanAbstractParserParser<ApiDefi
|
|||
request.setRequest(JSON.toJSONString(msHTTPSamplerProxy));
|
||||
if (parentModule != null) {
|
||||
request.setModuleId(parentModule.getId());
|
||||
if (StringUtils.isNotBlank(this.selectModulePath)) {
|
||||
request.setModulePath(this.selectModulePath + "/" + path);
|
||||
} else {
|
||||
request.setModulePath("/" + path);
|
||||
}
|
||||
}
|
||||
if (request != null) {
|
||||
if (repeatMap.keySet().contains(request.getMethod() + request.getPath())
|
||||
|
|
|
@ -56,7 +56,14 @@ public class Swagger2Parser extends SwaggerAbstractParser {
|
|||
|
||||
List<ApiDefinitionWithBLOBs> results = new ArrayList<>();
|
||||
|
||||
ApiModule parentNode = ApiDefinitionImportUtil.getSelectModule(importRequest.getModuleId());
|
||||
ApiModule selectModule = null;
|
||||
String selectModulePath = null;
|
||||
if (StringUtils.isNotBlank(importRequest.getModuleId())) {
|
||||
selectModule = ApiDefinitionImportUtil.getSelectModule(importRequest.getModuleId());
|
||||
if (selectModule != null) {
|
||||
selectModulePath = ApiDefinitionImportUtil.getSelectModulePath(selectModule.getName(), selectModule.getParentId());
|
||||
}
|
||||
}
|
||||
|
||||
String basePath = swagger.getBasePath();
|
||||
for (String pathName : pathNames) {
|
||||
|
@ -76,7 +83,7 @@ public class Swagger2Parser extends SwaggerAbstractParser {
|
|||
}
|
||||
apiDefinition.setRequest(JSON.toJSONString(request));
|
||||
apiDefinition.setResponse(JSON.toJSONString(parseResponse(operation, operation.getResponses())));
|
||||
buildModule(parentNode, apiDefinition, operation.getTags());
|
||||
buildModule(selectModule, apiDefinition, operation.getTags(), selectModulePath);
|
||||
results.add(apiDefinition);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,15 +26,12 @@ import io.swagger.v3.oas.models.parameters.*;
|
|||
import io.swagger.v3.oas.models.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.models.responses.ApiResponses;
|
||||
import io.swagger.v3.parser.core.models.SwaggerParseResult;
|
||||
import net.sf.saxon.ma.json.XMLToJsonFn;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.fife.ui.rsyntaxtextarea.parser.XmlParser;
|
||||
import org.springframework.http.HttpMethod;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
|
@ -84,7 +81,14 @@ public class Swagger3Parser extends SwaggerAbstractParser {
|
|||
|
||||
List<ApiDefinitionWithBLOBs> results = new ArrayList<>();
|
||||
|
||||
ApiModule parentNode = ApiDefinitionImportUtil.getSelectModule(importRequest.getModuleId());
|
||||
ApiModule selectModule = null;
|
||||
String selectModulePath = null;
|
||||
if (StringUtils.isNotBlank(importRequest.getModuleId())) {
|
||||
selectModule = ApiDefinitionImportUtil.getSelectModule(importRequest.getModuleId());
|
||||
if (selectModule != null) {
|
||||
selectModulePath = ApiDefinitionImportUtil.getSelectModulePath(selectModule.getName(), selectModule.getParentId());
|
||||
}
|
||||
}
|
||||
|
||||
for (String pathName : pathNames) {
|
||||
PathItem pathItem = paths.get(pathName);
|
||||
|
@ -109,7 +113,7 @@ public class Swagger3Parser extends SwaggerAbstractParser {
|
|||
addBodyHeader(request);
|
||||
apiDefinition.setRequest(JSON.toJSONString(request));
|
||||
apiDefinition.setResponse(JSON.toJSONString(parseResponse(operation.getResponses())));
|
||||
buildModule(parentNode, apiDefinition, operation.getTags());
|
||||
buildModule(selectModule, apiDefinition, operation.getTags(), selectModulePath);
|
||||
results.add(apiDefinition);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,16 +3,23 @@ package io.metersphere.api.dto.definition.parse;
|
|||
import io.metersphere.api.parse.ApiImportAbstractParser;
|
||||
import io.metersphere.base.domain.ApiDefinitionWithBLOBs;
|
||||
import io.metersphere.base.domain.ApiModule;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class SwaggerAbstractParser extends ApiImportAbstractParser<ApiDefinitionImport> {
|
||||
|
||||
protected void buildModule(ApiModule parentModule, ApiDefinitionWithBLOBs apiDefinition, List<String> tags) {
|
||||
protected void buildModule(ApiModule parentModule, ApiDefinitionWithBLOBs apiDefinition,
|
||||
List<String> tags, String selectModulePath) {
|
||||
if (tags != null) {
|
||||
tags.forEach(tag -> {
|
||||
ApiModule module = ApiDefinitionImportUtil.buildModule(parentModule, tag, this.projectId);
|
||||
apiDefinition.setModuleId(module.getId());
|
||||
if (StringUtils.isNotBlank(selectModulePath)) {
|
||||
apiDefinition.setModulePath(selectModulePath + "/" + tag);
|
||||
} else {
|
||||
apiDefinition.setModulePath("/" + tag);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -198,20 +198,14 @@ public abstract class ApiImportAbstractParser<T> implements ApiImportParser<T> {
|
|||
}
|
||||
|
||||
protected ApiScenarioWithBLOBs parseScenario(MsScenario msScenario) {
|
||||
// ApiScenarioModule module = ApiScenarioImportUtil.buildModule(ApiScenarioImportUtil.getSelectModule(request.getModuleId()), msScenario.getName(), this.projectId);
|
||||
ApiScenarioWithBLOBs scenarioWithBLOBs = new ApiScenarioWithBLOBs();
|
||||
scenarioWithBLOBs.setName(msScenario.getName());
|
||||
scenarioWithBLOBs.setProjectId(this.projectId);
|
||||
if (msScenario != null && CollectionUtils.isNotEmpty(msScenario.getHashTree())) {
|
||||
scenarioWithBLOBs.setStepTotal(msScenario.getHashTree().size());
|
||||
}
|
||||
// if (module != null) {
|
||||
// scenarioWithBLOBs.setApiScenarioModuleId(module.getId());
|
||||
// scenarioWithBLOBs.setModulePath("/" + module.getName());
|
||||
// }
|
||||
scenarioWithBLOBs.setId(UUID.randomUUID().toString());
|
||||
scenarioWithBLOBs.setScenarioDefinition(JSON.toJSONString(msScenario));
|
||||
return scenarioWithBLOBs;
|
||||
// scenarioWithBLOBsList.add(scenarioWithBLOBs);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -275,6 +275,9 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
|||
@Override
|
||||
public ApiModuleDTO getNode(String id) {
|
||||
ApiModule module = apiModuleMapper.selectByPrimaryKey(id);
|
||||
if (module == null) {
|
||||
return null;
|
||||
}
|
||||
ApiModuleDTO dto = JSON.parseObject(JSON.toJSONString(module), ApiModuleDTO.class);
|
||||
return dto;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue