From 7436b19964ec1bf571f1f485e9f5adc46c4e55c9 Mon Sep 17 00:00:00 2001 From: wxg0103 <727495428@qq.com> Date: Mon, 22 May 2023 11:49:47 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8Dswagger=E5=AF=BC=E5=85=A5=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E7=9A=84=E7=BC=BA=E9=99=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1026379 --user=王孝刚 [接口测试]github#24501接口定义-Swagger 导入报“解析数据出错” https://www.tapd.cn/55049933/s/1373638 --- .../api/parse/api/Swagger3Parser.java | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/api-test/backend/src/main/java/io/metersphere/api/parse/api/Swagger3Parser.java b/api-test/backend/src/main/java/io/metersphere/api/parse/api/Swagger3Parser.java index e69ea7cb34..9d10c9a08e 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/parse/api/Swagger3Parser.java +++ b/api-test/backend/src/main/java/io/metersphere/api/parse/api/Swagger3Parser.java @@ -33,6 +33,7 @@ import io.swagger.v3.parser.core.models.AuthorizationValue; import io.swagger.v3.parser.core.models.SwaggerParseResult; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; +import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; import org.json.JSONArray; import org.json.JSONObject; @@ -616,16 +617,18 @@ public class Swagger3Parser extends SwaggerAbstractParser { Schema schema = getSchema(parameter.getSchema()); Set refSet = new HashSet<>(); JsonSchemaItem jsonSchemaItem = parseSchema(schema, refSet); - if (MapUtils.isEmpty(jsonSchemaItem.getProperties())) { - arguments.add(new KeyValue(queryParameter.getName(), getDefaultValue(queryParameter, jsonSchemaItem), getDefaultStringValue(queryParameter.getDescription()), parameter.getRequired(), getMin(jsonSchemaItem), getMax(jsonSchemaItem))); - } else { - Map properties = jsonSchemaItem.getProperties(); - properties.forEach((key, value) -> { - arguments.add(new KeyValue(key, getDefaultValue(queryParameter, value), - getDefaultStringValue(value.getDescription()), - parameter.getRequired(), - getMin(value), getMax(value))); - }); + if (ObjectUtils.isNotEmpty(jsonSchemaItem)) { + if (MapUtils.isEmpty(jsonSchemaItem.getProperties())) { + arguments.add(new KeyValue(queryParameter.getName(), getDefaultValue(queryParameter, jsonSchemaItem), getDefaultStringValue(queryParameter.getDescription()), parameter.getRequired(), getMin(jsonSchemaItem), getMax(jsonSchemaItem))); + } else { + Map properties = jsonSchemaItem.getProperties(); + properties.forEach((key, value) -> { + arguments.add(new KeyValue(key, getDefaultValue(queryParameter, value), + getDefaultStringValue(value.getDescription()), + parameter.getRequired(), + getMin(value), getMax(value))); + }); + } } }