From fb0653c0f0970ef18dd0afb954be1ed239fd4082 Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Thu, 23 Jul 2020 11:54:35 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=8F=92=E4=BB=B6=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=E5=A4=B4=E7=AD=89=E4=BF=A1=E6=81=AF=E7=BC=BA?= =?UTF-8?q?=E5=A4=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/metersphere/api/parse/MsParser.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/parse/MsParser.java b/backend/src/main/java/io/metersphere/api/parse/MsParser.java index c562f6c2ca..0b77a2c126 100644 --- a/backend/src/main/java/io/metersphere/api/parse/MsParser.java +++ b/backend/src/main/java/io/metersphere/api/parse/MsParser.java @@ -11,6 +11,7 @@ import org.apache.commons.lang3.StringUtils; import org.eclipse.jetty.http.HttpMethod; import java.io.InputStream; +import java.util.Map; public class MsParser extends ApiImportAbstractParser { @@ -37,9 +38,17 @@ public class MsParser extends ApiImportAbstractParser { JSONArray requestsObjects = new JSONArray(); JSONObject requestsObject = testObject.getJSONObject(scenarioName); requestsObject.keySet().forEach(requestName -> { - JSONObject requestObject = requestsObject.getJSONObject(requestName); + JSONObject requestObject = new JSONObject(true); + JSONObject requestTmpObject = requestsObject.getJSONObject(requestName); + //排序,确保type在第一个,否则转换失败 + if (StringUtils.isBlank(requestTmpObject.getString("type"))) { + requestObject.put("type", RequestType.HTTP); + } + + requestTmpObject.keySet().forEach(key -> { + requestObject.put(key, requestTmpObject.get(key)); + });; requestObject.put("name", requestName); - requestObject.put("type", RequestType.HTTP); JSONArray bodies = requestObject.getJSONArray("body"); if (StringUtils.equalsIgnoreCase(requestObject.getString("method"), HttpMethod.POST.name()) && bodies != null) { StringBuilder bodyStr = new StringBuilder();