From 0cfcdfdf73c9754d6c90a358ceb202ee882a82b9 Mon Sep 17 00:00:00 2001 From: guoyuqi Date: Tue, 12 Apr 2022 14:34:53 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20sw?= =?UTF-8?q?agger3.0=E5=AF=BC=E5=85=A5=E5=AF=BC=E5=87=BA=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --user=郭雨琦 --bug=1012087 【接口测试】 github#12447 ,swagger url导入接口文档,字段的 值 丢失 https://www.tapd.cn/55049933/bugtrace/bugs/view?bug_id=1155049933001012087 --- .../api/dto/definition/parse/Swagger3Parser.java | 15 +++++++++++---- 1 file changed, 11 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 c24740b3a9..23ff48002c 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 @@ -495,7 +495,7 @@ public class Swagger3Parser extends SwaggerAbstractParser { return null; } - if (schema.getExample() != null) { + if (schema.getExample() != null) { item.getMock().put("mock", schema.getExample()); } else { item.getMock().put("mock", ""); @@ -511,6 +511,7 @@ public class Swagger3Parser extends SwaggerAbstractParser { Map JsonSchemaProperties = new LinkedHashMap<>(); properties.forEach((key, value) -> { JsonSchemaItem item = new JsonSchemaItem(); + item.setType(schema.getType()); item.setDescription(schema.getDescription()); JsonSchemaItem proItem = parseSchema(value, refSet); if (proItem != null) JsonSchemaProperties.put(key, proItem); @@ -739,11 +740,11 @@ public class Swagger3Parser extends SwaggerAbstractParser { } else if (StringUtils.equals(type, "object")) { parsedParam.put("type", "object"); JSONObject properties = requestBody.getJSONObject("properties"); - + JSONObject jsonObject = buildFormDataSchema(properties); if (StringUtils.isNotBlank(requestBody.getString("description"))) { parsedParam.put("description", requestBody.getString("description")); } - parsedParam.put("properties", properties); + parsedParam.put("properties", jsonObject.getJSONObject("properties")); } else if (StringUtils.equals(type, "integer")) { parsedParam.put("type", "integer"); parsedParam.put("format", "int64"); @@ -828,7 +829,13 @@ public class Swagger3Parser extends SwaggerAbstractParser { JSONObject obj = ((JSONObject) kvs.get(key)); property.put("type", StringUtils.isNotEmpty(obj.getString("type")) ? obj.getString("type") : "string"); String value = obj.getString("value"); - property.put("example", value); + if(StringUtils.isBlank(value)){ + JSONObject mock = obj.getJSONObject("mock"); + Object mockValue = mock.get("mock"); + property.put("example", mockValue); + }else{ + property.put("example", value); + } property.put("description", obj.getString("description")); property.put("required", obj.getString("required")); properties.put(key, property);