mirror of
https://gitee.com/durcframework/SOP.git
synced 2025-08-12 07:02:14 +08:00
4.0.0
This commit is contained in:
@@ -23,16 +23,14 @@ import java.util.function.Consumer;
|
|||||||
public class DocManagerImpl implements DocManager {
|
public class DocManagerImpl implements DocManager {
|
||||||
|
|
||||||
// key:title
|
// key:title
|
||||||
private Map<String, DocInfo> docDefinitionMap = new HashMap<>();
|
private static final Map<String, DocInfo> docDefinitionMap = new HashMap<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* KEY:serviceId, value: md5
|
* KEY:serviceId, value: md5
|
||||||
*/
|
*/
|
||||||
private Map<String, String> serviceIdMd5Map = new HashMap<>();
|
private static final Map<String, String> serviceIdMd5Map = new HashMap<>();
|
||||||
|
|
||||||
private DocParser swaggerDocParser = new SwaggerDocParser();
|
private static final DocParser swaggerDocParser = new SwaggerDocParser();
|
||||||
|
|
||||||
private DocParser easyopenDocParser = new EasyopenDocParser();
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addDocInfo(String serviceId, String docInfoJson, Consumer<DocInfo> callback) {
|
public void addDocInfo(String serviceId, String docInfoJson, Consumer<DocInfo> callback) {
|
||||||
@@ -43,22 +41,12 @@ public class DocManagerImpl implements DocManager {
|
|||||||
}
|
}
|
||||||
serviceIdMd5Map.put(serviceId, newMd5);
|
serviceIdMd5Map.put(serviceId, newMd5);
|
||||||
JSONObject docRoot = JSON.parseObject(docInfoJson, Feature.OrderedField, Feature.DisableCircularReferenceDetect);
|
JSONObject docRoot = JSON.parseObject(docInfoJson, Feature.OrderedField, Feature.DisableCircularReferenceDetect);
|
||||||
DocParser docParser = this.buildDocParser(docRoot);
|
DocInfo docInfo = swaggerDocParser.parseJson(docRoot);
|
||||||
DocInfo docInfo = docParser.parseJson(docRoot);
|
|
||||||
docInfo.setServiceId(serviceId);
|
docInfo.setServiceId(serviceId);
|
||||||
docDefinitionMap.put(docInfo.getTitle(), docInfo);
|
docDefinitionMap.put(docInfo.getTitle(), docInfo);
|
||||||
callback.accept(docInfo);
|
callback.accept(docInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected DocParser buildDocParser(JSONObject rootDoc) {
|
|
||||||
Object easyopen = rootDoc.get("easyopen");
|
|
||||||
if (easyopen != null) {
|
|
||||||
return easyopenDocParser;
|
|
||||||
} else {
|
|
||||||
return swaggerDocParser;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DocInfo getByTitle(String title) {
|
public DocInfo getByTitle(String title) {
|
||||||
return docDefinitionMap.get(title);
|
return docDefinitionMap.get(title);
|
||||||
|
@@ -1,83 +0,0 @@
|
|||||||
package com.gitee.sop.websiteserver.manager;
|
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONArray;
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
import com.gitee.sop.websiteserver.bean.DocInfo;
|
|
||||||
import com.gitee.sop.websiteserver.bean.DocItem;
|
|
||||||
import com.gitee.sop.websiteserver.bean.DocModule;
|
|
||||||
import com.gitee.sop.websiteserver.bean.DocParameter;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author tanghc
|
|
||||||
*/
|
|
||||||
public class EasyopenDocParser implements DocParser {
|
|
||||||
@Override
|
|
||||||
public DocInfo parseJson(JSONObject docRoot) {
|
|
||||||
String title = docRoot.getString("title");
|
|
||||||
List<DocItem> docItems = new ArrayList<>();
|
|
||||||
JSONArray apiModules = docRoot.getJSONArray("apiModules");
|
|
||||||
for (int i = 0; i < apiModules.size(); i++) {
|
|
||||||
JSONObject module = apiModules.getJSONObject(i);
|
|
||||||
JSONArray moduleItems = module.getJSONArray("moduleItems");
|
|
||||||
for (int k = 0; k < moduleItems.size(); k++) {
|
|
||||||
JSONObject docInfo = moduleItems.getJSONObject(k);
|
|
||||||
DocItem docItem = buildDocItem(docInfo);
|
|
||||||
docItem.setModule(module.getString("name"));
|
|
||||||
docItems.add(docItem);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
List<DocModule> docModuleList = docItems.stream()
|
|
||||||
.collect(Collectors.groupingBy(DocItem::getModule))
|
|
||||||
.entrySet()
|
|
||||||
.stream()
|
|
||||||
.map(entry -> {
|
|
||||||
DocModule docModule = new DocModule();
|
|
||||||
docModule.setModule(entry.getKey());
|
|
||||||
docModule.setDocItems(entry.getValue());
|
|
||||||
return docModule;
|
|
||||||
})
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
DocInfo docInfo = new DocInfo();
|
|
||||||
docInfo.setTitle(title);
|
|
||||||
docInfo.setDocModuleList(docModuleList);
|
|
||||||
return docInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected DocItem buildDocItem(JSONObject docInfo) {
|
|
||||||
DocItem docItem = new DocItem();
|
|
||||||
docItem.setName(docInfo.getString("name"));
|
|
||||||
docItem.setVersion(docInfo.getString("version"));
|
|
||||||
docItem.setSummary(docInfo.getString("description"));
|
|
||||||
docItem.setDescription(docInfo.getString("description"));
|
|
||||||
List<DocParameter> docParameterList = this.buildParameterList(docInfo, "paramDefinitions");
|
|
||||||
docItem.setRequestParameters(docParameterList);
|
|
||||||
|
|
||||||
List<DocParameter> responseParameterList = this.buildParameterList(docInfo, "resultDefinitions");
|
|
||||||
docItem.setResponseParameters(responseParameterList);
|
|
||||||
|
|
||||||
return docItem;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected List<DocParameter> buildParameterList(JSONObject docInfo, String key) {
|
|
||||||
JSONArray params = docInfo.getJSONArray(key);
|
|
||||||
if (params == null) {
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
List<DocParameter> docParameterList = new ArrayList<>();
|
|
||||||
for (int i = 0; i < params.size(); i++) {
|
|
||||||
JSONObject jsonObject = params.getJSONObject(i);
|
|
||||||
DocParameter docParameter = jsonObject.toJavaObject(DocParameter.class);
|
|
||||||
docParameter.setType(jsonObject.getString("dataType"));
|
|
||||||
docParameterList.add(docParameter);
|
|
||||||
}
|
|
||||||
return docParameterList;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Reference in New Issue
Block a user