diff --git a/CHANGELOG.md b/CHANGELOG.md
index 03749ce..474d44e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -13,6 +13,7 @@
8. 修改类中使用集合字段未指定泛型可能出错的bug。
9. 优化set等集合类在文档中的类型显示。
10. 添加对集合字段中枚举的处理。
+ 11. 枚举序列化支持优化。
#### 版本号:2.0.1
- 更新日期: 2020-12-20
- 更新内容:
diff --git a/src/main/java/com/power/doc/helper/JsonBuildHelper.java b/src/main/java/com/power/doc/helper/JsonBuildHelper.java
index c1d2e70..60f6a5b 100644
--- a/src/main/java/com/power/doc/helper/JsonBuildHelper.java
+++ b/src/main/java/com/power/doc/helper/JsonBuildHelper.java
@@ -52,7 +52,7 @@ public class JsonBuildHelper {
public static String buildReturnJson(DocJavaMethod docJavaMethod, ProjectDocConfigBuilder builder) {
JavaMethod method = docJavaMethod.getJavaMethod();
if (method.getReturns().isVoid()) {
- return "void";
+ return "Doesn't return a value.";
}
String returnTypeGenericCanonicalName = method.getReturnType().getGenericCanonicalName();
if (Objects.nonNull(builder.getApiConfig().getResponseBodyAdvice())
diff --git a/src/main/java/com/power/doc/helper/ParamsBuildHelper.java b/src/main/java/com/power/doc/helper/ParamsBuildHelper.java
index 8ebe27f..ed88eb9 100644
--- a/src/main/java/com/power/doc/helper/ParamsBuildHelper.java
+++ b/src/main/java/com/power/doc/helper/ParamsBuildHelper.java
@@ -343,12 +343,13 @@ public class ParamsBuildHelper {
if (gName.length() == 1) {
// handle generic
int len = globGicName.length;
- if (len > 0) {
- String gicName = genericMap.get(gName) != null ? genericMap.get(gName) : globGicName[0];
- if (!JavaClassValidateUtil.isPrimitive(gicName) && !simpleName.equals(gicName)) {
- paramList.addAll(buildParams(gicName, preBuilder.toString(), nextLevel, isRequired,
- responseFieldMap, isResp, registryClasses, projectBuilder, groupClasses, fieldPid));
- }
+ if (len < 1) {
+ continue out;
+ }
+ String gicName = genericMap.get(gName) != null ? genericMap.get(gName) : globGicName[0];
+ if (!JavaClassValidateUtil.isPrimitive(gicName) && !simpleName.equals(gicName)) {
+ paramList.addAll(buildParams(gicName, preBuilder.toString(), nextLevel, isRequired,
+ responseFieldMap, isResp, registryClasses, projectBuilder, groupClasses, fieldPid));
}
} else {
paramList.addAll(buildParams(gName, preBuilder.toString(), nextLevel, isRequired,
@@ -412,7 +413,7 @@ public class ParamsBuildHelper {
}
}
}
- }
+ }//end field
}
return paramList;
}
@@ -454,7 +455,7 @@ public class ParamsBuildHelper {
String enumComments = javaClass.getComment();
if (projectBuilder.getApiConfig().getInlineEnum()) {
ApiDataDictionary dataDictionary = projectBuilder.getApiConfig().getDataDictionary(javaClass.getSimpleName());
- if (dataDictionary == null) {
+ if (Objects.isNull(dataDictionary)) {
comment = comment + "
" + JavaClassUtil.getEnumParams(javaClass);
} else {
comment = comment + "[enum:" + dictionaryListComment(dataDictionary) + "]";
@@ -462,7 +463,7 @@ public class ParamsBuildHelper {
} else {
enumComments = DocUtil.replaceNewLineToHtmlBr(enumComments);
comment = comment + "
" + JavaClassUtil.getEnumParams(javaClass) + "
";
- if (enumComments != null) {
+ if (StringUtil.isNotEmpty(enumComments)) {
comment = comment + "(See: " + enumComments + ")";
}
comment = StringUtil.removeQuotes(comment);
diff --git a/src/main/java/com/power/doc/template/IDocBuildTemplate.java b/src/main/java/com/power/doc/template/IDocBuildTemplate.java
index b14eba4..04e9050 100644
--- a/src/main/java/com/power/doc/template/IDocBuildTemplate.java
+++ b/src/main/java/com/power/doc/template/IDocBuildTemplate.java
@@ -95,7 +95,7 @@ public interface IDocBuildTemplate {
default List buildReturnApiParams(DocJavaMethod docJavaMethod, ProjectDocConfigBuilder projectBuilder) {
JavaMethod method = docJavaMethod.getJavaMethod();
if (method.getReturns().isVoid()) {
- return null;
+ return new ArrayList<>(0);
}
String returnTypeGenericCanonicalName = method.getReturnType().getGenericCanonicalName();
if (Objects.nonNull(projectBuilder.getApiConfig().getResponseBodyAdvice())
@@ -117,33 +117,33 @@ public interface IDocBuildTemplate {
String typeName = apiReturn.getSimpleName();
if (this.ignoreReturnObject(typeName, projectBuilder.getApiConfig().getIgnoreRequestParams())) {
- return null;
+ return new ArrayList<>(0);
}
if (JavaClassValidateUtil.isPrimitive(typeName)) {
docJavaMethod.setReturnSchema(OpenApiSchemaUtil.primaryTypeSchema(typeName));
- return null;
+ return new ArrayList<>(0);
}
if (JavaClassValidateUtil.isCollection(typeName)) {
if (returnType.contains("<")) {
String gicName = returnType.substring(returnType.indexOf("<") + 1, returnType.lastIndexOf(">"));
if (JavaClassValidateUtil.isPrimitive(gicName)) {
docJavaMethod.setReturnSchema(OpenApiSchemaUtil.arrayTypeSchema(gicName));
- return null;
+ return new ArrayList<>(0);
}
return ParamsBuildHelper.buildParams(gicName, "", 0, null, projectBuilder.getCustomRespFieldMap(),
Boolean.TRUE, new HashMap<>(), projectBuilder, null, 0);
} else {
- return null;
+ return new ArrayList<>(0);
}
}
if (JavaClassValidateUtil.isMap(typeName)) {
String[] keyValue = DocClassUtil.getMapKeyValueType(returnType);
if (keyValue.length == 0) {
- return null;
+ return new ArrayList<>(0);
}
if (JavaClassValidateUtil.isPrimitive(keyValue[1])) {
docJavaMethod.setReturnSchema(OpenApiSchemaUtil.mapTypeSchema(keyValue[1]));
- return null;
+ return new ArrayList<>(0);
}
return ParamsBuildHelper.buildParams(keyValue[1], "", 0, null, projectBuilder.getCustomRespFieldMap(),
Boolean.TRUE, new HashMap<>(), projectBuilder, null, 0);
@@ -152,7 +152,7 @@ public interface IDocBuildTemplate {
return ParamsBuildHelper.buildParams(returnType, "", 0, null, projectBuilder.getCustomRespFieldMap(),
Boolean.TRUE, new HashMap<>(), projectBuilder, null, 0);
}
- return null;
+ return new ArrayList<>(0);
}
List getApiData(ProjectDocConfigBuilder projectBuilder);
diff --git a/src/main/java/com/power/doc/utils/ApiParamTreeUtil.java b/src/main/java/com/power/doc/utils/ApiParamTreeUtil.java
index 624cb5e..3f60251 100644
--- a/src/main/java/com/power/doc/utils/ApiParamTreeUtil.java
+++ b/src/main/java/com/power/doc/utils/ApiParamTreeUtil.java
@@ -35,12 +35,12 @@ public class ApiParamTreeUtil {
public static List apiParamToTree(List apiParamList) {
if (Objects.isNull(apiParamList)) {
- return null;
+ return new ArrayList<>(0);
}
List params = new ArrayList<>();
// find root
for (ApiParam apiParam : apiParamList) {
- //去除filed的前缀
+ // remove pre of field
apiParam.setField(apiParam.getField().replaceAll("└─", "").replaceAll(" ", ""));
// pid == 0
if (apiParam.getPid() == 0) {
@@ -48,7 +48,7 @@ public class ApiParamTreeUtil {
}
}
for (ApiParam apiParam : params) {
- //去除filed的前缀
+ // remove pre of field
apiParam.setChildren(getChild(apiParam.getId(), apiParamList));
}
return params;
@@ -72,7 +72,7 @@ public class ApiParamTreeUtil {
param.setChildren(getChild(param.getId(), apiParamList));
}
if (childList.size() == 0) {
- return null;
+ return new ArrayList<>(0);
}
return childList;
}
diff --git a/src/main/java/com/power/doc/utils/BeetlTemplateUtil.java b/src/main/java/com/power/doc/utils/BeetlTemplateUtil.java
index b104c2f..c9d0eae 100644
--- a/src/main/java/com/power/doc/utils/BeetlTemplateUtil.java
+++ b/src/main/java/com/power/doc/utils/BeetlTemplateUtil.java
@@ -32,6 +32,7 @@ import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
+import java.util.Objects;
/**
* Beetl template handle util
@@ -75,7 +76,7 @@ public class BeetlTemplateUtil {
if (f.isFile()) {
String fileName = f.getName();
Template tp = gt.getTemplate(fileName);
- if (null != params) {
+ if (Objects.nonNull(params)) {
tp.binding(params);
}
templateMap.put(fileName, tp.render());
@@ -95,7 +96,7 @@ public class BeetlTemplateUtil {
GroupTemplate gt = new GroupTemplate(resourceLoader, cfg);
return gt;
} catch (IOException e) {
- throw new RuntimeException("Can't get Beetl template.");
+ throw new RuntimeException("Can't found Beetl template.");
}
}
}
diff --git a/src/main/java/com/power/doc/utils/CurlUtil.java b/src/main/java/com/power/doc/utils/CurlUtil.java
index 44e928c..b852be0 100644
--- a/src/main/java/com/power/doc/utils/CurlUtil.java
+++ b/src/main/java/com/power/doc/utils/CurlUtil.java
@@ -1,3 +1,25 @@
+/*
+ * smart-doc
+ *
+ * Copyright (C) 2018-2021 smart-doc
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
package com.power.doc.utils;
import com.power.common.util.CollectionUtil;
diff --git a/src/main/java/com/power/doc/utils/Iterables.java b/src/main/java/com/power/doc/utils/Iterables.java
index b78b625..fc572f7 100644
--- a/src/main/java/com/power/doc/utils/Iterables.java
+++ b/src/main/java/com/power/doc/utils/Iterables.java
@@ -21,6 +21,9 @@
* under the License.
*/
+/**
+ * @author daiww 2020/08/26.
+ */
package com.power.doc.utils;
import java.util.function.BiConsumer;
@@ -28,7 +31,7 @@ import java.util.function.BiConsumer;
public class Iterables {
public static void forEach(
Iterable extends E> elements, BiConsumer action) {
- if(elements==null||action==null) return;
+ if (elements == null || action == null) return;
int index = 0;
for (E element : elements) {
action.accept(index++, element);
diff --git a/src/main/java/com/power/doc/utils/JavaClassUtil.java b/src/main/java/com/power/doc/utils/JavaClassUtil.java
index 8572b58..3a5005f 100644
--- a/src/main/java/com/power/doc/utils/JavaClassUtil.java
+++ b/src/main/java/com/power/doc/utils/JavaClassUtil.java
@@ -57,12 +57,12 @@ public class JavaClassUtil {
*/
public static List getFields(JavaClass cls1, int counter, Set addedFields) {
List fieldList = new ArrayList<>();
- if (null == cls1) {
+ if (Objects.isNull(cls1)) {
return fieldList;
} else if ("Object".equals(cls1.getSimpleName()) || "Timestamp".equals(cls1.getSimpleName()) ||
"Date".equals(cls1.getSimpleName()) || "Locale".equals(cls1.getSimpleName())
|| "ClassLoader".equals(cls1.getSimpleName()) || JavaClassValidateUtil.isMap(cls1.getFullyQualifiedName())
- || cls1.isEnum()) {
+ || cls1.isEnum() || "Serializable".equals(cls1.getSimpleName())) {
return fieldList;
} else {
String className = cls1.getFullyQualifiedName();
@@ -285,7 +285,7 @@ public class JavaClassUtil {
* @return JavaClass
*/
public static List getActualTypes(JavaType javaType) {
- if (null == javaType) {
+ if (Objects.isNull(javaType)) {
return new ArrayList<>(0);
}
String typeName = javaType.getGenericFullyQualifiedName();
@@ -454,7 +454,7 @@ public class JavaClassUtil {
}
public static void genericParamMap(Map genericMap, JavaClass cls, String[] globGicName) {
- if (cls != null && null != cls.getTypeParameters()) {
+ if (Objects.nonNull(cls) && Objects.nonNull(cls.getTypeParameters())) {
List> variables = cls.getTypeParameters();
for (int i = 0; i < cls.getTypeParameters().size() && i < globGicName.length; i++) {
genericMap.put(variables.get(i).getName(), globGicName[i]);