From bdb7d32d1ef8ca55c262fccf7ca785f219046f63 Mon Sep 17 00:00:00 2001 From: guoyuqi Date: Wed, 24 Aug 2022 17:15:53 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20sw?= =?UTF-8?q?agger=E5=AF=BC=E5=85=A5formdata=E5=80=BC=E5=A4=84=E7=90=86?= =?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=郭雨琦 https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001016219 --- .../dto/definition/parse/Swagger3Parser.java | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 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 acfe61b99f..2745f22ed9 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 @@ -396,6 +396,9 @@ public class Swagger3Parser extends SwaggerAbstractParser { if (MapUtils.isEmpty(properties)) return null; JSONObject jsonObject = new JSONObject(true); properties.forEach((key, value) -> { + if (StringUtils.isBlank(value.getName())) { + value.setName(key); + } jsonObject.put(key, parseSchemaToJson(value, refSet, infoMap)); }); return jsonObject; @@ -403,9 +406,18 @@ public class Swagger3Parser extends SwaggerAbstractParser { private void parseKvBody(Schema schema, Body body, Object data, Map infoMap) { if (data instanceof JSONObject) { - ((JSONObject) data).forEach((k, v) -> { - parseKvBodyItem(schema, body, k, infoMap); - }); + if (MapUtils.isNotEmpty(schema.getProperties())) { + schema.getProperties().forEach((key, value) -> { + if (value instanceof Schema) { + parseKvBodyItem(value, body, key.toString(), infoMap); + } + }); + } else { + ((JSONObject) data).forEach((k, v) -> { + parseKvBodyItem(schema, body, k, infoMap); + }); + } + } else { if (data instanceof Schema) { Schema dataSchema = (Schema) data; @@ -538,7 +550,7 @@ public class Swagger3Parser extends SwaggerAbstractParser { return example == null ? 0 : example; } else if (value instanceof NumberSchema) { return example == null ? 0.0 : example; - } else if (value instanceof StringSchema || StringUtils.equals("string", value.getType())) { + } else if (value instanceof StringSchema || StringUtils.equals("string", value.getType()) || StringUtils.equals("text", value.getType())) { return example == null ? "" : example; } else {// todo 其他类型? return getDefaultStringValue(value.getDescription());