merge to dev

# Conflicts:
#	CHANGELOG.md
This commit is contained in:
oppofind 2020-06-15 16:28:59 +08:00
commit 9ede928bf6
8 changed files with 117 additions and 13 deletions

View File

@ -5,11 +5,8 @@
- 更新内容:
1. 修改忽略对LinkedHashMap的解析gitee #I1JI5W
2. 修改接口或和实现类合并分析是字段重复问题gitee #I1JHMW
3. 增加dubbo rpc文档生成支持。
4. 增加将驼峰字段格式转化为下划线格式。
5. maven插件和gradle插件提供includes支持方便自行配置加载第三方库。
6. fix #32.
7. 增加文档接口根据接口标题排序功能。
3. 优化接口方法字段不能获取docletTag的问题。
4. 增加枚举内联展示功能。
#### 版本号1.8.7
- 更新日期: 2020-06-01
- 更新内容:

View File

@ -170,13 +170,13 @@ public class JsonBuildHelper {
if ((responseFieldToUnderline && isResp) || (requestFieldToUnderline && !isResp)) {
fieldName = StringUtil.camelToUnderline(fieldName);
}
Map<String, String> tagsMap = DocUtil.getFieldTagsValue(field);
Map<String, String> tagsMap = DocUtil.getFieldTagsValue(field, docField);
if (!isResp) {
if (tagsMap.containsKey(DocTags.IGNORE)) {
continue out;
}
}
List<JavaAnnotation> annotations = field.getAnnotations();
List<JavaAnnotation> annotations = docField.getAnnotations();
for (JavaAnnotation annotation : annotations) {
String annotationName = annotation.getType().getValue();
if (DocAnnotationConstants.SHORT_JSON_IGNORE.equals(annotationName) && isResp) {

View File

@ -22,6 +22,7 @@
*/
package com.power.doc.helper;
import com.power.common.model.EnumDictionary;
import com.power.common.util.CollectionUtil;
import com.power.common.util.StringUtil;
import com.power.doc.builder.ProjectDocConfigBuilder;
@ -29,6 +30,7 @@ import com.power.doc.constants.DocAnnotationConstants;
import com.power.doc.constants.DocGlobalConstants;
import com.power.doc.constants.DocTags;
import com.power.doc.constants.ValidatorAnnotations;
import com.power.doc.model.ApiDataDictionary;
import com.power.doc.model.ApiParam;
import com.power.doc.model.CustomRespField;
import com.power.doc.model.DocJavaField;
@ -39,6 +41,7 @@ import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import static com.power.doc.constants.DocGlobalConstants.NO_COMMENTS_FOUND;
@ -109,9 +112,9 @@ public class ParamsBuildHelper {
}
String typeSimpleName = field.getType().getSimpleName();
String fieldGicName = field.getType().getGenericCanonicalName();
List<JavaAnnotation> javaAnnotations = field.getAnnotations();
List<JavaAnnotation> javaAnnotations = docField.getAnnotations();
Map<String, String> tagsMap = DocUtil.getFieldTagsValue(field);
Map<String, String> tagsMap = DocUtil.getFieldTagsValue(field, docField);
String since = DocGlobalConstants.DEFAULT_VERSION;//since tag value
if (!isResp) {
pre:
@ -203,8 +206,13 @@ public class ParamsBuildHelper {
JavaClass javaClass = projectBuilder.getJavaProjectBuilder().getClassByName(subTypeName);
String enumComments = javaClass.getComment();
if (StringUtil.isNotEmpty(enumComments) && javaClass.isEnum()) {
enumComments = DocUtil.replaceNewLineToHtmlBr(enumComments);
comment = comment + "(See: " + enumComments + ")";
if (projectBuilder.getApiConfig().getInlineEnum()) {
ApiDataDictionary dataDictionary = projectBuilder.getApiConfig().getDataDictionary(javaClass.getSimpleName());
comment = comment + "(See: " + dictionaryListComment(dataDictionary) + ")";
} else {
enumComments = DocUtil.replaceNewLineToHtmlBr(enumComments);
comment = comment + "(See: " + enumComments + ")";
}
}
String processedType = isShowJavaType ? typeSimpleName : DocClassUtil.processTypeNameForParams(typeSimpleName.toLowerCase());
param.setType(processedType);
@ -337,6 +345,13 @@ public class ParamsBuildHelper {
return paramList;
}
public static String dictionaryListComment(ApiDataDictionary dictionary) {
List<EnumDictionary> enumDataDict = dictionary.getEnumDataDict();
return enumDataDict.stream().map(apiDataDictionary ->
apiDataDictionary.getValue() + ":" + apiDataDictionary.getDesc()
).collect(Collectors.joining(","));
}
public static List<ApiParam> primitiveReturnRespComment(String typeName) {
StringBuilder comments = new StringBuilder();
comments.append("The api directly returns the ").append(typeName).append(" type value.");

View File

@ -181,6 +181,12 @@ public class ApiConfig {
*/
private Boolean showJavaType = Boolean.FALSE;
/**
* is inline enum field comment
* @since 1.8.8
*/
private Boolean inlineEnum = Boolean.FALSE;
/**
* rpc consumer config example
* @since 1.8.7
@ -304,6 +310,12 @@ public class ApiConfig {
this.dataDictionaries = CollectionUtil.asList(dataDictConfigs);
}
public ApiDataDictionary getDataDictionary(String enumClassSimpleName) {
return this.dataDictionaries.stream().filter((apiDataDictionary ->
enumClassSimpleName.equalsIgnoreCase(apiDataDictionary.getEnumClassName())))
.findFirst().orElse(new ApiDataDictionary());
}
public List<ApiErrorCodeDictionary> getErrorCodeDictionaries() {
return errorCodeDictionaries;
}
@ -399,4 +411,12 @@ public class ApiConfig {
public void setRpcConsumerConfig(String rpcConsumerConfig) {
this.rpcConsumerConfig = rpcConsumerConfig;
}
public Boolean getInlineEnum() {
return inlineEnum;
}
public void setInlineEnum(Boolean inlineEnum) {
this.inlineEnum = inlineEnum;
}
}

View File

@ -22,6 +22,13 @@
*/
package com.power.doc.model;
import com.power.common.model.EnumDictionary;
import com.power.common.util.EnumUtil;
import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList;
import java.util.List;
/**
* @author yu 2019/10/31.
*/
@ -72,6 +79,9 @@ public class ApiDataDictionary {
public ApiDataDictionary setEnumClass(Class enumClass) {
this.enumClass = enumClass;
if (StringUtils.isBlank(this.enumClassName)) {
this.enumClassName = enumClass.getSimpleName();
}
return this;
}
@ -101,4 +111,14 @@ public class ApiDataDictionary {
this.enumClassName = enumClassName;
return this;
}
public List<EnumDictionary> getEnumDataDict() {
if (this.enumClass != null) {
return EnumUtil.getEnumInformation(this.enumClass, this.getCodeField(),
this.getDescField());
} else {
return new ArrayList<>();
}
}
}

View File

@ -22,8 +22,13 @@
*/
package com.power.doc.model;
import com.thoughtworks.qdox.model.DocletTag;
import com.thoughtworks.qdox.model.JavaAnnotation;
import com.thoughtworks.qdox.model.JavaField;
import java.util.ArrayList;
import java.util.List;
/**
* @author yu 2020/3/19.
*/
@ -39,6 +44,16 @@ public class DocJavaField {
*/
private String Comment;
/**
* tags
*/
private List<DocletTag> docletTags;
/**
* annotations
*/
private List<JavaAnnotation> annotations;
public static DocJavaField builder() {
return new DocJavaField();
}
@ -60,4 +75,32 @@ public class DocJavaField {
Comment = comment;
return this;
}
public List<DocletTag> getDocletTags() {
if (docletTags == null) {
return new ArrayList<>();
}
return docletTags;
}
public DocJavaField setDocletTags(List<DocletTag> docletTags) {
this.docletTags = docletTags;
return this;
}
public List<JavaAnnotation> getAnnotations() {
List<JavaAnnotation> fieldAnnotations = javaField.getAnnotations();
if (fieldAnnotations != null && !fieldAnnotations.isEmpty()) {
return fieldAnnotations;
}
if (annotations == null) {
return new ArrayList<>();
}
return this.annotations;
}
public DocJavaField setAnnotations(List<JavaAnnotation> annotations) {
this.annotations = annotations;
return this;
}
}

View File

@ -26,6 +26,7 @@ import com.github.javafaker.Faker;
import com.power.common.util.*;
import com.power.doc.constants.DocAnnotationConstants;
import com.power.doc.constants.DocGlobalConstants;
import com.power.doc.model.DocJavaField;
import com.power.doc.model.FormData;
import com.thoughtworks.qdox.model.DocletTag;
import com.thoughtworks.qdox.model.JavaAnnotation;
@ -358,8 +359,11 @@ public class DocUtil {
* @param field JavaField
* @return map
*/
public static Map<String, String> getFieldTagsValue(final JavaField field) {
public static Map<String, String> getFieldTagsValue(final JavaField field, DocJavaField docJavaField) {
List<DocletTag> paramTags = field.getTags();
if (CollectionUtil.isEmpty(paramTags) && Objects.nonNull(docJavaField)) {
paramTags = docJavaField.getDocletTags();
}
return paramTags.stream().collect(Collectors.toMap(DocletTag::getName, DocletTag::getValue,
(key1, key2) -> key1 + "," + key2));
}

View File

@ -85,7 +85,12 @@ public class JavaClassUtil {
addedFields.add(methodName);
String comment = javaMethod.getComment();
JavaField javaField = new DefaultJavaField(javaMethod.getReturns(), methodName);
DocJavaField docJavaField = DocJavaField.builder().setJavaField(javaField).setComment(comment);
DocJavaField docJavaField = DocJavaField.builder()
.setJavaField(javaField)
.setComment(comment)
.setDocletTags(javaMethod.getTags())
.setAnnotations(javaMethod.getAnnotations());
fieldList.add(docJavaField);
}
}