From fdeb2d4b237e556311936c2079411994c193edab Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Tue, 16 Nov 2021 13:18:37 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=8C=96):=20=E4=BF=AE=E5=A4=8Dswagger=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/definition/parse/Swagger3Parser.java | 28 +++++++++---------- .../request/sampler/MsHTTPSamplerProxy.java | 2 +- 2 files changed, 14 insertions(+), 16 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 6e23699cd6..0e812724d8 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 @@ -295,7 +295,6 @@ public class Swagger3Parser extends SwaggerAbstractParser { } private void parseKvBody(Schema schema, Body body, Object data, Map infoMap) { - if (data == null) return; if (data instanceof JSONObject) { ((JSONObject) data).forEach((k, v) -> { Schema dataSchema = (Schema) v; @@ -312,22 +311,21 @@ public class Swagger3Parser extends SwaggerAbstractParser { body.getKvs().add(kv); }); } else { - if (data instanceof String && StringUtils.isBlank((String) data)) { - return; - } - Schema dataSchema = (Schema) data; - KeyValue kv = new KeyValue(schema.getName(), String.valueOf(dataSchema.getExample()), schema.getDescription()); - Schema schemaInfo = infoMap.get(schema.getName()); - if (schemaInfo != null) { - if (schemaInfo instanceof BinarySchema) { - kv.setType("file"); + if(data instanceof Schema) { + Schema dataSchema = (Schema) data; + KeyValue kv = new KeyValue(schema.getName(), String.valueOf(dataSchema.getExample()), schema.getDescription()); + Schema schemaInfo = infoMap.get(schema.getName()); + if (schemaInfo != null) { + if (schemaInfo instanceof BinarySchema) { + kv.setType("file"); + } } - } - if (body != null) { - if (body.getKvs() == null) { - body.setKvs(new ArrayList<>()); + if (body != null) { + if (body.getKvs() == null) { + body.setKvs(new ArrayList<>()); + } + body.getKvs().add(kv); } - body.getKvs().add(kv); } } } diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java index 9d06f093f4..96351a3bf3 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java @@ -582,7 +582,7 @@ public class MsHTTPSamplerProxy extends MsTestElement { * @return */ private boolean isCustomizeReqCompleteUrl(String url) { - if (isCustomizeReq() && (url.startsWith("http://") || url.startsWith("https://"))) { + if (isCustomizeReq() && StringUtils.isNotEmpty(url) && (url.startsWith("http://") || url.startsWith("https://"))) { return true; } return false;