From be5f059836d4b7fafbc9a4e7a6bf3c1c6d8b1619 Mon Sep 17 00:00:00 2001 From: guoyuqi Date: Wed, 27 Jul 2022 17:47:53 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=AF=BC=E5=85=A5esb=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --user=郭雨琦 --- .../dto/definition/parse/Swagger3Parser.java | 2 +- .../api/service/ApiDefinitionService.java | 2 +- .../api/service/ApiModuleService.java | 23 +++++++++++++++---- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/parse/Swagger3Parser.java b/backend/src/main/java/io/metersphere/api/dto/definition/parse/Swagger3Parser.java index b533632537..7cd3e455c1 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/parse/Swagger3Parser.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/parse/Swagger3Parser.java @@ -461,7 +461,7 @@ public class Swagger3Parser extends SwaggerAbstractParser { private JsonSchemaItem parseSchema(Schema schema, Set refSet) { if (schema == null) return null; - if (StringUtils.isBlank(schema.get$ref()) && schema.getProperties() == null && refSet.isEmpty()) { + if (StringUtils.isBlank(schema.get$ref()) && schema.getProperties() == null && refSet.isEmpty() && schema.getExample() == null) { return null; } JsonSchemaItem item = new JsonSchemaItem(); diff --git a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java index 689d98686a..5604dc7d03 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java @@ -1015,9 +1015,9 @@ public class ApiDefinitionService { apiDefinition.setId(existApi.getId()); String request = setImportHashTree(apiDefinition); apiDefinition.setOrder(existApi.getOrder()); - batchMapper.updateByPrimaryKeyWithBLOBs(apiDefinition); apiDefinition.setRequest(request); reSetImportMocksApiId(mocks, originId, apiDefinition.getId(), apiDefinition.getNum()); + batchMapper.updateByPrimaryKeyWithBLOBs(apiDefinition); } else { apiDefinition.setId(existApi.getId()); if (StringUtils.equalsAnyIgnoreCase(apiDefinition.getProtocol(), RequestType.TCP)) { diff --git a/backend/src/main/java/io/metersphere/api/service/ApiModuleService.java b/backend/src/main/java/io/metersphere/api/service/ApiModuleService.java index c0f6039334..febebaf1a3 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiModuleService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiModuleService.java @@ -771,9 +771,9 @@ public class ApiModuleService extends NodeTreeService { //处理数据 if (fullCoverage) { if (fullCoverageApi) { - coverModule(toUpdateList, nameModuleMap, repeatDataMap, updateVersionId, definitionIdCaseMAp, oldCaseMap); + coverModule(toUpdateList, nameModuleMap, repeatDataMap, updateVersionId, definitionIdCaseMAp, oldCaseMap, apiImport.getEsbApiParamsMap()); } else { - moduleMap = cover(moduleMap, toUpdateList, nameModuleMap, repeatDataMap, updateVersionId, definitionIdCaseMAp, oldCaseMap); + moduleMap = cover(moduleMap, toUpdateList, nameModuleMap, repeatDataMap, updateVersionId, definitionIdCaseMAp, oldCaseMap, apiImport.getEsbApiParamsMap()); } } else { //不覆盖 @@ -784,7 +784,7 @@ public class ApiModuleService extends NodeTreeService { Map repeatMap = repeatApiDefinitionWithBLOBs.stream().collect(Collectors.toMap(t -> t.getName() + t.getModulePath(), api -> api)); Map optionMap = optionData.stream().collect(Collectors.toMap(t -> t.getName() + t.getModulePath(), api -> api)); if (fullCoverage) { - cover(moduleMap, toUpdateList, optionMap, repeatMap, updateVersionId, definitionIdCaseMAp, oldCaseMap); + cover(moduleMap, toUpdateList, optionMap, repeatMap, updateVersionId, definitionIdCaseMAp, oldCaseMap, apiImport.getEsbApiParamsMap()); } else { //不覆盖,同一接口不做更新 removeRepeat(optionData, optionMap, repeatMap, moduleMap, versionId, definitionIdCaseMAp, optionDataCases); @@ -878,7 +878,7 @@ public class ApiModuleService extends NodeTreeService { private Map cover(Map moduleMap, List toUpdateList, Map nameModuleMap, Map repeatDataMap, String updateVersionId, Map> definitionIdCaseMAp, - Map> oldCaseMap) { + Map> oldCaseMap, Map esbApiParamsMap) { //覆盖但不覆盖模块 if (nameModuleMap != null) { //导入文件没有新增接口无需创建接口模块 @@ -893,6 +893,7 @@ public class ApiModuleService extends NodeTreeService { } //该接口的case Map caseNameMap = getDistinctCaseNameMap(definitionIdCaseMAp, apiDefinitionWithBLOBs); + updateEsb(esbApiParamsMap, v.getId(), apiDefinitionWithBLOBs.getId()); apiDefinitionWithBLOBs.setId(v.getId()); apiDefinitionWithBLOBs.setVersionId(updateVersionId); apiDefinitionWithBLOBs.setModuleId(v.getModuleId()); @@ -915,6 +916,17 @@ public class ApiModuleService extends NodeTreeService { return moduleMap; } + private void updateEsb(Map esbApiParamsMap, String newId, String oldId) { + if (MapUtils.isNotEmpty(esbApiParamsMap)) { + EsbApiParamsWithBLOBs esbApiParamsWithBLOBs = esbApiParamsMap.get(oldId); + if (esbApiParamsWithBLOBs != null) { + esbApiParamsMap.remove(oldId); + esbApiParamsWithBLOBs.setResourceId(newId); + esbApiParamsMap.put(newId, esbApiParamsWithBLOBs); + } + } + } + private Map judgeModule(Map moduleMap, Map nameModuleMap, Map repeatDataMap) { AtomicBoolean remove = new AtomicBoolean(true); @@ -934,7 +946,7 @@ public class ApiModuleService extends NodeTreeService { private void coverModule(List toUpdateList, Map nameModuleMap, Map repeatDataMap, String updateVersionId, Map> definitionIdCaseMAp, - Map> oldCaseMap) { + Map> oldCaseMap, Map esbApiParamsMap) { if (nameModuleMap != null) { repeatDataMap.forEach((k, v) -> { ApiDefinitionWithBLOBs apiDefinitionWithBLOBs = nameModuleMap.get(k); @@ -946,6 +958,7 @@ public class ApiModuleService extends NodeTreeService { } //该接口的case Map caseNameMap = getDistinctCaseNameMap(definitionIdCaseMAp, apiDefinitionWithBLOBs); + updateEsb(esbApiParamsMap, v.getId(), apiDefinitionWithBLOBs.getId()); apiDefinitionWithBLOBs.setId(v.getId()); setApiParam(apiDefinitionWithBLOBs, updateVersionId, v); //组合case