fix(接口测试): 修复接口测试文件解析路径存在的问题

--bug=1046557 --user=宋天阳 【接口导入】-不选择模块,覆盖更新,关闭同步更新接口所在目录,导入后,没有在接口原模块更新,而是将接口移动到新建模块下 https://www.tapd.cn/55049933/s/1579692
This commit is contained in:
Jianguo-Genius 2024-09-18 14:48:41 +08:00 committed by Craftsman
parent c4ceb70ad5
commit 0f715c095b
2 changed files with 41 additions and 19 deletions

View File

@ -425,7 +425,13 @@ public class Swagger3ParserApiDefinition extends HttpApiDefinitionImportAbstract
} else { } else {
name = path; name = path;
} }
String modulePath = CollectionUtils.isNotEmpty(operation.getTags()) ? StringUtils.join("/", operation.getTags().getFirst()) : StringUtils.EMPTY; String modulePath = StringUtils.EMPTY;
if (CollectionUtils.isNotEmpty(operation.getTags())) {
modulePath = operation.getTags().getFirst();
if (!StringUtils.startsWith(modulePath, "/")) {
modulePath = "/" + modulePath;
}
}
return buildApiDefinition(name, path, method, modulePath, importRequest); return buildApiDefinition(name, path, method, modulePath, importRequest);
} }

View File

@ -527,7 +527,7 @@ public class ApiDefinitionImportService {
modulePathMap.put(item.getPath(), item); modulePathMap.put(item.getPath(), item);
}); });
// 进一步处理已存在的数据 // 进一步处理已存在的数据
this.furtherProcessingExistenceApiData(request.getModuleId(), selectModulePath.get(), insertAndUpdateData, preImportAnalysisResult, modulePathMap); this.furtherProcessingExistenceApiData(request.getModuleId(), selectModulePath.get(), request.isCoverModule(), insertAndUpdateData, preImportAnalysisResult, modulePathMap);
// 新增数据处理 // 新增数据处理
this.inertDataAnalysis(preImportAnalysisResult, request, selectModulePath.get(), modulePathMap, insertAndUpdateData); this.inertDataAnalysis(preImportAnalysisResult, request, selectModulePath.get(), modulePathMap, insertAndUpdateData);
// 已有数据处理 // 已有数据处理
@ -547,7 +547,10 @@ public class ApiDefinitionImportService {
* @param modulePathMap * @param modulePathMap
*/ */
private void furtherProcessingExistenceApiData(String selectModuleId, String selectModulePath, private void furtherProcessingExistenceApiData(String selectModuleId, String selectModulePath,
ApiImportDataAnalysisResult insertAndUpdateData, ApiDefinitionPreImportAnalysisResult apiDefinitionPreImportAnalysisResult, Map<String, BaseTreeNode> modulePathMap) { boolean isCoverModule,
ApiImportDataAnalysisResult insertAndUpdateData,
ApiDefinitionPreImportAnalysisResult apiDefinitionPreImportAnalysisResult,
Map<String, BaseTreeNode> modulePathMap) {
for (ApiDefinitionDetail importApi : insertAndUpdateData.getInsertApiList()) { for (ApiDefinitionDetail importApi : insertAndUpdateData.getInsertApiList()) {
//为新增数据赋予模块ID //为新增数据赋予模块ID
this.updateApiDefinitionModule(importApi, selectModulePath, modulePathMap, selectModuleId, apiDefinitionPreImportAnalysisResult); this.updateApiDefinitionModule(importApi, selectModulePath, modulePathMap, selectModuleId, apiDefinitionPreImportAnalysisResult);
@ -555,24 +558,34 @@ public class ApiDefinitionImportService {
List<ExistenceApiDefinitionDetail> removeList = new ArrayList<>(); List<ExistenceApiDefinitionDetail> removeList = new ArrayList<>();
for (ExistenceApiDefinitionDetail existenceApiDefinitionDetail : insertAndUpdateData.getExistenceApiList()) { for (ExistenceApiDefinitionDetail existenceApiDefinitionDetail : insertAndUpdateData.getExistenceApiList()) {
ApiDefinitionDetail importApi = existenceApiDefinitionDetail.getImportApiDefinition(); ApiDefinitionDetail importApi = existenceApiDefinitionDetail.getImportApiDefinition();
//为修改数据赋予模块ID
this.updateApiDefinitionModule(importApi, selectModulePath, modulePathMap, selectModuleId, apiDefinitionPreImportAnalysisResult); // 是否覆盖接口模块只针对http接口有效非http模块的校验性是有模块路径判断的
if (!StringUtils.equalsIgnoreCase(importApi.getProtocol(), ModuleConstants.NODE_PROTOCOL_HTTP)) { if (!isCoverModule && StringUtils.equalsIgnoreCase(importApi.getProtocol(), ModuleConstants.NODE_PROTOCOL_HTTP)) {
List<ApiDefinitionDetail> existenceApiList = new ArrayList<>(); ApiDefinitionDetail existenceApi = existenceApiDefinitionDetail.getExistenceApiDefinition().getFirst();
for (ApiDefinitionDetail existenceApi : existenceApiDefinitionDetail.getExistenceApiDefinition()) { importApi.setModulePath(existenceApi.getModulePath());
if (!StringUtils.equalsIgnoreCase(importApi.getProtocol(), ModuleConstants.NODE_PROTOCOL_HTTP)) { importApi.setModuleId(existenceApi.getModuleId());
if (StringUtils.equals(importApi.getName(), existenceApi.getName()) && StringUtils.equals(importApi.getModuleId(), existenceApi.getModuleId())) { } else {
existenceApiList.add(existenceApi); // 为修改数据赋予模块ID
this.updateApiDefinitionModule(importApi, selectModulePath, modulePathMap, selectModuleId, apiDefinitionPreImportAnalysisResult);
if (!StringUtils.equalsIgnoreCase(importApi.getProtocol(), ModuleConstants.NODE_PROTOCOL_HTTP)) {
//非HTTP接口判断是否存在相同接口的方式不一样也有可能出现多个相同接口所以这里要单独处理
List<ApiDefinitionDetail> existenceApiList = new ArrayList<>();
for (ApiDefinitionDetail existenceApi : existenceApiDefinitionDetail.getExistenceApiDefinition()) {
if (!StringUtils.equalsIgnoreCase(importApi.getProtocol(), ModuleConstants.NODE_PROTOCOL_HTTP)) {
if (StringUtils.equals(importApi.getName(), existenceApi.getName()) && StringUtils.equals(importApi.getModuleId(), existenceApi.getModuleId())) {
existenceApiList.add(existenceApi);
}
} }
} }
} if (CollectionUtils.isEmpty(existenceApiList)) {
if (CollectionUtils.isEmpty(existenceApiList)) { //不存在相同用例走新建逻辑
//不存在相同用例走新建逻辑 insertAndUpdateData.getInsertApiList().add(importApi);
insertAndUpdateData.getInsertApiList().add(importApi); removeList.add(existenceApiDefinitionDetail);
removeList.add(existenceApiDefinitionDetail); } else {
} else { //更新相同用例的数据集合
//更新相同用例的数据集合 existenceApiDefinitionDetail.setExistenceApiDefinition(existenceApiList);
existenceApiDefinitionDetail.setExistenceApiDefinition(existenceApiList); }
} }
} }
} }
@ -734,6 +747,8 @@ public class ApiDefinitionImportService {
* @param apiDefinitionPreImportAnalysisResult 如果有需要创建的模块要存储在result中 * @param apiDefinitionPreImportAnalysisResult 如果有需要创建的模块要存储在result中
*/ */
private void updateApiDefinitionModule(ApiDefinitionDetail importApi, String selectModulePath, Map<String, BaseTreeNode> modulePathMap, String importModuleId, ApiDefinitionPreImportAnalysisResult apiDefinitionPreImportAnalysisResult) { private void updateApiDefinitionModule(ApiDefinitionDetail importApi, String selectModulePath, Map<String, BaseTreeNode> modulePathMap, String importModuleId, ApiDefinitionPreImportAnalysisResult apiDefinitionPreImportAnalysisResult) {
// 开启同步更改接口模块时
if (StringUtils.isNotBlank(importApi.getModulePath()) && !StringUtils.startsWith(importApi.getModulePath(), "/")) { if (StringUtils.isNotBlank(importApi.getModulePath()) && !StringUtils.startsWith(importApi.getModulePath(), "/")) {
importApi.setModulePath("/" + importApi.getModulePath()); importApi.setModulePath("/" + importApi.getModulePath());
} }
@ -745,6 +760,7 @@ public class ApiDefinitionImportService {
} else { } else {
if (importApi.getModulePath() == null) { if (importApi.getModulePath() == null) {
importApi.setModulePath(StringUtils.EMPTY); importApi.setModulePath(StringUtils.EMPTY);
importApi.setModuleId(ModuleConstants.DEFAULT_NODE_ID);
} }
// 指定了导入模块 以当前模块为基准进行操作 // 指定了导入模块 以当前模块为基准进行操作
String finalModulePath = (StringUtils.isBlank(selectModulePath) ? StringUtils.EMPTY : selectModulePath) String finalModulePath = (StringUtils.isBlank(selectModulePath) ? StringUtils.EMPTY : selectModulePath)