feat show author

This commit is contained in:
songhaozhi 2019-12-15 15:48:43 +08:00
parent 1361c449be
commit b0dfa64272
8 changed files with 49 additions and 33 deletions

View File

@ -60,25 +60,26 @@ public class SourceBuilder {
private String appUrl; private String appUrl;
private boolean isUseMD5; private boolean isUseMD5;
private boolean isAdoc; private boolean isAdoc;
private boolean isShowAuthor;
/** /**
* if isStrict value is true,it while check all method * if isStrict value is true,it while check all method
* *
* @param isStrict strict flag * @param isStrict strict flag
* @param projectBuilder JavaProjectBuilder * @param projectBuilder JavaProjectBuilder
*/ */
public SourceBuilder(boolean isStrict,JavaProjectBuilder projectBuilder) { public SourceBuilder(boolean isStrict, JavaProjectBuilder projectBuilder) {
loadJavaFiles(null,projectBuilder); loadJavaFiles(null, projectBuilder);
this.isStrict = isStrict; this.isStrict = isStrict;
} }
/** /**
* use custom config * use custom config
* *
* @param config config * @param config config
* @param projectBuilder JavaProjectBuilder * @param projectBuilder JavaProjectBuilder
*/ */
public SourceBuilder(ApiConfig config,JavaProjectBuilder projectBuilder) { public SourceBuilder(ApiConfig config, JavaProjectBuilder projectBuilder) {
if (null == config) { if (null == config) {
throw new NullPointerException("ApiConfig can't be null."); throw new NullPointerException("ApiConfig can't be null.");
} }
@ -93,7 +94,8 @@ public class SourceBuilder {
this.packageMatch = config.getPackageFilters(); this.packageMatch = config.getPackageFilters();
this.isStrict = config.isStrict(); this.isStrict = config.isStrict();
this.isAdoc = config.isAdoc(); this.isAdoc = config.isAdoc();
loadJavaFiles(config.getSourceCodePaths(),projectBuilder); this.isShowAuthor = config.isShowAuthor();
loadJavaFiles(config.getSourceCodePaths(), projectBuilder);
this.headers = config.getRequestHeaders(); this.headers = config.getRequestHeaders();
if (CollectionUtil.isNotEmpty(config.getCustomResponseFields())) { if (CollectionUtil.isNotEmpty(config.getCustomResponseFields())) {
@ -183,6 +185,10 @@ public class SourceBuilder {
if (StringUtil.isEmpty(apiNoteValue)) { if (StringUtil.isEmpty(apiNoteValue)) {
apiNoteValue = method.getComment(); apiNoteValue = method.getComment();
} }
String authorValue = DocUtil.getNormalTagComments(method, DocTags.AUTHOR, cls.getName());
if(this.isShowAuthor && StringUtil.isNotEmpty(authorValue)){
apiMethodDoc.setAuthor(authorValue);
}
apiMethodDoc.setDetail(apiNoteValue); apiMethodDoc.setDetail(apiNoteValue);
List<JavaAnnotation> annotations = method.getAnnotations(); List<JavaAnnotation> annotations = method.getAnnotations();
String url = null; String url = null;
@ -324,8 +330,8 @@ public class SourceBuilder {
* *
* @param paths list of SourcePath * @param paths list of SourcePath
*/ */
private void loadJavaFiles(List<SourceCodePath> paths,JavaProjectBuilder builder) { private void loadJavaFiles(List<SourceCodePath> paths, JavaProjectBuilder builder) {
if(Objects.isNull(builder)) { if (Objects.isNull(builder)) {
builder = new JavaProjectBuilder(); builder = new JavaProjectBuilder();
} }
if (CollectionUtil.isEmpty(paths)) { if (CollectionUtil.isEmpty(paths)) {
@ -1289,7 +1295,7 @@ public class SourceBuilder {
|| DocAnnotationConstants.SHORT_REST_CONTROLLER.equals(annotationName) || DocAnnotationConstants.SHORT_REST_CONTROLLER.equals(annotationName)
|| DocGlobalConstants.REST_CONTROLLER_FULLY.equals(annotationName) || DocGlobalConstants.REST_CONTROLLER_FULLY.equals(annotationName)
|| DocGlobalConstants.CONTROLLER_FULLY.equals(annotationName) || DocGlobalConstants.CONTROLLER_FULLY.equals(annotationName)
) { ) {
return true; return true;
} }
} }

View File

@ -25,6 +25,11 @@ public class DocTags {
*/ */
public static final String API_NOTE = "apiNote"; public static final String API_NOTE = "apiNote";
/**
* java author tag for method author
*/
public static final String AUTHOR = "author";
/** /**
* custom ignore tag * custom ignore tag
*/ */

View File

@ -52,6 +52,11 @@ public class ApiMethodDoc implements Serializable {
*/ */
private String type; private String type;
/**
* http request author
*/
private String author;
/** /**
* only used for generate markdown and adoc * only used for generate markdown and adoc
* http readers * http readers
@ -201,4 +206,12 @@ public class ApiMethodDoc implements Serializable {
public void setDetail(String detail) { public void setDetail(String detail) {
this.detail = detail; this.detail = detail;
} }
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
} }

View File

@ -27,7 +27,9 @@ for(doc in api.list){
*URL:* ${doc.url} *URL:* ${doc.url}
*Type:* ${doc.type} *Type:* ${doc.type}
<%if(isNotEmpty(doc.author)){%>
*Author:* ${doc.author}
<%}%>
*Description:* ${doc.detail} *Description:* ${doc.detail}
*Content-Type:* ${doc.contentType} *Content-Type:* ${doc.contentType}

View File

@ -25,6 +25,10 @@ for(doc in api.list){
**Type:** ${doc.type} **Type:** ${doc.type}
<%if(isNotEmpty(doc.author)){%>
**Author:** ${doc.author}
<%}%>
**Content-Type:** ${doc.contentType} **Content-Type:** ${doc.contentType}
**Description:** ${doc.detail} **Description:** ${doc.detail}

File diff suppressed because one or more lines are too long

View File

@ -8,6 +8,10 @@ for(doc in list){
*Type:* `${doc.type}` *Type:* `${doc.type}`
<%if(isNotEmpty(doc.author)){%>
*Author:* ${doc.author}
<%}%>
*Content-Type:* `${doc.contentType}` *Content-Type:* `${doc.contentType}`
*Description:* ${doc.detail} *Description:* ${doc.detail}

View File

@ -8,6 +8,10 @@ for(doc in list){
**Type:** `${doc.type}` **Type:** `${doc.type}`
<%if(isNotEmpty(doc.author)){%>
**Author:** ${doc.author}
<%}%>
**Content-Type:** `${doc.contentType}` **Content-Type:** `${doc.contentType}`
**Description:** ${doc.detail} **Description:** ${doc.detail}