in shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/impl/SwaggerDocParser.java [58:111]
public DocInfo parseJson(final JsonObject docRoot) {
final String basePath = docRoot.get("basePath").getAsString();
final String title = Optional.ofNullable(docRoot.getAsJsonObject("info")).map(jsonObject -> jsonObject.get("title").getAsString()).orElse(basePath);
final List<DocItem> docItems = new ArrayList<>();
JsonObject paths = docRoot.getAsJsonObject("paths");
if (Objects.isNull(paths)) {
paths = new JsonObject();
}
Set<String> pathNameSet = paths.keySet();
for (String apiPath : pathNameSet) {
JsonObject pathInfo = paths.getAsJsonObject(apiPath);
Collection<String> httpMethodList = getHttpMethods(pathInfo);
Optional<String> first = httpMethodList.stream().findFirst();
if (first.isPresent()) {
String method = first.get();
JsonObject docInfo = pathInfo.getAsJsonObject(method);
docInfo.addProperty("real_req_path", apiPath);
docInfo.addProperty("basePath", basePath);
DocItem docItem = buildDocItem(docInfo, docRoot);
if (Objects.isNull(docItem)) {
continue;
}
if (docItem.isUploadRequest()) {
docItem.setHttpMethodList(Sets.newHashSet("post"));
} else {
docItem.setHttpMethodList(httpMethodList);
}
docItems.add(docItem);
}
}
docItems.sort(Comparator.comparing(DocItem::getApiOrder).thenComparing(DocItem::getName));
List<DocModule> docModuleList = docItems.stream()
.collect(Collectors.groupingBy(DocItem::getModule))
.entrySet()
.stream()
.map(entry -> {
List<DocItem> docItemList = entry.getValue();
DocModule docModule = new DocModule();
docModule.setModule(entry.getKey());
docModule.setDocItems(docItemList);
docModule.setOrder(getMuduleOrder(docItemList));
return docModule;
})
.sorted(Comparator.comparing(DocModule::getOrder))
.collect(Collectors.toList());
DocInfo docInfo = new DocInfo();
docInfo.setTitle(title);
docInfo.setDocModuleList(docModuleList);
return docInfo;
}