From 388c178662269c58c9fa694eb702ef1bdc39f02c Mon Sep 17 00:00:00 2001 From: chenqi <1535985458@qq.com> Date: Sun, 1 Aug 2021 23:19:39 +0800 Subject: [PATCH] feat: add group --- .../com/power/doc/builder/AdocDocBuilder.java | 2 + .../com/power/doc/builder/ApiDocBuilder.java | 2 + .../power/doc/builder/DocBuilderTemplate.java | 2 + .../power/doc/builder/HtmlApiDocBuilder.java | 4 +- .../com/power/doc/builder/TornaBuilder.java | 30 +- .../java/com/power/doc/model/ApiConfig.java | 18 + src/main/java/com/power/doc/model/ApiDoc.java | 66 +++ .../java/com/power/doc/model/ApiGroup.java | 55 ++ .../power/doc/template/IDocBuildTemplate.java | 52 ++ src/main/resources/template/AllInOne.adoc | 19 +- src/main/resources/template/AllInOne.btl | 7 +- src/main/resources/template/debug-all.html | 516 +++++++++++++++++- .../resources/template/js/search_all.js.btl | 106 ++-- src/test/java/com/power/doc/ApiDocTest.java | 2 +- 14 files changed, 799 insertions(+), 82 deletions(-) create mode 100644 src/main/java/com/power/doc/model/ApiGroup.java diff --git a/src/main/java/com/power/doc/builder/AdocDocBuilder.java b/src/main/java/com/power/doc/builder/AdocDocBuilder.java index d7a8fc5..f703f5e 100644 --- a/src/main/java/com/power/doc/builder/AdocDocBuilder.java +++ b/src/main/java/com/power/doc/builder/AdocDocBuilder.java @@ -31,6 +31,7 @@ import com.power.doc.template.SpringBootDocBuildTemplate; import com.thoughtworks.qdox.JavaProjectBuilder; import java.util.List; +import java.util.stream.Collectors; import static com.power.doc.constants.DocGlobalConstants.*; @@ -71,6 +72,7 @@ public class AdocDocBuilder { List apiDocList = docBuildTemplate.getApiData(configBuilder); if (config.isAllInOne()) { String docName = builderTemplate.allInOneDocName(config,INDEX_DOC,".doc"); + apiDocList = docBuildTemplate.handleApiGroup(apiDocList, config); builderTemplate.buildAllInOne(apiDocList, config, javaProjectBuilder, ALL_IN_ONE_ADOC_TPL, docName); } else { builderTemplate.buildApiDoc(apiDocList, config, API_DOC_ADOC_TPL, API_EXTENSION); diff --git a/src/main/java/com/power/doc/builder/ApiDocBuilder.java b/src/main/java/com/power/doc/builder/ApiDocBuilder.java index c9b119f..1c97568 100644 --- a/src/main/java/com/power/doc/builder/ApiDocBuilder.java +++ b/src/main/java/com/power/doc/builder/ApiDocBuilder.java @@ -31,6 +31,7 @@ import com.power.doc.template.SpringBootDocBuildTemplate; import com.thoughtworks.qdox.JavaProjectBuilder; import java.util.List; +import java.util.stream.Collectors; import static com.power.doc.constants.DocGlobalConstants.*; @@ -70,6 +71,7 @@ public class ApiDocBuilder { if (config.isAllInOne()) { String version = config.isCoverOld() ? "" : "-V" + DateTimeUtil.long2Str(System.currentTimeMillis(), DATE_FORMAT); String docName = builderTemplate.allInOneDocName(config,"AllInOne" + version + ".md",".md"); + apiDocList = docBuildTemplate.handleApiGroup(apiDocList, config); builderTemplate.buildAllInOne(apiDocList, config, javaProjectBuilder, ALL_IN_ONE_MD_TPL, docName); } else { builderTemplate.buildApiDoc(apiDocList, config, API_DOC_MD_TPL, API_EXTENSION); diff --git a/src/main/java/com/power/doc/builder/DocBuilderTemplate.java b/src/main/java/com/power/doc/builder/DocBuilderTemplate.java index 40978c0..e460282 100644 --- a/src/main/java/com/power/doc/builder/DocBuilderTemplate.java +++ b/src/main/java/com/power/doc/builder/DocBuilderTemplate.java @@ -169,6 +169,7 @@ public class DocBuilderTemplate extends BaseDocBuilderTemplate { apiDoc1.setList(new ArrayList<>(0)); apiDoc1.setLink("error_code_list"); apiDoc1.setAlias("error"); + apiDoc1.setGroup(apiDoc1.getDesc()); apiDocs.add(apiDoc1); } // set dict list @@ -178,6 +179,7 @@ public class DocBuilderTemplate extends BaseDocBuilderTemplate { apiDoc1.setLink("dict_list"); apiDoc1.setAlias("dict"); apiDoc1.setDesc(titleMap.get(TemplateVariable.DICT_LIST_TITLE.getVariable())); + apiDoc1.setGroup(apiDoc1.getDesc()); List methodDocs = new ArrayList<>(); for (ApiDocDict apiDocDict : apiDocDictList) { ApiMethodDoc methodDoc = new ApiMethodDoc(); diff --git a/src/main/java/com/power/doc/builder/HtmlApiDocBuilder.java b/src/main/java/com/power/doc/builder/HtmlApiDocBuilder.java index 693fa95..87ed083 100644 --- a/src/main/java/com/power/doc/builder/HtmlApiDocBuilder.java +++ b/src/main/java/com/power/doc/builder/HtmlApiDocBuilder.java @@ -27,13 +27,14 @@ import com.power.doc.factory.BuildTemplateFactory; import com.power.doc.model.ApiConfig; import com.power.doc.model.ApiDoc; import com.power.doc.template.IDocBuildTemplate; -import com.power.doc.template.SpringBootDocBuildTemplate; import com.power.doc.utils.BeetlTemplateUtil; import com.thoughtworks.qdox.JavaProjectBuilder; import org.apache.commons.lang3.StringUtils; import org.beetl.core.Template; import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.Collectors; import static com.power.doc.constants.DocGlobalConstants.*; @@ -74,6 +75,7 @@ public class HtmlApiDocBuilder { Template indexCssTemplate = BeetlTemplateUtil.getByName(ALL_IN_ONE_CSS); FileUtil.nioWriteFile(indexCssTemplate.render(), config.getOutPath() + FILE_SEPARATOR + ALL_IN_ONE_CSS); if (config.isAllInOne()) { + apiDocList = docBuildTemplate.handleApiGroup(apiDocList, config); if (config.isCreateDebugPage()) { INDEX_HTML = DEBUG_PAGE_ALL_TPL; if (StringUtils.isNotEmpty(config.getAllInOneDocFileName())) { diff --git a/src/main/java/com/power/doc/builder/TornaBuilder.java b/src/main/java/com/power/doc/builder/TornaBuilder.java index a51699c..9f01320 100644 --- a/src/main/java/com/power/doc/builder/TornaBuilder.java +++ b/src/main/java/com/power/doc/builder/TornaBuilder.java @@ -80,6 +80,7 @@ public class TornaBuilder { ProjectDocConfigBuilder configBuilder = new ProjectDocConfigBuilder(config, javaProjectBuilder); IDocBuildTemplate docBuildTemplate = BuildTemplateFactory.getDocBuildTemplate(config.getFramework()); List apiDocList = docBuildTemplate.getApiData(configBuilder); + apiDocList = docBuildTemplate.handleApiGroup(apiDocList, config); buildTorna(apiDocList, config, javaProjectBuilder); } @@ -94,19 +95,32 @@ public class TornaBuilder { TornaApi tornaApi = new TornaApi(); tornaApi.setAuthor(StringUtil.isEmpty(apiConfig.getAuthor()) ? System.getProperty("user.name") : apiConfig.getAuthor()); Apis api; - List apisList = new ArrayList<>(); + List groupApiList = new ArrayList<>(); //添加接口数据 - for (ApiDoc a : apiDocs) { + for (ApiDoc groupApi : apiDocs) { + + List apisList = new ArrayList<>(); + List childrenApiDocs = groupApi.getChildrenApiDocs(); + for (ApiDoc a : childrenApiDocs) { + api = new Apis(); + api.setName(StringUtils.isBlank(a.getDesc()) ? a.getName() : a.getDesc()); + api.setItems(buildApis(a.getList(), TornaUtil.setDebugEnv(apiConfig, tornaApi))); + api.setIsFolder(TornaConstants.YES); + api.setAuthor(a.getAuthor()); + api.setOrderIndex(a.getOrder()); + apisList.add(api); + } api = new Apis(); - api.setName(StringUtils.isBlank(a.getDesc()) ? a.getName() : a.getDesc()); - api.setItems(buildApis(a.getList(), TornaUtil.setDebugEnv(apiConfig, tornaApi))); + api.setName(StringUtils.isBlank(groupApi.getDesc()) ? groupApi.getName() : groupApi.getDesc()); + api.setAuthor(tornaApi.getAuthor()); + api.setOrderIndex(groupApi.getOrder()); api.setIsFolder(TornaConstants.YES); - api.setAuthor(a.getAuthor()); - api.setOrderIndex(a.getOrder()); - apisList.add(api); + api.setItems(apisList); + groupApiList.add(api); + } tornaApi.setCommonErrorCodes(buildErrorCode(apiConfig)); - tornaApi.setApis(apisList); + tornaApi.setApis(groupApiList); //推送文档信息 Map requestJson = TornaConstants.buildParams(PUSH, new Gson().toJson(tornaApi), apiConfig); //推送字典信息 diff --git a/src/main/java/com/power/doc/model/ApiConfig.java b/src/main/java/com/power/doc/model/ApiConfig.java index 22e9925..74769a8 100644 --- a/src/main/java/com/power/doc/model/ApiConfig.java +++ b/src/main/java/com/power/doc/model/ApiConfig.java @@ -26,8 +26,10 @@ import com.power.common.util.CollectionUtil; import com.power.doc.constants.DocLanguage; import com.power.doc.model.rpc.RpcApiDependency; +import java.util.Arrays; import java.util.List; import java.util.Objects; +import java.util.stream.Collectors; /** * Description: @@ -347,6 +349,8 @@ public class ApiConfig { */ private String framework; + private List groups; + public String getPathPrefix() { return pathPrefix; } @@ -440,6 +444,20 @@ public class ApiConfig { this.requestHeaders.forEach(header -> header.setDesc(header.getDesc() + "(Global)")); } + public List getGroups() { + return groups; + } + + public ApiConfig setGroups(List groups) { + this.groups = groups; + return this; + } + + public ApiConfig setGroups(ApiGroup... groups) { + this.groups = CollectionUtil.asList(groups); + return this; + } + public List getRequestParams() { return requestParams; } diff --git a/src/main/java/com/power/doc/model/ApiDoc.java b/src/main/java/com/power/doc/model/ApiDoc.java index 829bc85..e27f1d8 100644 --- a/src/main/java/com/power/doc/model/ApiDoc.java +++ b/src/main/java/com/power/doc/model/ApiDoc.java @@ -57,6 +57,19 @@ public class ApiDoc implements Comparable { */ private String[] tags; + /** + * group + * + * @author cqmike + */ + private String group; + + /** + * class in package name + * + */ + private String packageName; + /** * List of method doc */ @@ -74,6 +87,16 @@ public class ApiDoc implements Comparable { private String author; + /** + * if this is group, then is true + */ + private boolean isFolder; + + /** + * children + */ + private List childrenApiDocs = new ArrayList<>(); + public String getAuthor() { return author; } @@ -141,6 +164,38 @@ public class ApiDoc implements Comparable { this.link = link; } + public String getPackageName() { + return packageName; + } + + public void setPackageName(String packageName) { + this.packageName = packageName; + } + + public String getGroup() { + return group; + } + + public void setGroup(String group) { + this.group = group; + } + + public boolean isFolder() { + return isFolder; + } + + public void setFolder(boolean folder) { + isFolder = folder; + } + + public List getChildrenApiDocs() { + return childrenApiDocs; + } + + public void setChildrenApiDocs(List childrenApiDocs) { + this.childrenApiDocs = childrenApiDocs; + } + @Override public int compareTo(ApiDoc o) { if (Objects.nonNull(o.getDesc())) { @@ -155,6 +210,7 @@ public class ApiDoc implements Comparable { apiDoc.setLink(source.getLink()); apiDoc.setDesc(tag); apiDoc.setAuthor(source.getAuthor()); + apiDoc.setPackageName(source.getPackageName()); apiDoc.setName(tag); apiDoc.setList(new ArrayList<>()); ApiMethodDoc clone = methodDoc.clone(); @@ -164,6 +220,16 @@ public class ApiDoc implements Comparable { } + public static ApiDoc buildGroupApiDoc(String group) { + ApiDoc apiDoc = new ApiDoc(); + apiDoc.setFolder(true); + apiDoc.setGroup(group); + apiDoc.setName(group); + apiDoc.setDesc(group); + apiDoc.setChildrenApiDocs(new ArrayList<>()); + return apiDoc; + } + @Override public String toString() { final StringBuilder sb = new StringBuilder("{"); diff --git a/src/main/java/com/power/doc/model/ApiGroup.java b/src/main/java/com/power/doc/model/ApiGroup.java new file mode 100644 index 0000000..eb813b5 --- /dev/null +++ b/src/main/java/com/power/doc/model/ApiGroup.java @@ -0,0 +1,55 @@ +package com.power.doc.model; + +/** + * api group + * + * @author cqmike + * @version 1.0.0 + * @since 2021年07月31日 16:39:00 + */ +public class ApiGroup { + + /** + * group name + */ + private String name; + + /** + * package name + * support patten + */ + private String apis; + + /** + * url path + * support patten + */ + private String paths; + + public String getName() { + return name; + } + + public ApiGroup setName(String name) { + this.name = name; + return this; + } + + public String getApis() { + return apis; + } + + public ApiGroup setApis(String apis) { + this.apis = apis; + return this; + } + + public String getPaths() { + return paths; + } + + public ApiGroup setPaths(String paths) { + this.paths = paths; + return this; + } +} diff --git a/src/main/java/com/power/doc/template/IDocBuildTemplate.java b/src/main/java/com/power/doc/template/IDocBuildTemplate.java index 799698a..70468b8 100644 --- a/src/main/java/com/power/doc/template/IDocBuildTemplate.java +++ b/src/main/java/com/power/doc/template/IDocBuildTemplate.java @@ -35,6 +35,8 @@ import com.thoughtworks.qdox.model.JavaMethod; import com.thoughtworks.qdox.model.JavaType; import java.util.*; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.Collectors; import static com.power.doc.constants.DocGlobalConstants.NO_COMMENTS_FOUND; import static com.power.doc.constants.DocTags.IGNORE_RESPONSE_BODY_ADVICE; @@ -82,6 +84,8 @@ public interface IDocBuildTemplate { apiDoc.setName(controllerName); apiDoc.setAuthor(classAuthor); apiDoc.setAlias(controllerName); + apiDoc.setFolder(true); + apiDoc.setPackageName(cls.getPackage().getName()); //apiDoc.setAuthor(); // handle class tags @@ -99,6 +103,54 @@ public interface IDocBuildTemplate { } + /** + * handle group api docs + * + * @author cqmike + * @param apiDocList + * @param apiConfig + */ + default List handleApiGroup(List apiDocList, ApiConfig apiConfig) { + if (CollectionUtil.isEmpty(apiDocList) || apiConfig == null) { + return apiDocList; + } + + List groups = apiConfig.getGroups(); + ApiDoc defaultGroup = ApiDoc.buildGroupApiDoc("default"); + + List finalApiDocs = new ArrayList<>(); + finalApiDocs.add(defaultGroup); + AtomicInteger order = new AtomicInteger(1); + defaultGroup.setOrder(order.getAndIncrement()); + groups.forEach(group -> { + + ApiDoc groupApiDoc = ApiDoc.buildGroupApiDoc(group.getName()); + groupApiDoc.setOrder(order.getAndIncrement()); + finalApiDocs.add(groupApiDoc); + apiDocList.forEach(doc -> { + + if (!DocUtil.isMatch(group.getApis(), doc.getPackageName())) { + defaultGroup.getChildrenApiDocs().add(doc); + doc.setOrder(defaultGroup.getChildrenApiDocs().size()); + return; + } + groupApiDoc.getChildrenApiDocs().add(doc); + doc.setOrder(groupApiDoc.getChildrenApiDocs().size()); + doc.setGroup(group.getName()); + if (StringUtil.isEmpty(group.getPaths())) { + return; + } + List methodDocs = doc.getList().stream() + .filter(l -> DocPathUtil.matches(l.getPath(), group.getPaths(), null)) + .collect(Collectors.toList()); + doc.setList(methodDocs); + }); + }); + + return finalApiDocs; + } + + default List buildReturnApiParams(DocJavaMethod docJavaMethod, ProjectDocConfigBuilder projectBuilder) { JavaMethod method = docJavaMethod.getJavaMethod(); if (method.getReturns().isVoid() && Objects.isNull(projectBuilder.getApiConfig().getResponseBodyAdvice())) { diff --git a/src/main/resources/template/AllInOne.adoc b/src/main/resources/template/AllInOne.adoc index 319ec70..ac7f46e 100644 --- a/src/main/resources/template/AllInOne.adoc +++ b/src/main/resources/template/AllInOne.adoc @@ -17,26 +17,30 @@ for(revisionLog in revisionLogList){ <% -for(api in apiDocList){ +for(apiGroup in apiDocList){ %> -== ${api.desc} +== ${apiGroup.group} +<% +for(api in apiGroup.childrenApiDocs){ +%> +=== ${api.desc} <% for(doc in api.list){ %> <%if(doc.deprecated){%> -=== [line-through]#${doc.desc}# +==== [line-through]#${doc.desc}# <%}else{%> -=== ${doc.desc} +==== ${doc.desc} <%}%> -*URL:* ${doc.url} +*URL:* `${doc.url}` -*Type:* ${doc.type} +*Type:* `${doc.type}` <%if(isNotEmpty(doc.author)){%> *Author:* ${doc.author} <%}%> -*Content-Type:* ${doc.contentType} +*Content-Type:* `${doc.contentType}` <%if(isNotEmpty(doc.headers)){%> *Request-headers:* @@ -122,6 +126,7 @@ ${doc.responseUsage} ---- <%}%> +<% } %> <% } %> <% } %> <%if(isNotEmpty(errorCodeList)){%> diff --git a/src/main/resources/template/AllInOne.btl b/src/main/resources/template/AllInOne.btl index 18ea36d..b565da4 100644 --- a/src/main/resources/template/AllInOne.btl +++ b/src/main/resources/template/AllInOne.btl @@ -14,7 +14,11 @@ ${revisionLog.version}|${revisionLog.revisionTime}|${revisionLog.status}|${revis <% -for(api in apiDocList){ +for(apiGroup in apiDocList){ +%> +# ${apiGroup.group} +<% +for(api in apiGroup.childrenApiDocs){ %> ## ${api.desc} <% @@ -106,6 +110,7 @@ ${doc.responseUsage} ``` <%}%> +<% } %> <% } %> <% } %> <%if(isNotEmpty(errorCodeList)){%> diff --git a/src/main/resources/template/debug-all.html b/src/main/resources/template/debug-all.html index 1e86df6..c624aac 100644 --- a/src/main/resources/template/debug-all.html +++ b/src/main/resources/template/debug-all.html @@ -1,30 +1,492 @@ -<%if(isNotEmpty(projectName)){%>${projectName}<%}else{%>API Reference<%}%>
<%if(isNotEmpty(revisionLogList)){%>
<%for(revisionLog in revisionLogList){%><%}%>
VersionUpdate TimeStatusAuthorDescription

${revisionLog.version}

${revisionLog.revisionTime}

${revisionLog.status}

${revisionLog.author}

${revisionLog.remarks}

<%}%><%for(api in apiDocList){%>

${api.order}. ${htmlEscape(api.desc)}

<%for(doc in api.list){%>

<%if(doc.deprecated){%>${api.order}.${doc.order}. ${htmlEscape(doc.desc)}<%}else{%>${api.order}.${doc.order}. ${htmlEscape(doc.desc)}<%}%>

Type: ${doc.type}

<%if(isNotEmpty(doc.author)){%>

Author:  ${doc.author}

<%}%>

Content-Type: ${doc.contentType}

Description:  ${htmlEscape(doc.detail)}

<%if(isNotEmpty(doc.requestHeaders)){%>

Request-headers:

<%for(header in doc.requestHeaders){%><%}%>
HeaderValueTypeRequiredDescription

${header.name}

${header.type}

${header.required}

${htmlEscape(header.desc)}

<%}%><%if(isNotEmpty(doc.pathParams)){%>

Path-parameters:

<%for(param in doc.pathParams){%><%}%>
Parameter ValueTypeRequiredDescription

${param.field}

${param.type}

${param.required}

${htmlEscape(param.desc)}

<%}%><%if(isNotEmpty(doc.queryParams)){%>

Query-parameters:

<%for(param in doc.queryParams){%><%if(param.version !='-' ){%><%}else{%><%}%><%}%>
ParameterValueTypeRequiredDescription

${param.field}

<%if(param.type=="file"){%><%}else{%><%}%>

${param.type}

${param.required}

${htmlEscape(param.desc)}@since ${param.version}

${htmlEscape(param.desc)}

<%}%><%if(isNotEmpty(doc.requestParams)){%>

Body-parameters:

<%for(param in doc.requestParams){%><%if(param.version !='-' ){%><%}else{%><%}%><%}%>
ParameterTypeRequiredDescription

${param.field}

${param.type}

${param.required}

${htmlEscape(param.desc)}@since ${param.version}

${htmlEscape(param.desc)}

<%}%><%if(isNotEmpty(doc.requestExample.jsonBody)&&isRequestExample){%>

Request-body:

${doc.requestExample.jsonBody}
<%}%><%if(isNotEmpty(doc.responseParams)){%>

Response-fields:

<%for(param in doc.responseParams){%><%}%>
FieldTypeDescriptionSince

${param.field}

${param.type}

${htmlEscape(param.desc)}

${param.version}

<%}%>

<%if(isNotEmpty(doc.responseUsage)&&isResponseExample){%>

Response-example:

${doc.responseUsage}
<%}%><%if(isNotEmpty(doc.requestUsage)&&isRequestExample){%>

Curl-example:

${doc.requestUsage}
<%}%>
<%}%>
<%}%><%if(isNotEmpty(errorCodeList)){%>

${apiDocList.~size+1}. ${errorListTitle}

<%for(error in errorCodeList){%><%}%>
Error codeDescription

${error.value}

${htmlEscape(error.desc)}

<%}%><%if(isNotEmpty(dictList)){%>

${dictListOrder}. ${dictListTitle}

<%for(dict in dictList){%>

${dictListOrder}.${dict.order}. ${htmlEscape(dict.title)}

<%for(dataDict in dict.dataDictList){%><%}%>
CodeTypeDescription

${dataDict.value}

${dataDict.type}

${htmlEscape(dataDict.desc)}

<%}%>
<%}%>
Generated by smart-doc at ${createTime}Suggestions,contact,support and error reporting on Gitee or Github
Top
- - - + + + + +
<%if(isNotEmpty(revisionLogList)){%> +
+
+ + + + + + + + + + + + + + + + + + <%for(revisionLog in revisionLogList){%> + + + + + + + + <%}%> + +
VersionUpdate TimeStatusAuthorDescription

+ ${revisionLog.version}

+ ${revisionLog.revisionTime}

+ ${revisionLog.status}

+ ${revisionLog.author}

+ ${revisionLog.remarks}

+
+
+ <%}%> + <%for(apiGroup in apiDocList){%> + <%for(api in apiGroup.childrenApiDocs){%> +

${api.order}. ${htmlEscape(api.desc)} +

+
<%for(doc in api.list){%> +

<%if(doc.deprecated){%>${api.order}.${doc.order}. ${htmlEscape(doc.desc)}<%}else{%>${api.order}.${doc.order}. ${htmlEscape(doc.desc)}<%}%> +

+ +

+ Type: ${doc.type}

+ <%if(isNotEmpty(doc.author)){%> +

Author:  ${doc.author}

+ <%}%> +
+

Content-Type: ${doc.contentType}

+

Description:  ${htmlEscape(doc.detail)}

+
+ <%if(isNotEmpty(doc.requestHeaders)){%> +

Request-headers:

+ + + + + + + + + + + + + + + + + + + + <%for(header in doc.requestHeaders){%> + + + + + + + + + <%}%> + +
+
+
HeaderValueTypeRequiredDescription
+
+

${header.name}

+

${header.type}

+

+ ${header.required}

+ ${htmlEscape(header.desc)}

+ <%}%><%if(isNotEmpty(doc.pathParams)){%> +

Path-parameters:

+ + + + + + + + + + + + + + + + + + + + <%for(param in doc.pathParams){%> + + + + + + + + + <%}%> + +
+
+
Parameter ValueTypeRequiredDescription
+
+

${param.field}

+

${param.type}

+

+ ${param.required}

+ ${htmlEscape(param.desc)}

+ <%}%><%if(isNotEmpty(doc.queryParams)){%> +

Query-parameters:

+ + + + + + + + + + + + + + + + + + + + <%for(param in doc.queryParams){%> + + + + + + + <%if(param.version !='-' ){%> + + <%}else{%> + + <%}%> + + <%}%> + +
+
+
ParameterValueTypeRequiredDescription
+
+

${param.field}

+

+ <%if(param.type=="file"){%><%}else{%><%}%>

${param.type}

+

+ ${param.required}

+ ${htmlEscape(param.desc)}@since ${param.version}

+ ${htmlEscape(param.desc)}

+ <%}%><%if(isNotEmpty(doc.requestParams)){%> +

Body-parameters:

+ + + + + + + + + + + + + + + + <%for(param in doc.requestParams){%> + + + + + <%if(param.version !='-' ){%> + + <%}else{%> + + <%}%> + + <%}%> + +
ParameterTypeRequiredDescription

${param.field}

+

${param.type}

+

+ ${param.required}

+ ${htmlEscape(param.desc)}@since ${param.version}

+ ${htmlEscape(param.desc)}

+ <%}%><%if(isNotEmpty(doc.requestExample.jsonBody)&&isRequestExample){%> +

Request-body:

+
+
+
${doc.requestExample.jsonBody}
+
+
+ <%}%><%if(isNotEmpty(doc.responseParams)){%> +

Response-fields:

+ + + + + + + + + + + + + + + + <%for(param in doc.responseParams){%> + + + + + + + <%}%> + +
FieldTypeDescriptionSince

${param.field}

+

${param.type}

+

+ ${htmlEscape(param.desc)}

${param.version}

+
+ <%}%> +
+

+ +

+
+ <%if(isNotEmpty(doc.responseUsage)&&isResponseExample){%> +

Response-example:

+
+
+
${doc.responseUsage}
+
+
+ <%}%><%if(isNotEmpty(doc.requestUsage)&&isRequestExample){%> +

Curl-example:

+
+
+
${doc.requestUsage}
+
+
+ <%}%> +
+ <%}%> +
+
+ <%}%> + <%}%> + <%if(isNotEmpty(errorCodeList)){%> +

${apiDocList.~size+1}. ${errorListTitle} +

+
+ + + + + + + + + + + + <%for(error in errorCodeList){%> + + + + + <%}%> + +
Error codeDescription

${error.value}

+ ${htmlEscape(error.desc)}

+
+
+ <%}%><%if(isNotEmpty(dictList)){%> +

${dictListOrder}. ${dictListTitle} +

+
<%for(dict in dictList){%> +

+ ${dictListOrder}.${dict.order}. ${htmlEscape(dict.title)}

+ + + + + + + + + + + + + + <%for(dataDict in dict.dataDictList){%> + + + + + + <%}%> + +
CodeTypeDescription

+ ${dataDict.value}

${dataDict.type}

+

+ ${htmlEscape(dataDict.desc)}

+
+ <%}%> +
+
+ <%}%> +
Generated by smart-doc at ${createTime}Suggestions,contact,support and error reporting on Gitee or Github +
+
Top
+
+ + + - + }); + + \ No newline at end of file diff --git a/src/main/resources/template/js/search_all.js.btl b/src/main/resources/template/js/search_all.js.btl index d98e5ff..7942d91 100644 --- a/src/main/resources/template/js/search_all.js.btl +++ b/src/main/resources/template/js/search_all.js.btl @@ -1,6 +1,12 @@ let api = []; -<%for(api in apiDocList){%> +<%for(apiGroup in apiDocList) {%> api.push({ + name: '${apiGroup.group}', + order: '${apiGroup.order}', + list: [] +}) +<%for(api in apiGroup.childrenApiDocs) {%> +api[${apiGroupLP.dataIndex}].list.push({ alias: '${api.alias}', order: '${api.order}', link: '${removeLineBreaks(api.link)}', @@ -8,12 +14,13 @@ api.push({ list: [] }) <%for(doc in api.list) {%> -api[${apiLP.dataIndex}].list.push({ +api[${apiGroupLP.dataIndex}].list[${apiLP.dataIndex}].list.push({ order: '${doc.order}', desc: '${removeLineBreaks(doc.desc)}', }); <%}%> <%}%> +<%}%> document.onkeydown = keyDownSearch; function keyDownSearch(e) { const theEvent = e; @@ -21,38 +28,52 @@ function keyDownSearch(e) { if (code == 13) { const search = document.getElementById('search'); const searchValue = search.value; - let searchArr = []; + let searchGroup = []; for (let i = 0; i < api.length; i++) { - let apiData = api[i]; - const desc = apiData.desc; - if (desc.indexOf(searchValue) > -1) { - searchArr.push({ - order: apiData.order, - desc: apiData.desc, - link: apiData.link, - list: apiData.list - }); - } else { - let methodList = apiData.list || []; - let methodListTemp = []; - for (let j = 0; j < methodList.length; j++) { - const methodData = methodList[j]; - const methodDesc = methodData.desc; - if (methodDesc.indexOf(searchValue) > -1) { - methodListTemp.push(methodData); - break; - } - } - if (methodListTemp.length > 0) { - const data = { + + let apiGroup = api[i]; + + let searchArr = []; + for (let i = 0; i < apiGroup.list.length; i++) { + let apiData = apiGroup.list[i]; + const desc = apiData.desc; + if (desc.indexOf(searchValue) > -1) { + searchArr.push({ order: apiData.order, desc: apiData.desc, link: apiData.link, - list: methodListTemp - }; - searchArr.push(data); + list: apiData.list + }); + } else { + let methodList = apiData.list || []; + let methodListTemp = []; + for (let j = 0; j < methodList.length; j++) { + const methodData = methodList[j]; + const methodDesc = methodData.desc; + if (methodDesc.indexOf(searchValue) > -1) { + methodListTemp.push(methodData); + break; + } + } + if (methodListTemp.length > 0) { + const data = { + order: apiData.order, + desc: apiData.desc, + link: apiData.link, + list: methodListTemp + }; + searchArr.push(data); + } } } + if (searchArr.length === 0) { + continue; + } + searchGroup.push({ + name: apiGroup.name, + order: apiGroup.order, + list: searchArr + }); } let html; if (searchValue == '') { @@ -63,7 +84,7 @@ function keyDownSearch(e) { } else { const liClass = "open"; const display = "display: block"; - html = buildAccordion(searchArr,liClass,display); + html = buildAccordion(searchGroup,liClass,display); document.getElementById('accordion').innerHTML = html; } const Accordion = function (el, multiple) { @@ -85,18 +106,29 @@ function keyDownSearch(e) { } } -function buildAccordion(apiData, liClass, display) { +function buildAccordion(apiGroups, liClass, display) { let html = ""; let doc; - if (apiData.length > 0) { - for (let j = 0; j < apiData.length; j++) { + if (apiGroups.length > 0) { + for (let i = 0; i < apiGroups.length; i++) { + let apiGroup = apiGroups[i]; html += '
  • '; - html += '' + apiData[j].order + '. ' + apiData[j].desc + ''; - html += '
      '; - doc = apiData[j].list; - for (let m = 0; m < doc.length; m++) { - html += '
    • ' + apiData[j].order + '.' + doc[m].order + '. ' + doc[m].desc + '
    • '; + html += '' + apiGroup.order + '. ' + apiGroup.name + ''; + html += ''; html += ''; } diff --git a/src/test/java/com/power/doc/ApiDocTest.java b/src/test/java/com/power/doc/ApiDocTest.java index d1d794f..45e87ee 100644 --- a/src/test/java/com/power/doc/ApiDocTest.java +++ b/src/test/java/com/power/doc/ApiDocTest.java @@ -102,7 +102,7 @@ public class ApiDocTest { //OpenApiBuilder.buildOpenApi(config); HtmlApiDocBuilder.buildApiDoc(config); //RpcTornaBuilder.buildApiDoc(config); - TornaBuilder.buildApiDoc(config); +// TornaBuilder.buildApiDoc(config); // RpcHtmlBuilder.buildApiDoc(config); long end = System.currentTimeMillis(); DateTimeUtil.printRunTime(end, start);