parent
7168be9b55
commit
9cd5d1a65d
@ -0,0 +1,48 @@
|
|||||||
|
package com.dsideal.base.Plugin;
|
||||||
|
|
||||||
|
import freemarker.template.Template;
|
||||||
|
import freemarker.template.TemplateException;
|
||||||
|
import io.github.yedaxia.apidocs.DocContext;
|
||||||
|
import io.github.yedaxia.apidocs.IPluginSupport;
|
||||||
|
import io.github.yedaxia.apidocs.Resources;
|
||||||
|
import io.github.yedaxia.apidocs.Utils;
|
||||||
|
import io.github.yedaxia.apidocs.parser.ControllerNode;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class PostmanDocPlugin implements IPluginSupport {
|
||||||
|
public PostmanDocPlugin() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void execute(List<ControllerNode> controllerNodeList) {
|
||||||
|
FileWriter docFileWriter = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
Template ctrlTemplate = this.getDocTpl();
|
||||||
|
|
||||||
|
String docFileName = String.format("%s-%s-api-docs.json", DocContext.getDocsConfig().getProjectName(), DocContext.getDocsConfig().getApiVersion());
|
||||||
|
File docFile = new File(DocContext.getDocPath(), docFileName);
|
||||||
|
docFileWriter = new FileWriter(docFile);
|
||||||
|
Map<String, Object> data = new HashMap();
|
||||||
|
data.put("controllerNodes", controllerNodeList);
|
||||||
|
data.put("currentApiVersion", DocContext.getCurrentApiVersion());
|
||||||
|
data.put("projectName", DocContext.getDocsConfig().getProjectName());
|
||||||
|
data.put("i18n", DocContext.getI18n());
|
||||||
|
ctrlTemplate.process(data, docFileWriter);
|
||||||
|
|
||||||
|
} catch (IOException | TemplateException var10) {
|
||||||
|
var10.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
Utils.closeSilently(docFileWriter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Template getDocTpl() throws IOException {
|
||||||
|
return Resources.getFreemarkerTemplate("postman-doc.json.ftl");
|
||||||
|
}
|
||||||
|
}
|
@ -1,80 +0,0 @@
|
|||||||
package com.dsideal.base.fay.tree.domain;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.alibaba.fastjson.annotation.JSONField;
|
|
||||||
import com.dsideal.base.fay.tree.service.IFayTreeNode;
|
|
||||||
|
|
||||||
public class FayTreeNode {
|
|
||||||
|
|
||||||
@JSONField(ordinal=1)
|
|
||||||
private String nodeId;
|
|
||||||
|
|
||||||
@JSONField(ordinal=3)
|
|
||||||
private String parentNodeId;
|
|
||||||
|
|
||||||
private FayTreeNode parent;
|
|
||||||
|
|
||||||
private IFayTreeNode treeObject;
|
|
||||||
|
|
||||||
@JSONField(ordinal=6)
|
|
||||||
private List<FayTreeNode> children = new ArrayList<FayTreeNode>();
|
|
||||||
|
|
||||||
private List<FayTreeNode> allChildren = new ArrayList<FayTreeNode>();
|
|
||||||
|
|
||||||
public FayTreeNode(IFayTreeNode obj){
|
|
||||||
this.nodeId = obj.getNodeId();
|
|
||||||
this.parentNodeId = obj.getNodeParentId();
|
|
||||||
this.treeObject = obj;
|
|
||||||
}
|
|
||||||
public void addChild(FayTreeNode treeNode){
|
|
||||||
this.children.add(treeNode);
|
|
||||||
}
|
|
||||||
public void removeChild(FayTreeNode treeNode){
|
|
||||||
this.children.remove(treeNode);
|
|
||||||
}
|
|
||||||
public String getNodeId() {
|
|
||||||
return nodeId;
|
|
||||||
}
|
|
||||||
public void setNodeId(String nodeId) {
|
|
||||||
this.nodeId = nodeId;
|
|
||||||
}
|
|
||||||
public String getParentNodeId() {
|
|
||||||
return parentNodeId;
|
|
||||||
}
|
|
||||||
public void setParentNodeId(String parentNodeId) {
|
|
||||||
this.parentNodeId = parentNodeId;
|
|
||||||
}
|
|
||||||
public FayTreeNode getParent() {
|
|
||||||
return parent;
|
|
||||||
}
|
|
||||||
public void setParent(FayTreeNode parent) {
|
|
||||||
this.parent = parent;
|
|
||||||
}
|
|
||||||
public List<FayTreeNode> getChildren() {
|
|
||||||
if(children == null || children.isEmpty()) return null;
|
|
||||||
return children;
|
|
||||||
}
|
|
||||||
public void setChildren(List<FayTreeNode> children) {
|
|
||||||
this.children = children;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IFayTreeNode getTreeObject() {
|
|
||||||
return treeObject;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTreeObject(IFayTreeNode treeObject) {
|
|
||||||
this.treeObject = treeObject;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<FayTreeNode> getAllChildren() {
|
|
||||||
if(this.allChildren.isEmpty()){
|
|
||||||
for(FayTreeNode treeNode : this.children){
|
|
||||||
this.allChildren.add(treeNode);
|
|
||||||
this.allChildren.addAll(treeNode.getAllChildren());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return this.allChildren;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,69 +0,0 @@
|
|||||||
package com.dsideal.base.fay.tree.domain;
|
|
||||||
|
|
||||||
import com.dsideal.base.fay.tree.service.IFayTreeNode;
|
|
||||||
|
|
||||||
public class MenuBean implements IFayTreeNode {
|
|
||||||
private String menu_id;
|
|
||||||
private String parentId;
|
|
||||||
private String menu_name;
|
|
||||||
private String url;
|
|
||||||
private String memo;
|
|
||||||
|
|
||||||
public MenuBean(String menu_id, String parentId, String menu_name, String url, String type) {
|
|
||||||
this.menu_id = menu_id;
|
|
||||||
this.parentId = parentId;
|
|
||||||
this.menu_name = menu_name;
|
|
||||||
this.url = url;
|
|
||||||
this.memo = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getNodeId() {
|
|
||||||
return this.menu_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getNodeParentId() {
|
|
||||||
return this.parentId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMenu_id() {
|
|
||||||
return menu_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMenu_id(String menu_id) {
|
|
||||||
this.menu_id = menu_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getParentId() {
|
|
||||||
return parentId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setParentId(String parentId) {
|
|
||||||
this.parentId = parentId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMenu_name() {
|
|
||||||
return menu_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMenu_name(String menu_name) {
|
|
||||||
this.menu_name = menu_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUrl() {
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUrl(String url) {
|
|
||||||
this.url = url;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMemo() {
|
|
||||||
return memo;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMemo(String memo) {
|
|
||||||
this.memo = memo;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
package com.dsideal.base.fay.tree.service;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.dsideal.base.fay.tree.domain.FayTreeNode;
|
|
||||||
|
|
||||||
public interface IFayTree {
|
|
||||||
List<FayTreeNode> getTree();
|
|
||||||
List<FayTreeNode> getRoot();
|
|
||||||
FayTreeNode getFayTreeNode(String nodeId);
|
|
||||||
}
|
|
@ -1,6 +0,0 @@
|
|||||||
package com.dsideal.base.fay.tree.service;
|
|
||||||
|
|
||||||
public interface IFayTreeNode {
|
|
||||||
String getNodeId();
|
|
||||||
String getNodeParentId();
|
|
||||||
}
|
|
@ -1,84 +0,0 @@
|
|||||||
package com.dsideal.base.fay.tree.service.impl;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.dsideal.base.fay.tree.domain.FayTreeNode;
|
|
||||||
import com.dsideal.base.fay.tree.service.IFayTree;
|
|
||||||
import com.dsideal.base.fay.tree.service.IFayTreeNode;
|
|
||||||
|
|
||||||
public class FayTree implements IFayTree {
|
|
||||||
private HashMap<String, FayTreeNode> treeNodesMap = new LinkedHashMap<String, FayTreeNode>();
|
|
||||||
private List<FayTreeNode> treeNodesList = new ArrayList<FayTreeNode>();
|
|
||||||
|
|
||||||
public FayTree(List<IFayTreeNode> list){
|
|
||||||
initTreeNodeMap(list);
|
|
||||||
initTreeNodeList();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initTreeNodeMap(List<IFayTreeNode> list){
|
|
||||||
FayTreeNode treeNode = null;
|
|
||||||
for(IFayTreeNode item : list){
|
|
||||||
treeNode = new FayTreeNode(item);
|
|
||||||
treeNodesMap.put(treeNode.getNodeId(), treeNode);
|
|
||||||
}
|
|
||||||
|
|
||||||
Iterator<FayTreeNode> iter = treeNodesMap.values().iterator();
|
|
||||||
FayTreeNode parentTreeNode = null;
|
|
||||||
while(iter.hasNext()){
|
|
||||||
treeNode = iter.next();
|
|
||||||
if(treeNode.getParentNodeId() == null || treeNode.getParentNodeId() == ""){
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
parentTreeNode = treeNodesMap.get(treeNode.getParentNodeId());
|
|
||||||
if(parentTreeNode != null){
|
|
||||||
treeNode.setParent(parentTreeNode);
|
|
||||||
parentTreeNode.addChild(treeNode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initTreeNodeList(){
|
|
||||||
if(treeNodesList.size() > 0){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(treeNodesMap.size() == 0){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Iterator<FayTreeNode> iter = treeNodesMap.values().iterator();
|
|
||||||
FayTreeNode treeNode = null;
|
|
||||||
while(iter.hasNext()){
|
|
||||||
treeNode = iter.next();
|
|
||||||
if(treeNode.getParent() == null){
|
|
||||||
this.treeNodesList.add(treeNode);
|
|
||||||
this.treeNodesList.addAll(treeNode.getAllChildren());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<FayTreeNode> getTree() {
|
|
||||||
return this.treeNodesList;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<FayTreeNode> getRoot() {
|
|
||||||
List<FayTreeNode> rootList = new ArrayList<FayTreeNode>();
|
|
||||||
if (this.treeNodesList.size() > 0) {
|
|
||||||
for (FayTreeNode node : treeNodesList) {
|
|
||||||
if (node.getParent() == null)
|
|
||||||
rootList.add(node);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return rootList;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public FayTreeNode getFayTreeNode(String nodeId) {
|
|
||||||
return this.treeNodesMap.get(nodeId);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,27 +0,0 @@
|
|||||||
package com.dsideal.base.fay.tree.util;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
import com.alibaba.fastjson.serializer.SimplePropertyPreFilter;
|
|
||||||
import com.dsideal.base.fay.tree.service.IFayTreeNode;
|
|
||||||
import com.dsideal.base.fay.tree.service.impl.FayTree;
|
|
||||||
|
|
||||||
public class FayTreeUtil {
|
|
||||||
|
|
||||||
public static Object getTreeInJsonObject(List<? extends IFayTreeNode> list){
|
|
||||||
if(list == null || list.isEmpty()){
|
|
||||||
return new ArrayList<>();
|
|
||||||
}
|
|
||||||
FayTree tree = new FayTree(new ArrayList<>(list));
|
|
||||||
SimplePropertyPreFilter filter = new SimplePropertyPreFilter(); // 构造方法里,也可以直接传需要序列化的属性名字
|
|
||||||
filter.getExcludes().add("parent");
|
|
||||||
filter.getExcludes().add("allChildren");
|
|
||||||
filter.getExcludes().add("parentNodeId");
|
|
||||||
filter.getExcludes().add("nodeId");
|
|
||||||
String treeJsonString = JSONObject.toJSONString(tree.getRoot(), filter);
|
|
||||||
Object data = JSONObject.parse(treeJsonString);
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in new issue