fix 方法字段不能获取docletTag导致不能过滤ignore标记 & 增加枚举内联展示 添加apiConfig inlineEnum 开启后可将数据字典数据关联到字段说明里面
This commit is contained in:
parent
754ed586b5
commit
f472b7ec52
|
@ -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) {
|
||||
|
|
|
@ -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.");
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<>();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 (paramTags == null || paramTags.isEmpty()) {
|
||||
paramTags = docJavaField.getDocletTags();
|
||||
}
|
||||
return paramTags.stream().collect(Collectors.toMap(DocletTag::getName, DocletTag::getValue,
|
||||
(key1, key2) -> key1 + "," + key2));
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue