From b0dfa642720d29dc0c9776cafac50d006967ed50 Mon Sep 17 00:00:00 2001 From: songhaozhi <1150837340@qq.com> Date: Sun, 15 Dec 2019 15:48:43 +0800 Subject: [PATCH] feat show author --- .../com/power/doc/builder/SourceBuilder.java | 24 ++++++++++++------- .../java/com/power/doc/constants/DocTags.java | 5 ++++ .../com/power/doc/model/ApiMethodDoc.java | 13 ++++++++++ src/main/resources/template/AllInOne.adoc | 4 +++- src/main/resources/template/AllInOne.btl | 4 ++++ src/main/resources/template/AllInOne.html | 24 +------------------ src/main/resources/template/ApiDoc.adoc | 4 ++++ src/main/resources/template/ApiDoc.btl | 4 ++++ 8 files changed, 49 insertions(+), 33 deletions(-) diff --git a/src/main/java/com/power/doc/builder/SourceBuilder.java b/src/main/java/com/power/doc/builder/SourceBuilder.java index 65879fa..256cf5e 100644 --- a/src/main/java/com/power/doc/builder/SourceBuilder.java +++ b/src/main/java/com/power/doc/builder/SourceBuilder.java @@ -60,25 +60,26 @@ public class SourceBuilder { private String appUrl; private boolean isUseMD5; private boolean isAdoc; + private boolean isShowAuthor; /** * if isStrict value is true,it while check all method * - * @param isStrict strict flag + * @param isStrict strict flag * @param projectBuilder JavaProjectBuilder */ - public SourceBuilder(boolean isStrict,JavaProjectBuilder projectBuilder) { - loadJavaFiles(null,projectBuilder); + public SourceBuilder(boolean isStrict, JavaProjectBuilder projectBuilder) { + loadJavaFiles(null, projectBuilder); this.isStrict = isStrict; } /** * use custom config * - * @param config config + * @param config config * @param projectBuilder JavaProjectBuilder */ - public SourceBuilder(ApiConfig config,JavaProjectBuilder projectBuilder) { + public SourceBuilder(ApiConfig config, JavaProjectBuilder projectBuilder) { if (null == config) { throw new NullPointerException("ApiConfig can't be null."); } @@ -93,7 +94,8 @@ public class SourceBuilder { this.packageMatch = config.getPackageFilters(); this.isStrict = config.isStrict(); this.isAdoc = config.isAdoc(); - loadJavaFiles(config.getSourceCodePaths(),projectBuilder); + this.isShowAuthor = config.isShowAuthor(); + loadJavaFiles(config.getSourceCodePaths(), projectBuilder); this.headers = config.getRequestHeaders(); if (CollectionUtil.isNotEmpty(config.getCustomResponseFields())) { @@ -183,6 +185,10 @@ public class SourceBuilder { if (StringUtil.isEmpty(apiNoteValue)) { apiNoteValue = method.getComment(); } + String authorValue = DocUtil.getNormalTagComments(method, DocTags.AUTHOR, cls.getName()); + if(this.isShowAuthor && StringUtil.isNotEmpty(authorValue)){ + apiMethodDoc.setAuthor(authorValue); + } apiMethodDoc.setDetail(apiNoteValue); List annotations = method.getAnnotations(); String url = null; @@ -324,8 +330,8 @@ public class SourceBuilder { * * @param paths list of SourcePath */ - private void loadJavaFiles(List paths,JavaProjectBuilder builder) { - if(Objects.isNull(builder)) { + private void loadJavaFiles(List paths, JavaProjectBuilder builder) { + if (Objects.isNull(builder)) { builder = new JavaProjectBuilder(); } if (CollectionUtil.isEmpty(paths)) { @@ -1289,7 +1295,7 @@ public class SourceBuilder { || DocAnnotationConstants.SHORT_REST_CONTROLLER.equals(annotationName) || DocGlobalConstants.REST_CONTROLLER_FULLY.equals(annotationName) || DocGlobalConstants.CONTROLLER_FULLY.equals(annotationName) - ) { + ) { return true; } } diff --git a/src/main/java/com/power/doc/constants/DocTags.java b/src/main/java/com/power/doc/constants/DocTags.java index a20421d..b4c83fc 100644 --- a/src/main/java/com/power/doc/constants/DocTags.java +++ b/src/main/java/com/power/doc/constants/DocTags.java @@ -25,6 +25,11 @@ public class DocTags { */ public static final String API_NOTE = "apiNote"; + /** + * java author tag for method author + */ + public static final String AUTHOR = "author"; + /** * custom ignore tag */ diff --git a/src/main/java/com/power/doc/model/ApiMethodDoc.java b/src/main/java/com/power/doc/model/ApiMethodDoc.java index c18e514..1900386 100644 --- a/src/main/java/com/power/doc/model/ApiMethodDoc.java +++ b/src/main/java/com/power/doc/model/ApiMethodDoc.java @@ -52,6 +52,11 @@ public class ApiMethodDoc implements Serializable { */ private String type; + /** + * http request author + */ + private String author; + /** * only used for generate markdown and adoc * http readers @@ -201,4 +206,12 @@ public class ApiMethodDoc implements Serializable { public void setDetail(String detail) { this.detail = detail; } + + public String getAuthor() { + return author; + } + + public void setAuthor(String author) { + this.author = author; + } } diff --git a/src/main/resources/template/AllInOne.adoc b/src/main/resources/template/AllInOne.adoc index 31408aa..3687023 100644 --- a/src/main/resources/template/AllInOne.adoc +++ b/src/main/resources/template/AllInOne.adoc @@ -27,7 +27,9 @@ for(doc in api.list){ *URL:* ${doc.url} *Type:* ${doc.type} - +<%if(isNotEmpty(doc.author)){%> +*Author:* ${doc.author} +<%}%> *Description:* ${doc.detail} *Content-Type:* ${doc.contentType} diff --git a/src/main/resources/template/AllInOne.btl b/src/main/resources/template/AllInOne.btl index 357375b..26d155e 100644 --- a/src/main/resources/template/AllInOne.btl +++ b/src/main/resources/template/AllInOne.btl @@ -25,6 +25,10 @@ for(doc in api.list){ **Type:** ${doc.type} +<%if(isNotEmpty(doc.author)){%> +**Author:** ${doc.author} +<%}%> + **Content-Type:** ${doc.contentType} **Description:** ${doc.detail} diff --git a/src/main/resources/template/AllInOne.html b/src/main/resources/template/AllInOne.html index fb1d69d..830fef0 100644 --- a/src/main/resources/template/AllInOne.html +++ b/src/main/resources/template/AllInOne.html @@ -1,23 +1 @@ -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}. ${api.desc}

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

${api.order}.${doc.order}. ${doc.desc}

Type: ${doc.type}

Content-Type: ${doc.contentType}

Description: ${doc.detail}

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

Request-headers:

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

${header.name}

${header.type}

${header.desc}

${header.required}

${header.since}

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

Request-parameters:

<%for(param in doc.requestParams){%><%}%>
ParameterTypeDescriptionRequiredSince

${param.field}

${param.type}

${param.desc}

${param.required}

${param.version}

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

Request-example:

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

Response-fields:

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

${param.field}

${param.type}

${param.desc}

${param.version}

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

Response-example:

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

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

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

${error.value}

${error.desc}

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

${dictListOrder}. ${dictListTitle}

<% for(dict in dictList){ %>

${dictListOrder}.${dict.order}. ${dict.title}

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

${dataDict.value}

${dataDict.type}

${dataDict.desc}

<%}%>
<%}%>
Generated by smart-doc at ${createTime}Suggestions,contact,support and error reporting on Gitee or Github
- - - \ No newline at end of file +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}. ${api.desc}

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

${api.order}.${doc.order}. ${doc.desc}

Type: ${doc.type}

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

Author: ${doc.author}

<%}%>

Content-Type: ${doc.contentType}

Description: ${doc.detail}

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

Request-headers:

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

${header.name}

${header.type}

${header.desc}

${header.required}

${header.since}

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

Request-parameters:

<%for(param in doc.requestParams){%><%}%>
ParameterTypeDescriptionRequiredSince

${param.field}

${param.type}

${param.desc}

${param.required}

${param.version}

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

Request-example:

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

Response-fields:

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

${param.field}

${param.type}

${param.desc}

${param.version}

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

Response-example:

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

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

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

${error.value}

${error.desc}

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

${dictListOrder}. ${dictListTitle}

<% for(dict in dictList){ %>

${dictListOrder}.${dict.order}. ${dict.title}

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

${dataDict.value}

${dataDict.type}

${dataDict.desc}

<%}%>
<%}%>
Generated by smart-doc at ${createTime}Suggestions,contact,support and error reporting on Gitee or Github
\ No newline at end of file diff --git a/src/main/resources/template/ApiDoc.adoc b/src/main/resources/template/ApiDoc.adoc index 467500f..fcf046e 100644 --- a/src/main/resources/template/ApiDoc.adoc +++ b/src/main/resources/template/ApiDoc.adoc @@ -8,6 +8,10 @@ for(doc in list){ *Type:* `${doc.type}` +<%if(isNotEmpty(doc.author)){%> +*Author:* ${doc.author} +<%}%> + *Content-Type:* `${doc.contentType}` *Description:* ${doc.detail} diff --git a/src/main/resources/template/ApiDoc.btl b/src/main/resources/template/ApiDoc.btl index 2a89839..2b2e9eb 100644 --- a/src/main/resources/template/ApiDoc.btl +++ b/src/main/resources/template/ApiDoc.btl @@ -8,6 +8,10 @@ for(doc in list){ **Type:** `${doc.type}` +<%if(isNotEmpty(doc.author)){%> +**Author:** ${doc.author} +<%}%> + **Content-Type:** `${doc.contentType}` **Description:** ${doc.detail}