From 66f9d71b8e8b2d09407513806d7077d64dea6a9f Mon Sep 17 00:00:00 2001 From: tanghc Date: Mon, 26 Aug 2019 17:37:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=BF=94=E5=9B=9E=E6=95=B0?= =?UTF-8?q?=E7=BB=84=E6=96=87=E6=A1=A3=E4=B8=8D=E6=98=BE=E7=A4=BA=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../manager/SwaggerDocParser.java | 34 ++++++++----------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/sop-website/website-server/src/main/java/com/gitee/sop/websiteserver/manager/SwaggerDocParser.java b/sop-website/website-server/src/main/java/com/gitee/sop/websiteserver/manager/SwaggerDocParser.java index 0d7dc8ae..6bf8a1cc 100644 --- a/sop-website/website-server/src/main/java/com/gitee/sop/websiteserver/manager/SwaggerDocParser.java +++ b/sop-website/website-server/src/main/java/com/gitee/sop/websiteserver/manager/SwaggerDocParser.java @@ -137,14 +137,13 @@ public class SwaggerDocParser implements DocParser { }) .collect(Collectors.groupingBy(DocParameter::getModule)); - collect.entrySet() - .forEach(entry -> { - DocParameter moduleDoc = new DocParameter(); - moduleDoc.setName(entry.getKey()); - moduleDoc.setType("object"); - moduleDoc.setRefs(entry.getValue()); - docParameterList.add(moduleDoc); - }); + collect.forEach((key, value) -> { + DocParameter moduleDoc = new DocParameter(); + moduleDoc.setName(key); + moduleDoc.setType("object"); + moduleDoc.setRefs(value); + docParameterList.add(moduleDoc); + }); return docParameterList.stream() .filter(docParameter -> !docParameter.getName().contains(".")) @@ -242,32 +241,29 @@ public class SwaggerDocParser implements DocParser { return Optional.ofNullable(docInfo.getJSONObject("responses")) .flatMap(jsonObject -> Optional.ofNullable(jsonObject.getJSONObject("200"))) .flatMap(jsonObject -> Optional.ofNullable(jsonObject.getJSONObject("schema"))) - .flatMap(schema -> { - RefInfo refInfo = getRefInfo(schema); - return Optional.ofNullable(refInfo); - }) + .map(this::getRefInfo) .orElse(null); } private RefInfo getRefInfo(JSONObject jsonObject) { - String $ref; + String ref; boolean isArray = "array".equals(jsonObject.getString("type")); if (isArray) { - $ref = jsonObject.getJSONObject("items").getString("$ref"); + ref = jsonObject.getJSONObject("items").getString("$ref"); } else { // #/definitions/Category - $ref = jsonObject.getString("$ref"); + ref = jsonObject.getString("$ref"); } - if ($ref == null) { + if (ref == null) { return null; } - int index = $ref.lastIndexOf("/"); + int index = ref.lastIndexOf("/"); if (index > -1) { - $ref = $ref.substring(index + 1); + ref = ref.substring(index + 1); } RefInfo refInfo = new RefInfo(); refInfo.isArray = isArray; - refInfo.ref = $ref; + refInfo.ref = ref; return refInfo; }