From 66f79de62e1f4bb453f08304854f6f9ae9f3df6c Mon Sep 17 00:00:00 2001 From: guoyuqi Date: Thu, 13 Oct 2022 17:21:39 +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=85=A5jsonschem?= =?UTF-8?q?a=E6=97=B6=E6=B2=A1=E6=9C=89properties=E5=B1=9E=E6=80=A7?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E4=BC=9A=E9=94=99=E4=B9=B1=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --user=郭雨琦 https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001017370 --- .../io/metersphere/api/parse/api/Swagger3Parser.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 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 6f44210ba2..b85076f08c 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 @@ -328,6 +328,11 @@ public class Swagger3Parser extends SwaggerAbstractParser { Set refSet = new HashSet<>(); Map infoMap = new HashMap(); Schema schema = mediaType.getSchema(); + if (StringUtils.isBlank(schema.get$ref()) && schema.getItems()==null && StringUtils.isNotBlank(schema.getType()) && StringUtils.equals(schema.getType(),"string")) { + ObjectSchema objectSchema = new ObjectSchema(); + objectSchema.setExample(schema.getExample()); + schema = objectSchema; + } Object bodyData = null; if (!StringUtils.equals(contentType, org.springframework.http.MediaType.APPLICATION_JSON_VALUE)) { bodyData = parseSchemaToJson(schema, refSet, infoMap); @@ -341,7 +346,11 @@ public class Swagger3Parser extends SwaggerAbstractParser { } else if (StringUtils.equals(contentType, org.springframework.http.MediaType.MULTIPART_FORM_DATA_VALUE)) { parseKvBody(schema, body, bodyData, infoMap); } else if (StringUtils.equals(contentType, org.springframework.http.MediaType.APPLICATION_JSON_VALUE)) { - body.setJsonSchema(parseSchema(schema, refSet)); + JsonSchemaItem jsonSchemaItem = parseSchema(schema, refSet); + if (MapUtils.isEmpty(jsonSchemaItem.getProperties())) { + jsonSchemaItem.setProperties(new HashMap<>()); + } + body.setJsonSchema(jsonSchemaItem); body.setFormat("JSON-SCHEMA"); } else if (StringUtils.equals(contentType, org.springframework.http.MediaType.APPLICATION_XML_VALUE)) { body.setRaw(parseXmlBody(schema, bodyData)); @@ -513,7 +522,6 @@ public class Swagger3Parser extends SwaggerAbstractParser { } else { item.getMock().put(PropertyConstant.MOCK, ""); } - item.setDescription(schema.getDescription()); item.setPattern(schema.getPattern()); item.setMaxLength(schema.getMaxLength());