diff --git a/src/main/java/com/power/doc/template/SpringBootDocBuildTemplate.java b/src/main/java/com/power/doc/template/SpringBootDocBuildTemplate.java index 04cda26..88d4c74 100644 --- a/src/main/java/com/power/doc/template/SpringBootDocBuildTemplate.java +++ b/src/main/java/com/power/doc/template/SpringBootDocBuildTemplate.java @@ -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 { } 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)); diff --git a/src/main/java/com/power/doc/utils/JavaClassUtil.java b/src/main/java/com/power/doc/utils/JavaClassUtil.java index 200288c..5dc6352 100644 --- a/src/main/java/com/power/doc/utils/JavaClassUtil.java +++ b/src/main/java/com/power/doc/utils/JavaClassUtil.java @@ -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 javaFields = javaClass.getEnumConstants(); + StringBuilder stringBuilder = new StringBuilder(); + for (JavaField javaField : javaFields) { + List 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("
"); + } + } + return stringBuilder.toString(); + } + /** * Get annotation simpleName