pull/1/head
tanghc 5 years ago
parent 6408f0e7d2
commit e839692da4
  1. 3
      sop-website/src/main/java/com/gitee/sop/websiteserver/manager/DocDiscovery.java
  2. 34
      sop-website/src/main/java/com/gitee/sop/websiteserver/manager/SwaggerDocParser.java

@ -89,7 +89,8 @@ public class DocDiscovery {
docManager.addDocInfo( docManager.addDocInfo(
serviceName serviceName
, body , body
, callback -> log.info("加载服务文档,instance:{}", instance) , callback -> log.info("加载服务文档,serviceId={}, 机器={}"
, serviceName, instance.getIp() + ":" + instance.getPort())
); );
} }
} }

@ -137,14 +137,13 @@ public class SwaggerDocParser implements DocParser {
}) })
.collect(Collectors.groupingBy(DocParameter::getModule)); .collect(Collectors.groupingBy(DocParameter::getModule));
collect.entrySet() collect.forEach((key, value) -> {
.forEach(entry -> { DocParameter moduleDoc = new DocParameter();
DocParameter moduleDoc = new DocParameter(); moduleDoc.setName(key);
moduleDoc.setName(entry.getKey()); moduleDoc.setType("object");
moduleDoc.setType("object"); moduleDoc.setRefs(value);
moduleDoc.setRefs(entry.getValue()); docParameterList.add(moduleDoc);
docParameterList.add(moduleDoc); });
});
return docParameterList.stream() return docParameterList.stream()
.filter(docParameter -> !docParameter.getName().contains(".")) .filter(docParameter -> !docParameter.getName().contains("."))
@ -242,32 +241,29 @@ public class SwaggerDocParser implements DocParser {
return Optional.ofNullable(docInfo.getJSONObject("responses")) return Optional.ofNullable(docInfo.getJSONObject("responses"))
.flatMap(jsonObject -> Optional.ofNullable(jsonObject.getJSONObject("200"))) .flatMap(jsonObject -> Optional.ofNullable(jsonObject.getJSONObject("200")))
.flatMap(jsonObject -> Optional.ofNullable(jsonObject.getJSONObject("schema"))) .flatMap(jsonObject -> Optional.ofNullable(jsonObject.getJSONObject("schema")))
.flatMap(schema -> { .map(this::getRefInfo)
RefInfo refInfo = getRefInfo(schema);
return Optional.ofNullable(refInfo);
})
.orElse(null); .orElse(null);
} }
private RefInfo getRefInfo(JSONObject jsonObject) { private RefInfo getRefInfo(JSONObject jsonObject) {
String $ref; String ref;
boolean isArray = "array".equals(jsonObject.getString("type")); boolean isArray = "array".equals(jsonObject.getString("type"));
if (isArray) { if (isArray) {
$ref = jsonObject.getJSONObject("items").getString("$ref"); ref = jsonObject.getJSONObject("items").getString("$ref");
} else { } else {
// #/definitions/Category // #/definitions/Category
$ref = jsonObject.getString("$ref"); ref = jsonObject.getString("$ref");
} }
if ($ref == null) { if (ref == null) {
return null; return null;
} }
int index = $ref.lastIndexOf("/"); int index = ref.lastIndexOf("/");
if (index > -1) { if (index > -1) {
$ref = $ref.substring(index + 1); ref = ref.substring(index + 1);
} }
RefInfo refInfo = new RefInfo(); RefInfo refInfo = new RefInfo();
refInfo.isArray = isArray; refInfo.isArray = isArray;
refInfo.ref = $ref; refInfo.ref = ref;
return refInfo; return refInfo;
} }

Loading…
Cancel
Save