From 82812a58db16f1fb22cb959cf9de8c18cfa6fb98 Mon Sep 17 00:00:00 2001 From: guoyuqi Date: Fri, 8 Jul 2022 15:55:46 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E8=A7=A3=E5=86=B3=E6=8E=A5=E5=8F=A3=E5=AF=BC=E5=87=BA=E4=B8=BA?= =?UTF-8?q?swagger=E6=97=B6=E4=B8=8D=E5=B8=A6=E6=A8=A1=E5=9D=97=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --user=郭雨琦 --bug=1014699 https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001014699 --- .../api/dto/definition/parse/Swagger3Parser.java | 11 ++++++----- .../metersphere/api/service/ApiAutomationService.java | 2 +- .../metersphere/api/service/ApiDefinitionService.java | 2 +- 3 files changed, 8 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 3472c1b7be..06d2dbcc8a 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 @@ -936,9 +936,7 @@ public class Swagger3Parser extends SwaggerAbstractParser { if (body != null) { // 将请求体转换成相应的格式导出 String bodyType = body.getString("type"); - if (bodyType == null) { - - } else if (bodyType.equalsIgnoreCase("JSON")) { + if (StringUtils.isNotBlank(bodyType) && bodyType.equalsIgnoreCase("JSON")) { try { if (StringUtils.equals(body.getString("format"), "JSON-SCHEMA")) { String jsonSchema = body.getString("jsonSchema"); @@ -986,14 +984,17 @@ public class Swagger3Parser extends SwaggerAbstractParser { } } - String type = respOrReq.getJSONObject("body").getString("type"); + String type = null; + if (respOrReq.getJSONObject("body") != null) { + type = respOrReq.getJSONObject("body").getString("type"); + } JSONObject content = new JSONObject(); Object schema = bodyInfo; // 请求体部分 JSONObject typeName = new JSONObject(); if (schema != null) { typeName.put("schema", schema);//schema.getJSONObject("properties").size() == 0? "" : } - if (type != null && StringUtils.isNotBlank(type)) { + if (StringUtils.isNotBlank(type)) { content.put(typeMap.get(type), typeName); } return content; diff --git a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java index bbd7861248..4a9e39e712 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java @@ -1335,7 +1335,7 @@ public class ApiAutomationService { _importCreate(sameList, batchMapper, extApiScenarioMapper, scenarioWithBLOBs, apiTestImportRequest, apiTestCaseMapper, apiDefinitionMapper); } else if (StringUtils.equals("incrementalMerge", apiTestImportRequest.getModeId())) { if (CollectionUtils.isEmpty(sameList)) { - if (scenarioWithBLOBs.getVersionId() == null || scenarioWithBLOBs.getVersionId().equals("new")) { + if (scenarioWithBLOBs.getVersionId() != null && scenarioWithBLOBs.getVersionId().equals("new")) { scenarioWithBLOBs.setLatest(apiTestImportRequest.getVersionId().equals(apiTestImportRequest.getDefaultVersion())); } else { scenarioWithBLOBs.setOrder(getImportNextOrder(request.getProjectId())); 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 8a0f984d92..1ee641e7a2 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java @@ -805,7 +805,7 @@ public class ApiDefinitionService { if (CollectionUtils.isEmpty(collect)) { String originId = apiDefinition.getId(); //postman 可能含有前置脚本,接口定义去掉脚本 - if (apiDefinition.getVersionId() == null || apiDefinition.getVersionId().equals("new")) { + if (apiDefinition.getVersionId() != null && apiDefinition.getVersionId().equals("new")) { apiDefinition.setLatest(apiTestImportRequest.getVersionId().equals(apiTestImportRequest.getDefaultVersion())); } else { apiDefinition.setOrder(getImportNextOrder(apiTestImportRequest.getProjectId()));