From de2665e53cde6b0dfc74a1f790b1cb1efaee4952 Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Wed, 29 Dec 2021 15:36:11 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20swagger=E5=AF=BC=E5=85=A5=E6=8A=A5?= =?UTF-8?q?=E9=94=99=20--bug=3D1009378=20--user=3D=E9=99=88=E5=BB=BA?= =?UTF-8?q?=E6=98=9F=20[github=20#8948]=E5=AE=A2=E6=88=B7=E9=82=A3?= =?UTF-8?q?=E8=BE=B9=20=E4=BB=8Eyapi=E5=AF=BC=E5=87=BA=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=20swagger=202.0=E8=A7=84=E8=8C=83=E7=9A=84=E6=96=87=E6=A1=A3?= =?UTF-8?q?=EF=BC=8C=E5=AF=BC=E5=85=A5MS=E6=8F=90=E7=A4=BA=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=E9=94=99=E8=AF=AF=EF=BC=8Cpostman=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=E6=98=AFok=E7=9A=84=E3=80=82=20https://www.tapd.cn/55049933/s/?= =?UTF-8?q?10881544?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/dto/definition/parse/Swagger3Parser.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 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 309c955533..44181590a1 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 @@ -359,7 +359,10 @@ public class Swagger3Parser extends SwaggerAbstractParser { return new JSONObject(true); } refSet.add(schema.get$ref()); - Object propertiesResult = parseSchemaPropertiesToJson(getModelByRef(schema.get$ref()), refSet, infoMap); + Schema modelByRef = getModelByRef(schema.get$ref()); + Object propertiesResult = null; + if (modelByRef != null) + propertiesResult = parseSchemaPropertiesToJson(modelByRef, refSet, infoMap); return propertiesResult == null ? getDefaultValueByPropertyType(schema) : propertiesResult; } else if (schema instanceof ArraySchema) { JSONArray jsonArray = new JSONArray(); @@ -436,7 +439,9 @@ public class Swagger3Parser extends SwaggerAbstractParser { if (ref.split("/").length > 3) { ref = ref.replace("#/components/schemas/", ""); } - return this.components.getSchemas().get(ref); + if (this.components.getSchemas() != null) + return this.components.getSchemas().get(ref); + return null; } private JsonSchemaItem parseSchema(Schema schema, Set refSet) { @@ -446,7 +451,9 @@ public class Swagger3Parser extends SwaggerAbstractParser { if (refSet.contains(schema.get$ref())) return item; item.setType("object"); refSet.add(schema.get$ref()); - item.setProperties(parseSchemaProperties(getModelByRef(schema.get$ref()), refSet)); + Schema modelByRef = getModelByRef(schema.get$ref()); + if (modelByRef != null) + item.setProperties(parseSchemaProperties(modelByRef, refSet)); } else if (schema instanceof ArraySchema) { Schema items = ((ArraySchema) schema).getItems(); item.setType("array");