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