From 7d51f5ddef9314b5693ff5604c5157f33993aeee Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Fri, 23 Apr 2021 17:56:41 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=8E=A5=E5=8F=A3=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E5=AF=BC=E5=87=BA=E4=B8=BAswagger?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/definition/parse/Swagger3Parser.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 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 3319eb5685..1b2bba024f 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 @@ -542,6 +542,9 @@ public class Swagger3Parser extends SwaggerAbstractParser { } else { // JSONOArray parsedParam.put("type", "array"); JSONObject item = new JSONObject(); + if (param == null) { + param = new JSONArray(); + } if(((JSONArray) param).size() > 0) { if(((JSONArray) param).get(0) instanceof JSONObject) { /// item = buildRequestBodyJsonInfo((JSONObject) ((JSONArray) param).get(0)); @@ -591,11 +594,14 @@ public class Swagger3Parser extends SwaggerAbstractParser { } */ private JSONObject buildResponseBody(JSONObject response) { + if (response == null) { + return new JSONObject(); + } JSONObject responseBody = new JSONObject(); JSONObject statusCodeInfo = new JSONObject(); // build 请求头 JSONObject headers = new JSONObject(); - JSONArray headValueList =response.getJSONArray("headers"); + JSONArray headValueList = response.getJSONArray("headers"); if(headValueList != null) { for(Object item : headValueList) { if(item instanceof JSONObject && ((JSONObject) item).getString("name") != null) { @@ -654,12 +660,14 @@ public class Swagger3Parser extends SwaggerAbstractParser { } } String type = respOrReq.getJSONObject("body").getString("type"); + JSONObject content = new JSONObject(); JSONObject schema = bodyInfo; // 请求体部分 JSONObject typeName = new JSONObject(); - schema.put("type", null); - schema.put("format", null); - typeName.put("schema", schema); - JSONObject content = new JSONObject(); + if (schema != null) { + schema.put("type", null); + schema.put("format", null); + typeName.put("schema", schema); + } if (type != null && StringUtils.isNotBlank(type)) { content.put(typeMap.get(type), typeName); }