support dubbo rpc
This commit is contained in:
parent
0a5c19b1da
commit
fc82072114
|
@ -6,7 +6,7 @@ import com.power.doc.builder.BaseDocBuilderTemplate;
|
|||
import com.power.doc.constants.TemplateVariable;
|
||||
import com.power.doc.model.ApiConfig;
|
||||
import com.power.doc.model.ApiErrorCode;
|
||||
import com.power.doc.model.JavaApiDoc;
|
||||
import com.power.doc.model.rpc.RpcApiDoc;
|
||||
import com.power.doc.utils.BeetlTemplateUtil;
|
||||
import com.thoughtworks.qdox.JavaProjectBuilder;
|
||||
import org.beetl.core.Template;
|
||||
|
@ -29,14 +29,18 @@ public class RpcDocBuilderTemplate extends BaseDocBuilderTemplate {
|
|||
* @param template template
|
||||
* @param fileExtension file extension
|
||||
*/
|
||||
public void buildApiDoc(List<JavaApiDoc> apiDocList, ApiConfig config, String template, String fileExtension) {
|
||||
public void buildApiDoc(List<RpcApiDoc> apiDocList, ApiConfig config, String template, String fileExtension) {
|
||||
FileUtil.mkdirs(config.getOutPath());
|
||||
for (JavaApiDoc rpcDoc : apiDocList) {
|
||||
for (RpcApiDoc rpcDoc : apiDocList) {
|
||||
Template mapper = BeetlTemplateUtil.getByName(template);
|
||||
mapper.binding(TemplateVariable.DESC.getVariable(), rpcDoc.getDesc());
|
||||
mapper.binding(TemplateVariable.NAME.getVariable(), rpcDoc.getName());
|
||||
mapper.binding(TemplateVariable.LIST.getVariable(), rpcDoc.getList());
|
||||
FileUtil.nioWriteFile(mapper.render(), config.getOutPath() + FILE_SEPARATOR + rpcDoc.getName() + fileExtension);
|
||||
mapper.binding(TemplateVariable.PROTOCOL.getVariable(),rpcDoc.getProtocol());
|
||||
mapper.binding(TemplateVariable.AUTHOR.getVariable(),rpcDoc.getAuthor());
|
||||
mapper.binding(TemplateVariable.VERSION.getVariable(),rpcDoc.getVersion());
|
||||
mapper.binding(TemplateVariable.URI.getVariable(),rpcDoc.getUri());
|
||||
FileUtil.nioWriteFile(mapper.render(), config.getOutPath() + FILE_SEPARATOR + rpcDoc.getShortName() + fileExtension);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -49,7 +53,7 @@ public class RpcDocBuilderTemplate extends BaseDocBuilderTemplate {
|
|||
* @param template template
|
||||
* @param outPutFileName output file
|
||||
*/
|
||||
public void buildAllInOne(List<JavaApiDoc> apiDocList, ApiConfig config, JavaProjectBuilder javaProjectBuilder, String template, String outPutFileName) {
|
||||
public void buildAllInOne(List<RpcApiDoc> apiDocList, ApiConfig config, JavaProjectBuilder javaProjectBuilder, String template, String outPutFileName) {
|
||||
String outPath = config.getOutPath();
|
||||
String strTime = DateTimeUtil.long2Str(now, DateTimeUtil.DATE_FORMAT_SECOND);
|
||||
FileUtil.mkdirs(outPath);
|
||||
|
@ -58,6 +62,7 @@ public class RpcDocBuilderTemplate extends BaseDocBuilderTemplate {
|
|||
tpl.binding(TemplateVariable.API_DOC_LIST.getVariable(), apiDocList);
|
||||
tpl.binding(TemplateVariable.ERROR_CODE_LIST.getVariable(), errorCodeList);
|
||||
tpl.binding(TemplateVariable.VERSION_LIST.getVariable(), config.getRevisionLogs());
|
||||
tpl.binding(TemplateVariable.DEPENDENCY_LIST.getVariable(),config.getRpcApiDependencies());
|
||||
tpl.binding(TemplateVariable.VERSION.getVariable(), now);
|
||||
tpl.binding(TemplateVariable.CREATE_TIME.getVariable(), strTime);
|
||||
tpl.binding(TemplateVariable.PROJECT_NAME.getVariable(), config.getProjectName());
|
||||
|
|
|
@ -3,7 +3,7 @@ package com.power.doc.builder.rpc;
|
|||
import com.power.common.util.DateTimeUtil;
|
||||
import com.power.doc.builder.ProjectDocConfigBuilder;
|
||||
import com.power.doc.model.ApiConfig;
|
||||
import com.power.doc.model.JavaApiDoc;
|
||||
import com.power.doc.model.rpc.RpcApiDoc;
|
||||
import com.power.doc.template.JavaDocBuildTemplate;
|
||||
import com.thoughtworks.qdox.JavaProjectBuilder;
|
||||
|
||||
|
@ -40,10 +40,10 @@ public class RpcMarkdownBuilder {
|
|||
builderTemplate.checkAndInit(config);
|
||||
ProjectDocConfigBuilder configBuilder = new ProjectDocConfigBuilder(config, javaProjectBuilder);
|
||||
JavaDocBuildTemplate docBuildTemplate = new JavaDocBuildTemplate();
|
||||
List<JavaApiDoc> apiDocList = docBuildTemplate.getApiData(configBuilder);
|
||||
List<RpcApiDoc> apiDocList = docBuildTemplate.getApiData(configBuilder);
|
||||
if (config.isAllInOne()) {
|
||||
String version = config.isCoverOld() ? "" : "-V" + DateTimeUtil.long2Str(System.currentTimeMillis(), DATE_FORMAT);
|
||||
builderTemplate.buildAllInOne(apiDocList, config, javaProjectBuilder, RPC_ALL_IN_ONE_MD_TPL, "AllInOne" + version + ".md");
|
||||
builderTemplate.buildAllInOne(apiDocList, config, javaProjectBuilder, RPC_ALL_IN_ONE_MD_TPL, "DubboAllInOne" + version + ".md");
|
||||
} else {
|
||||
builderTemplate.buildApiDoc(apiDocList, config, RPC_API_DOC_MD_TPL, API_EXTENSION);
|
||||
builderTemplate.buildErrorCodeDoc(config, ERROR_CODE_LIST_MD_TPL, ERROR_CODE_LIST_MD);
|
||||
|
|
|
@ -53,7 +53,7 @@ public interface DocGlobalConstants {
|
|||
|
||||
String ALL_IN_ONE_CSS = "AllInOne.css";
|
||||
|
||||
String RPC_API_DOC_MD_TPL = "dubbo.md";
|
||||
String RPC_API_DOC_MD_TPL = "Dubbo.md";
|
||||
|
||||
String RPC_ALL_IN_ONE_MD_TPL = "DubboAllIneOne.md";
|
||||
|
||||
|
|
|
@ -1,42 +1,52 @@
|
|||
package com.power.doc.constants;
|
||||
|
||||
/**
|
||||
* @author yu 2019/9/13.
|
||||
*/
|
||||
public interface DocTags {
|
||||
|
||||
/**
|
||||
* java since tag
|
||||
*/
|
||||
String SINCE = "since";
|
||||
|
||||
/**
|
||||
* java required tag
|
||||
*/
|
||||
String REQUIRED = "required";
|
||||
|
||||
/**
|
||||
* java param tag
|
||||
*/
|
||||
String PARAM = "param";
|
||||
|
||||
/**
|
||||
* java apiNote tag for method detail
|
||||
*/
|
||||
String API_NOTE = "apiNote";
|
||||
|
||||
/**
|
||||
* java author tag for method author
|
||||
*/
|
||||
String AUTHOR = "author";
|
||||
|
||||
/**
|
||||
* custom ignore tag
|
||||
*/
|
||||
String IGNORE = "ignore";
|
||||
|
||||
/**
|
||||
* custom @mock tag
|
||||
*/
|
||||
String MOCK = "mock";
|
||||
}
|
||||
package com.power.doc.constants;
|
||||
|
||||
/**
|
||||
* @author yu 2019/9/13.
|
||||
*/
|
||||
public interface DocTags {
|
||||
|
||||
/**
|
||||
* java since tag
|
||||
*/
|
||||
String SINCE = "since";
|
||||
|
||||
/**
|
||||
* java required tag
|
||||
*/
|
||||
String REQUIRED = "required";
|
||||
|
||||
/**
|
||||
* java param tag
|
||||
*/
|
||||
String PARAM = "param";
|
||||
|
||||
/**
|
||||
* java apiNote tag for method detail
|
||||
*/
|
||||
String API_NOTE = "apiNote";
|
||||
|
||||
/**
|
||||
* java author tag for method author
|
||||
*/
|
||||
String AUTHOR = "author";
|
||||
|
||||
/**
|
||||
* java verion tag
|
||||
*/
|
||||
String VERSION = "version";
|
||||
|
||||
/**
|
||||
* custom ignore tag
|
||||
*/
|
||||
String IGNORE = "ignore";
|
||||
|
||||
/**
|
||||
* custom @mock tag
|
||||
*/
|
||||
String MOCK = "mock";
|
||||
|
||||
/**
|
||||
* custom dubbo tag
|
||||
*/
|
||||
String DUBBO = "dubbo";
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ public enum TemplateVariable {
|
|||
API_DOC_LIST("apiDocList"),
|
||||
ERROR_CODE_LIST("errorCodeList"),
|
||||
VERSION_LIST("revisionLogList"),
|
||||
DEPENDENCY_LIST("dependencyList"),
|
||||
HOME_PAGE("homePage"),
|
||||
HTML("html"),
|
||||
TITLE("title"),
|
||||
|
@ -41,7 +42,10 @@ public enum TemplateVariable {
|
|||
DICT_LIST("dictList"),
|
||||
DICT_LIST_TITLE("dictListTitle"),
|
||||
DICT_ORDER("dictListOrder"),
|
||||
VERSION("version");
|
||||
VERSION("version"),
|
||||
PROTOCOL("protocol"),
|
||||
AUTHOR("author"),
|
||||
URI("uri"),;
|
||||
|
||||
|
||||
private String variable;
|
||||
|
|
|
@ -24,6 +24,7 @@ package com.power.doc.model;
|
|||
|
||||
import com.power.common.util.CollectionUtil;
|
||||
import com.power.doc.constants.DocLanguage;
|
||||
import com.power.doc.model.rpc.RpcApiDependency;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
@ -130,6 +131,11 @@ public class ApiConfig {
|
|||
*/
|
||||
private List<ApiObjectReplacement> apiObjectReplacements;
|
||||
|
||||
/**
|
||||
* list of rpc api dependencies
|
||||
*/
|
||||
private List<RpcApiDependency> rpcApiDependencies;
|
||||
|
||||
/**
|
||||
* @since 1.7.5
|
||||
* project name
|
||||
|
@ -280,6 +286,14 @@ public class ApiConfig {
|
|||
this.apiObjectReplacements = CollectionUtil.asList(apiObjectReplaces);
|
||||
}
|
||||
|
||||
public List<RpcApiDependency> getRpcApiDependencies() {
|
||||
return rpcApiDependencies;
|
||||
}
|
||||
|
||||
public void setRpcApiDependencies(RpcApiDependency... rpcApiDependencies) {
|
||||
this.rpcApiDependencies = CollectionUtil.asList(rpcApiDependencies);
|
||||
}
|
||||
|
||||
public boolean isCoverOld() {
|
||||
return coverOld;
|
||||
}
|
||||
|
|
|
@ -1,156 +1,169 @@
|
|||
package com.power.doc.model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author yu 2020/1/29.
|
||||
*/
|
||||
public class JavaMethodDoc {
|
||||
|
||||
/**
|
||||
* methodId handled by md5
|
||||
*
|
||||
*/
|
||||
private String methodId;
|
||||
|
||||
/**
|
||||
* method name
|
||||
*
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* method order
|
||||
*
|
||||
*/
|
||||
private int order;
|
||||
|
||||
|
||||
/**
|
||||
* method description
|
||||
*/
|
||||
private String desc;
|
||||
|
||||
/**
|
||||
* detailed introduction of the method
|
||||
*/
|
||||
private String detail;
|
||||
|
||||
/**
|
||||
* method describe
|
||||
*/
|
||||
private String throwsInfo;
|
||||
|
||||
/**
|
||||
* return class Info
|
||||
*/
|
||||
private String returnClassInfo;
|
||||
|
||||
/**
|
||||
* http request params
|
||||
*/
|
||||
private List<ApiParam> requestParams;
|
||||
|
||||
/**
|
||||
* http request author
|
||||
*/
|
||||
private String author;
|
||||
|
||||
/**
|
||||
* http response params
|
||||
*/
|
||||
private List<ApiParam> responseParams;
|
||||
|
||||
/**
|
||||
* method deprecated
|
||||
*/
|
||||
private boolean deprecated;
|
||||
|
||||
public String getMethodId() {
|
||||
return methodId;
|
||||
}
|
||||
|
||||
public void setMethodId(String methodId) {
|
||||
this.methodId = methodId;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getOrder() {
|
||||
return order;
|
||||
}
|
||||
|
||||
public void setOrder(int order) {
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
public String getDesc() {
|
||||
return desc;
|
||||
}
|
||||
|
||||
public void setDesc(String desc) {
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
public String getDetail() {
|
||||
return detail;
|
||||
}
|
||||
|
||||
public void setDetail(String detail) {
|
||||
this.detail = detail;
|
||||
}
|
||||
|
||||
public String getThrowsInfo() {
|
||||
return throwsInfo;
|
||||
}
|
||||
|
||||
public void setThrowsInfo(String throwsInfo) {
|
||||
this.throwsInfo = throwsInfo;
|
||||
}
|
||||
|
||||
public String getReturnClassInfo() {
|
||||
return returnClassInfo;
|
||||
}
|
||||
|
||||
public void setReturnClassInfo(String returnClassInfo) {
|
||||
this.returnClassInfo = returnClassInfo;
|
||||
}
|
||||
|
||||
public String getAuthor() {
|
||||
return author;
|
||||
}
|
||||
|
||||
public void setAuthor(String author) {
|
||||
this.author = author;
|
||||
}
|
||||
|
||||
public List<ApiParam> getResponseParams() {
|
||||
return responseParams;
|
||||
}
|
||||
|
||||
public void setResponseParams(List<ApiParam> responseParams) {
|
||||
this.responseParams = responseParams;
|
||||
}
|
||||
|
||||
public boolean isDeprecated() {
|
||||
return deprecated;
|
||||
}
|
||||
|
||||
public void setDeprecated(boolean deprecated) {
|
||||
this.deprecated = deprecated;
|
||||
}
|
||||
|
||||
public List<ApiParam> getRequestParams() {
|
||||
return requestParams;
|
||||
}
|
||||
|
||||
public void setRequestParams(List<ApiParam> requestParams) {
|
||||
this.requestParams = requestParams;
|
||||
}
|
||||
}
|
||||
package com.power.doc.model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author yu 2020/1/29.
|
||||
*/
|
||||
public class JavaMethodDoc {
|
||||
|
||||
/**
|
||||
* methodId handled by md5
|
||||
*
|
||||
*/
|
||||
private String methodId;
|
||||
|
||||
/**
|
||||
* method name
|
||||
*
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* method order
|
||||
*
|
||||
*/
|
||||
private int order;
|
||||
|
||||
|
||||
/**
|
||||
* method description
|
||||
*/
|
||||
private String desc;
|
||||
|
||||
/**
|
||||
* method definition
|
||||
*/
|
||||
private String methodDefinition;
|
||||
|
||||
/**
|
||||
* detailed introduction of the method
|
||||
*/
|
||||
private String detail;
|
||||
|
||||
/**
|
||||
* method describe
|
||||
*/
|
||||
private String throwsInfo;
|
||||
|
||||
/**
|
||||
* return class Info
|
||||
*/
|
||||
private String returnClassInfo;
|
||||
|
||||
/**
|
||||
* http request params
|
||||
*/
|
||||
private List<ApiParam> requestParams;
|
||||
|
||||
/**
|
||||
* http request author
|
||||
*/
|
||||
private String author;
|
||||
|
||||
/**
|
||||
* http response params
|
||||
*/
|
||||
private List<ApiParam> responseParams;
|
||||
|
||||
/**
|
||||
* method deprecated
|
||||
*/
|
||||
private boolean deprecated;
|
||||
|
||||
public String getMethodId() {
|
||||
return methodId;
|
||||
}
|
||||
|
||||
public void setMethodId(String methodId) {
|
||||
this.methodId = methodId;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getOrder() {
|
||||
return order;
|
||||
}
|
||||
|
||||
public void setOrder(int order) {
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
public String getDesc() {
|
||||
return desc;
|
||||
}
|
||||
|
||||
public void setDesc(String desc) {
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
public String getDetail() {
|
||||
return detail;
|
||||
}
|
||||
|
||||
public void setDetail(String detail) {
|
||||
this.detail = detail;
|
||||
}
|
||||
|
||||
public String getThrowsInfo() {
|
||||
return throwsInfo;
|
||||
}
|
||||
|
||||
public void setThrowsInfo(String throwsInfo) {
|
||||
this.throwsInfo = throwsInfo;
|
||||
}
|
||||
|
||||
public String getReturnClassInfo() {
|
||||
return returnClassInfo;
|
||||
}
|
||||
|
||||
public void setReturnClassInfo(String returnClassInfo) {
|
||||
this.returnClassInfo = returnClassInfo;
|
||||
}
|
||||
|
||||
public String getAuthor() {
|
||||
return author;
|
||||
}
|
||||
|
||||
public void setAuthor(String author) {
|
||||
this.author = author;
|
||||
}
|
||||
|
||||
public List<ApiParam> getResponseParams() {
|
||||
return responseParams;
|
||||
}
|
||||
|
||||
public void setResponseParams(List<ApiParam> responseParams) {
|
||||
this.responseParams = responseParams;
|
||||
}
|
||||
|
||||
public boolean isDeprecated() {
|
||||
return deprecated;
|
||||
}
|
||||
|
||||
public void setDeprecated(boolean deprecated) {
|
||||
this.deprecated = deprecated;
|
||||
}
|
||||
|
||||
public List<ApiParam> getRequestParams() {
|
||||
return requestParams;
|
||||
}
|
||||
|
||||
public void setRequestParams(List<ApiParam> requestParams) {
|
||||
this.requestParams = requestParams;
|
||||
}
|
||||
|
||||
public String getMethodDefinition() {
|
||||
return methodDefinition;
|
||||
}
|
||||
|
||||
public void setMethodDefinition(String methodDefinition) {
|
||||
this.methodDefinition = methodDefinition;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* smart-doc https://github.com/shalousun/smart-doc
|
||||
*
|
||||
* Copyright (C) 2018-2020 smart-doc
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package com.power.doc.model.rpc;
|
||||
|
||||
/**
|
||||
* @author yu 2020/5/17.
|
||||
*/
|
||||
public class RpcApiDependency {
|
||||
|
||||
private String groupId;
|
||||
|
||||
private String artifactId;
|
||||
|
||||
private String version;
|
||||
|
||||
public static RpcApiDependency builder() {
|
||||
return new RpcApiDependency();
|
||||
}
|
||||
|
||||
public String getGroupId() {
|
||||
return groupId;
|
||||
}
|
||||
|
||||
public RpcApiDependency setGroupId(String groupId) {
|
||||
this.groupId = groupId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getArtifactId() {
|
||||
return artifactId;
|
||||
}
|
||||
|
||||
public RpcApiDependency setArtifactId(String artifactId) {
|
||||
this.artifactId = artifactId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public RpcApiDependency setVersion(String version) {
|
||||
this.version = version;
|
||||
return this;
|
||||
}
|
||||
}
|
|
@ -1,5 +1,7 @@
|
|||
package com.power.doc.model.rpc;
|
||||
|
||||
import com.power.doc.model.JavaMethodDoc;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -23,6 +25,11 @@ public class RpcApiDoc {
|
|||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* interface short name
|
||||
*/
|
||||
private String shortName;
|
||||
|
||||
/**
|
||||
* controller alias handled by md5
|
||||
*
|
||||
|
@ -40,6 +47,11 @@ public class RpcApiDoc {
|
|||
*/
|
||||
private String protocol;
|
||||
|
||||
/**
|
||||
* interface author
|
||||
*/
|
||||
private String author;
|
||||
|
||||
/**
|
||||
* interface uri
|
||||
*/
|
||||
|
@ -53,7 +65,7 @@ public class RpcApiDoc {
|
|||
/**
|
||||
* List of method doc
|
||||
*/
|
||||
private List<RpcApiMethodDoc> list;
|
||||
private List<JavaMethodDoc> list;
|
||||
|
||||
public int getOrder() {
|
||||
return order;
|
||||
|
@ -119,11 +131,27 @@ public class RpcApiDoc {
|
|||
this.version = version;
|
||||
}
|
||||
|
||||
public List<RpcApiMethodDoc> getList() {
|
||||
public List<JavaMethodDoc> getList() {
|
||||
return list;
|
||||
}
|
||||
|
||||
public void setList(List<RpcApiMethodDoc> list) {
|
||||
public void setList(List<JavaMethodDoc> list) {
|
||||
this.list = list;
|
||||
}
|
||||
|
||||
public String getShortName() {
|
||||
return shortName;
|
||||
}
|
||||
|
||||
public void setShortName(String shortName) {
|
||||
this.shortName = shortName;
|
||||
}
|
||||
|
||||
public String getAuthor() {
|
||||
return author;
|
||||
}
|
||||
|
||||
public void setAuthor(String author) {
|
||||
this.author = author;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import com.power.doc.constants.DocTags;
|
|||
import com.power.doc.constants.DubboAnnotationConstants;
|
||||
import com.power.doc.helper.ParamsBuildHelper;
|
||||
import com.power.doc.model.*;
|
||||
import com.power.doc.model.rpc.RpcApiDoc;
|
||||
import com.power.doc.utils.DocClassUtil;
|
||||
import com.power.doc.utils.DocUtil;
|
||||
import com.power.doc.utils.JavaClassUtil;
|
||||
|
@ -26,9 +27,9 @@ import static com.power.doc.constants.DocTags.IGNORE;
|
|||
*/
|
||||
public class JavaDocBuildTemplate {
|
||||
|
||||
public List<JavaApiDoc> getApiData(ProjectDocConfigBuilder projectBuilder) {
|
||||
public List<RpcApiDoc> getApiData(ProjectDocConfigBuilder projectBuilder) {
|
||||
ApiConfig apiConfig = projectBuilder.getApiConfig();
|
||||
List<JavaApiDoc> apiDocList = new ArrayList<>();
|
||||
List<RpcApiDoc> apiDocList = new ArrayList<>();
|
||||
int order = 0;
|
||||
for (JavaClass cls : projectBuilder.getJavaProjectBuilder().getClasses()) {
|
||||
if (!checkDubboInterface(cls)) {
|
||||
|
@ -38,12 +39,12 @@ public class JavaDocBuildTemplate {
|
|||
if (DocUtil.isMatch(apiConfig.getPackageFilters(), cls.getCanonicalName())) {
|
||||
order++;
|
||||
List<JavaMethodDoc> apiMethodDocs = buildServiceMethod(cls, apiConfig, projectBuilder);
|
||||
this.handleJavaApiDoc(cls, apiDocList, apiMethodDocs, order, apiConfig.isMd5EncryptedHtmlName());
|
||||
this.handleJavaApiDoc(cls, apiDocList, apiMethodDocs, order, projectBuilder);
|
||||
}
|
||||
} else {
|
||||
order++;
|
||||
List<JavaMethodDoc> apiMethodDocs = buildServiceMethod(cls, apiConfig, projectBuilder);
|
||||
this.handleJavaApiDoc(cls, apiDocList, apiMethodDocs, order, apiConfig.isMd5EncryptedHtmlName());
|
||||
this.handleJavaApiDoc(cls, apiDocList, apiMethodDocs, order, projectBuilder);
|
||||
}
|
||||
}
|
||||
return apiDocList;
|
||||
|
@ -80,6 +81,7 @@ public class JavaDocBuildTemplate {
|
|||
}
|
||||
methodOrder++;
|
||||
JavaMethodDoc apiMethodDoc = new JavaMethodDoc();
|
||||
apiMethodDoc.setMethodDefinition(methodDefinition(method));
|
||||
apiMethodDoc.setOrder(methodOrder);
|
||||
apiMethodDoc.setDesc(method.getComment());
|
||||
apiMethodDoc.setName(method.getName());
|
||||
|
@ -187,27 +189,42 @@ public class JavaDocBuildTemplate {
|
|||
}
|
||||
List<DocletTag> docletTags = cls.getTags();
|
||||
for (DocletTag docletTag : docletTags) {
|
||||
String value = docletTag.getValue();
|
||||
if ("dubbo".equals(value) || "api".equals(value)) {
|
||||
String value = docletTag.getName();
|
||||
if (DocTags.DUBBO.equals(value)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void handleJavaApiDoc(JavaClass cls, List<JavaApiDoc> apiDocList, List<JavaMethodDoc> apiMethodDocs, int order, boolean isUseMD5) {
|
||||
String controllerName = cls.getName();
|
||||
JavaApiDoc apiDoc = new JavaApiDoc();
|
||||
private void handleJavaApiDoc(JavaClass cls, List<RpcApiDoc> apiDocList, List<JavaMethodDoc> apiMethodDocs, int order, ProjectDocConfigBuilder builder) {
|
||||
String className = cls.getCanonicalName();
|
||||
RpcApiDoc apiDoc = new RpcApiDoc();
|
||||
apiDoc.setOrder(order);
|
||||
apiDoc.setName(controllerName);
|
||||
apiDoc.setAlias(controllerName);
|
||||
if (isUseMD5) {
|
||||
apiDoc.setName(className);
|
||||
apiDoc.setShortName(cls.getName());
|
||||
apiDoc.setAlias(className);
|
||||
apiDoc.setUri(builder.getServerUrl()+"/"+className);
|
||||
apiDoc.setProtocol("dubbo");
|
||||
if (builder.getApiConfig().isMd5EncryptedHtmlName()) {
|
||||
String name = DocUtil.generateId(apiDoc.getName());
|
||||
apiDoc.setAlias(name);
|
||||
}
|
||||
apiDoc.setDesc(cls.getComment());
|
||||
apiDoc.setList(apiMethodDocs);
|
||||
apiDocList.add(apiDoc);
|
||||
List<DocletTag> docletTags = cls.getTags();
|
||||
List<String> authorList = new ArrayList<>();
|
||||
for (DocletTag docletTag : docletTags) {
|
||||
String name = docletTag.getName();
|
||||
if (DocTags.VERSION.equals(name)) {
|
||||
apiDoc.setVersion(docletTag.getValue());
|
||||
}
|
||||
if (DocTags.AUTHOR.equals(name)) {
|
||||
authorList.add(docletTag.getValue());
|
||||
}
|
||||
}
|
||||
apiDoc.setAuthor(String.join(",",authorList));
|
||||
}
|
||||
|
||||
private List<ApiParam> buildReturnApiParams(JavaMethod method, ProjectDocConfigBuilder projectBuilder) {
|
||||
|
@ -264,4 +281,18 @@ public class JavaDocBuildTemplate {
|
|||
return comment;
|
||||
}
|
||||
|
||||
private String methodDefinition(JavaMethod method) {
|
||||
StringBuilder methodBuilder = new StringBuilder();
|
||||
String returnClass = method.getReturnType().getGenericCanonicalName();
|
||||
methodBuilder.append(returnClass).append(" ");
|
||||
List<String> params = new ArrayList<>();
|
||||
List<JavaParameter> parameters = method.getParameters();
|
||||
for (JavaParameter parameter : parameters) {
|
||||
params.add(parameter.getType() + " " + parameter.getName());
|
||||
}
|
||||
methodBuilder.append(method.getName()).append("(")
|
||||
.append(String.join(",", params)).append(")");
|
||||
return methodBuilder.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
|
||||
# ${desc}
|
||||
|
||||
**URI:** ${uri}
|
||||
|
||||
**Service:** ${name}
|
||||
|
||||
**Protocol:** ${protocol}
|
||||
|
||||
**Author:** ${author}
|
||||
|
||||
**Version:** ${version}
|
||||
<%
|
||||
for(doc in list){
|
||||
%>
|
||||
<%if(doc.deprecated){%>
|
||||
## ~~${doc.desc}~~
|
||||
<%}else{%>
|
||||
## ${doc.desc}
|
||||
<%}%>
|
||||
|
||||
**Definition:** ${doc.methodDefinition}
|
||||
|
||||
<%if(isNotEmpty(doc.author)){%>
|
||||
**Author:** ${doc.author}
|
||||
<%}%>
|
||||
|
||||
**Description:** ${doc.detail}
|
||||
|
||||
<%if(isNotEmpty(doc.requestParams)){%>
|
||||
**Request-parameters:**
|
||||
|
||||
Parameter|Type|Description|Required|Since
|
||||
---|---|---|---|---
|
||||
<%
|
||||
for(param in doc.requestParams){
|
||||
%>
|
||||
${param.field}|${param.type}|${param.desc}|${param.required}|${param.version}
|
||||
<%}%>
|
||||
<%}%>
|
||||
|
||||
<%if(isNotEmpty(doc.responseParams)){%>
|
||||
**Response-fields:**
|
||||
|
||||
Field | Type|Description|Since
|
||||
---|---|---|---
|
||||
<%
|
||||
for(param in doc.responseParams){
|
||||
%>
|
||||
${param.field}|${param.type}|${param.desc}|${param.version}
|
||||
<%}%>
|
||||
<%}%>
|
||||
|
||||
<% } %>
|
||||
|
||||
|
||||
|
|
@ -1,29 +1,99 @@
|
|||
# 1、数据同步接口
|
||||
<%if(isNotEmpty(projectName)){%>
|
||||
# ${projectName}
|
||||
<%}%>
|
||||
|
||||
**接口名称:** com.xxx.service
|
||||
<%if(isNotEmpty(revisionLogList)){%>
|
||||
Version | Update Time | Status | Author | Description
|
||||
---|---|---|---|---
|
||||
<%
|
||||
for(revisionLog in revisionLogList){
|
||||
%>
|
||||
${revisionLog.version}|${revisionLog.revisionTime}|${revisionLog.status}|${revisionLog.author}|${revisionLog.remarks}
|
||||
<%}%>
|
||||
<%}%>
|
||||
|
||||
**接口地址:** dubbo://xxx:20880/com.xxx.service
|
||||
<%if(isNotEmpty(dependencyList)){%>
|
||||
## Add dependency
|
||||
|
||||
**接口协议:** dubbo
|
||||
```
|
||||
<%
|
||||
for(dependency in dependencyList){
|
||||
%>
|
||||
<dependency>
|
||||
<groupId>${dependency.groupId}</groupId>
|
||||
<artifactId>${dependency.artifactId}</artifactId>
|
||||
<version>${dependency.version}</version>
|
||||
</dependency>
|
||||
|
||||
**接口版本:** 1.0.0
|
||||
<%}%>
|
||||
```
|
||||
<%}%>
|
||||
|
||||
## 1.1 sycData方法
|
||||
<%
|
||||
for(api in apiDocList){
|
||||
%>
|
||||
## ${api.desc}
|
||||
|
||||
**方法定义:** User getUser(String name)
|
||||
**URI:** ${api.uri}
|
||||
|
||||
**方法描述:** com.xxx.service
|
||||
**Service:** ${api.name}
|
||||
|
||||
**请求参数:**
|
||||
**Protocol:** ${api.protocol}
|
||||
|
||||
Param | Type|Description|Since
|
||||
---|---|---|---
|
||||
name|String|姓名|-
|
||||
age|Integer|年龄|-
|
||||
**Author:** ${api.author}
|
||||
|
||||
**响应参数:**
|
||||
**Version:** ${api.version}
|
||||
<%
|
||||
for(doc in api.list){
|
||||
%>
|
||||
<%if(doc.deprecated){%>
|
||||
### ~~${doc.desc}~~
|
||||
<%}else{%>
|
||||
### ${doc.desc}
|
||||
<%}%>
|
||||
|
||||
**Definition:** ${doc.methodDefinition}
|
||||
|
||||
<%if(isNotEmpty(doc.author)){%>
|
||||
**Author:** ${doc.author}
|
||||
<%}%>
|
||||
|
||||
**Description:** ${doc.detail}
|
||||
|
||||
<%if(isNotEmpty(doc.requestParams)){%>
|
||||
**Request-parameters:**
|
||||
|
||||
Parameter|Type|Description|Required|Since
|
||||
---|---|---|---|---
|
||||
<%
|
||||
for(param in doc.requestParams){
|
||||
%>
|
||||
${param.field}|${param.type}|${param.desc}|${param.required}|${param.version}
|
||||
<%}%>
|
||||
<%}%>
|
||||
|
||||
<%if(isNotEmpty(doc.responseParams)){%>
|
||||
**Response-fields:**
|
||||
|
||||
Field | Type|Description|Since
|
||||
---|---|---|---
|
||||
name|String|姓名|-
|
||||
age|Integer|年龄|-
|
||||
<%
|
||||
for(param in doc.responseParams){
|
||||
%>
|
||||
${param.field}|${param.type}|${param.desc}|${param.version}
|
||||
<%}%>
|
||||
<%}%>
|
||||
|
||||
<%if(isNotEmpty(errorCodeList)){%>
|
||||
## ${errorListTitle}
|
||||
Error code |Description
|
||||
---|---
|
||||
<%
|
||||
for(error in errorCodeList){
|
||||
%>
|
||||
${error.value}|${error.desc}
|
||||
<%}%>
|
||||
<%}%>
|
||||
|
||||
<%}%>
|
||||
<%}%>
|
|
@ -1,33 +0,0 @@
|
|||
|
||||
# 1、数据同步接口
|
||||
|
||||
**接口名称:** com.xxx.service
|
||||
|
||||
**接口地址:** dubbo://xxx:20880/com.xxx.service
|
||||
|
||||
**接口协议:** dubbo
|
||||
|
||||
**接口版本:** 1.0.0
|
||||
|
||||
## 1.1 sycData方法
|
||||
|
||||
**方法定义:** User getUser(String name)
|
||||
|
||||
**方法描述:** com.xxx.service
|
||||
|
||||
**请求参数:**
|
||||
|
||||
Param | Type|Description|Since
|
||||
---|---|---|---
|
||||
name|String|姓名|-
|
||||
age|Integer|年龄|-
|
||||
|
||||
**响应参数:**
|
||||
|
||||
Field | Type|Description|Since
|
||||
---|---|---|---
|
||||
name|String|姓名|-
|
||||
age|Integer|年龄|-
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue