优化枚举显示

This commit is contained in:
unknown 2020-06-16 23:27:53 +08:00
parent a8e092e26a
commit 4d463e60a0
2 changed files with 29 additions and 11 deletions

View File

@ -22,10 +22,7 @@
*/
package com.power.doc.template;
import com.power.common.util.JsonFormatUtil;
import com.power.common.util.RandomUtil;
import com.power.common.util.StringUtil;
import com.power.common.util.UrlUtil;
import com.power.common.util.*;
import com.power.doc.builder.ProjectDocConfigBuilder;
import com.power.doc.constants.*;
import com.power.doc.handler.SpringMVCRequestHeaderHandler;
@ -517,9 +514,13 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate<ApiDoc> {
}
String[] gicNameArr = DocClassUtil.getSimpleGicName(typeName);
paramList.addAll(ParamsBuildHelper.buildParams(gicNameArr[1], DocGlobalConstants.EMPTY, 0, "true", responseFieldMap, Boolean.FALSE, new HashMap<>(), builder, groupClasses));
} else if (javaClass.isEnum()) {
}
//参数列表 当为枚举时
else if (javaClass.isEnum()) {
String o = JavaClassUtil.getEnumParams(javaClass);
ApiParam param = ApiParam.of().setField(paramName)
.setType("string").setDesc(comment).setRequired(required).setVersion(DocGlobalConstants.DEFAULT_VERSION);
.setType("enum").setDesc(StringUtil.removeQuotes(o)).setRequired(required).setVersion(DocGlobalConstants.DEFAULT_VERSION);
paramList.add(param);
} else {
paramList.addAll(ParamsBuildHelper.buildParams(typeName, DocGlobalConstants.EMPTY, 0, "true", responseFieldMap, Boolean.FALSE, new HashMap<>(), builder, groupClasses));

View File

@ -31,6 +31,7 @@ import com.power.doc.model.DocJavaField;
import com.thoughtworks.qdox.model.*;
import com.thoughtworks.qdox.model.expression.AnnotationValue;
import com.thoughtworks.qdox.model.expression.AnnotationValueList;
import com.thoughtworks.qdox.model.expression.Expression;
import com.thoughtworks.qdox.model.expression.TypeRef;
import com.thoughtworks.qdox.model.impl.DefaultJavaField;
import com.thoughtworks.qdox.model.impl.DefaultJavaParameterizedType;
@ -142,12 +143,8 @@ public class JavaClassUtil {
String simpleName = javaField.getType().getSimpleName();
StringBuilder valueBuilder = new StringBuilder();
valueBuilder.append("\"").append(javaField.getName()).append("\"").toString();
if (formDataEnum) {
value = valueBuilder.toString();
return value;
}
if (!JavaClassValidateUtil.isPrimitive(simpleName) && index < 1) {
if (null != javaField.getEnumConstantArguments() && annotation > 0) {
if (null != javaField.getEnumConstantArguments()) {
value = javaField.getEnumConstantArguments().get(0);
} else {
value = valueBuilder.toString();
@ -158,6 +155,26 @@ public class JavaClassUtil {
return value;
}
public static String getEnumParams(JavaClass javaClass) {
List<JavaField> javaFields = javaClass.getEnumConstants();
StringBuilder stringBuilder = new StringBuilder();
for (JavaField javaField : javaFields) {
List<Expression> exceptions = javaField.getEnumConstantArguments();
//如果枚举值不为空
if (!CollectionUtil.isEmpty(exceptions)) {
stringBuilder.append(exceptions.get(0));
//如果枚举的参数数量大于2 只取第二个
if (exceptions.size() >= 2) {
stringBuilder.append(" : ")
.append(exceptions.get(1));
}
stringBuilder.append("<br/>");
}
}
return stringBuilder.toString();
}
/**
* Get annotation simpleName