From 915f425a31b112b2c26d1a1bda42e541e86e6825 Mon Sep 17 00:00:00 2001
From: oppofind <836575280@qq.com>
Date: Sun, 11 Apr 2021 12:31:11 +0800
Subject: [PATCH] fix set enum default value error
---
CHANGELOG.md | 4 +-
pom.xml | 2 +-
.../power/doc/helper/ParamsBuildHelper.java | 50 +++++++++----------
.../power/doc/template/IDocBuildTemplate.java | 6 +--
.../doc/template/RpcDocBuildTemplate.java | 9 ++--
.../template/SpringBootDocBuildTemplate.java | 9 ++--
src/main/resources/template/js/debug.js | 3 +-
7 files changed, 46 insertions(+), 37 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a4c0e1f4..74232b3e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,11 +1,13 @@
## smart-doc版本
版本小于1.0都属于试用,正式1.0起始发布将会等到文中提到的问题解决后才发布。
#### 版本号:2.1.3
-- 更新日期: 2020-04-09
+- 更新日期: 2020-04-11
- 更新内容:
1. 增强对文件上传的支持。
2. 增加customRequestFields配置项,#97。
3. 修复往torna推送漏掉pathParams的问题。
+ 4. 修改debug测试页面,支持post表单请求
+ 5. 修改表单请求对象中枚举字段默认值错误的bug
#### 版本号:2.1.2
- 更新日期: 2020-03-29
- 更新内容:
diff --git a/pom.xml b/pom.xml
index 96cdde7e..8e464e89 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
4.0.0
smart-doc
jar
- 2.1.2
+ 2.1.3
smart-doc
https://github.com/smart-doc-group/smart-doc.git
diff --git a/src/main/java/com/power/doc/helper/ParamsBuildHelper.java b/src/main/java/com/power/doc/helper/ParamsBuildHelper.java
index 5b082e7c..3a80b5fa 100644
--- a/src/main/java/com/power/doc/helper/ParamsBuildHelper.java
+++ b/src/main/java/com/power/doc/helper/ParamsBuildHelper.java
@@ -54,7 +54,7 @@ public class ParamsBuildHelper {
public static List buildParams(String className, String pre, int level, String isRequired,
Map responseFieldMap, boolean isResp,
Map registryClasses, ProjectDocConfigBuilder projectBuilder,
- List groupClasses, int pid) {
+ List groupClasses, int pid, boolean jsonRequest) {
String maxLength = null;
//存储泛型所对应的实体类
Map genericMap = new HashMap<>(10);
@@ -95,12 +95,12 @@ public static List buildParams(String className, String pre, int level
gicName = gicName.substring(0, gicName.indexOf("["));
}
paramList.addAll(buildParams(gicName, pre, nextLevel, isRequired, responseFieldMap, isResp,
- registryClasses, projectBuilder, groupClasses, pid));
+ registryClasses, projectBuilder, groupClasses, pid, jsonRequest));
}
} else if (JavaClassValidateUtil.isMap(simpleName)) {
if (globGicName.length == 2) {
paramList.addAll(buildParams(globGicName[1], pre, nextLevel, isRequired, responseFieldMap, isResp,
- registryClasses, projectBuilder, groupClasses, pid));
+ registryClasses, projectBuilder, groupClasses, pid, jsonRequest));
}
} else if (DocGlobalConstants.JAVA_OBJECT_FULLY.equals(className)) {
ApiParam param = ApiParam.of().setField(pre + "any object").setType("object").setPid(pid);
@@ -112,8 +112,8 @@ public static List buildParams(String className, String pre, int level
paramList.add(param);
} else if (JavaClassValidateUtil.isReactor(simpleName)) {
paramList.addAll(buildParams(globGicName[0], pre, nextLevel, isRequired, responseFieldMap, isResp,
- registryClasses, projectBuilder, groupClasses, pid));
- }else {
+ registryClasses, projectBuilder, groupClasses, pid, jsonRequest));
+ } else {
out:
for (DocJavaField docField : fields) {
JavaField field = docField.getJavaField();
@@ -151,11 +151,11 @@ public static List buildParams(String className, String pre, int level
boolean strRequired = false;
int annotationCounter = 0;
CustomField customResponseField = responseFieldMap.get(fieldName);
- if(customResponseField !=null && simpleName.equals(customResponseField.getOwnerClassName()) && (customResponseField.isIgnore()) && isResp){
+ if (customResponseField != null && simpleName.equals(customResponseField.getOwnerClassName()) && (customResponseField.isIgnore()) && isResp) {
continue;
}
CustomField customRequestField = projectBuilder.getCustomReqFieldMap().get(fieldName);
- if(customRequestField !=null && simpleName.equals(customRequestField.getOwnerClassName()) && (customRequestField.isIgnore()) && !isResp){
+ if (customRequestField != null && simpleName.equals(customRequestField.getOwnerClassName()) && (customRequestField.isIgnore()) && !isResp) {
continue;
}
an:
@@ -211,8 +211,8 @@ public static List buildParams(String className, String pre, int level
}
}
//cover required
- if(customRequestField !=null && !isResp && simpleName.equals(customRequestField.getOwnerClassName())
- && customRequestField.isRequire()){
+ if (customRequestField != null && !isResp && simpleName.equals(customRequestField.getOwnerClassName())
+ && customRequestField.isRequire()) {
strRequired = true;
}
//cover comment
@@ -222,11 +222,11 @@ public static List buildParams(String className, String pre, int level
comment = customRequestField.getDesc();
}
if (null != customResponseField && StringUtil.isNotEmpty(customResponseField.getDesc())
- && simpleName.equals(customResponseField.getOwnerClassName())&& isResp) {
+ && simpleName.equals(customResponseField.getOwnerClassName()) && isResp) {
comment = customResponseField.getDesc();
}
- if(StringUtils.isBlank(comment)){
- comment = docField.getComment();
+ if (StringUtils.isBlank(comment)) {
+ comment = docField.getComment();
}
if (StringUtil.isNotEmpty(comment)) {
comment = DocUtil.replaceNewLineToHtmlBr(comment);
@@ -315,7 +315,7 @@ public static List buildParams(String className, String pre, int level
}
index++;
}
- Object value = JavaClassUtil.getEnumValue(javaClass, Boolean.FALSE);
+ Object value = JavaClassUtil.getEnumValue(javaClass,!jsonRequest);
param.setValue(String.valueOf(value));
param.setEnumValues(JavaClassUtil.getEnumValues(javaClass));
param.setType(DocGlobalConstants.ENUM);
@@ -333,7 +333,7 @@ public static List buildParams(String className, String pre, int level
int fieldPid = paramList.size() + pid;
if (JavaClassValidateUtil.isMap(subTypeName)) {
String gNameTemp = fieldGicName;
- String valType = DocClassUtil.getMapKeyValueType(gNameTemp).length==0?gNameTemp:DocClassUtil.getMapKeyValueType(gNameTemp)[1];
+ String valType = DocClassUtil.getMapKeyValueType(gNameTemp).length == 0 ? gNameTemp : DocClassUtil.getMapKeyValueType(gNameTemp)[1];
if (JavaClassValidateUtil.isMap(gNameTemp) || JAVA_OBJECT_FULLY.equals(valType)) {
ApiParam param1 = ApiParam.of().setField(preBuilder.toString() + "any object")
.setId(fieldPid + 1).setPid(fieldPid)
@@ -347,11 +347,11 @@ public static List buildParams(String className, String pre, int level
String gicName = genericMap.get(valType);
if (!JavaClassValidateUtil.isPrimitive(gicName) && !simpleName.equals(gicName)) {
paramList.addAll(buildParams(gicName, preBuilder.toString(), nextLevel, isRequired,
- responseFieldMap, isResp, registryClasses, projectBuilder, groupClasses, fieldPid));
+ responseFieldMap, isResp, registryClasses, projectBuilder, groupClasses, fieldPid, jsonRequest));
}
} else {
paramList.addAll(buildParams(valType, preBuilder.toString(), nextLevel, isRequired,
- responseFieldMap, isResp, registryClasses, projectBuilder, groupClasses, fieldPid));
+ responseFieldMap, isResp, registryClasses, projectBuilder, groupClasses, fieldPid, jsonRequest));
}
}
} else if (JavaClassValidateUtil.isCollection(subTypeName)) {
@@ -375,11 +375,11 @@ public static List buildParams(String className, String pre, int level
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));
+ responseFieldMap, isResp, registryClasses, projectBuilder, groupClasses, fieldPid, jsonRequest));
}
} else {
paramList.addAll(buildParams(gName, preBuilder.toString(), nextLevel, isRequired,
- responseFieldMap, isResp, registryClasses, projectBuilder, groupClasses, fieldPid));
+ responseFieldMap, isResp, registryClasses, projectBuilder, groupClasses, fieldPid, jsonRequest));
}
}
} else {
@@ -409,25 +409,25 @@ public static List buildParams(String className, String pre, int level
String gName = DocClassUtil.getSimpleGicName(gicName)[0];
if (!JavaClassValidateUtil.isPrimitive(gName)) {
paramList.addAll(buildParams(gName, preBuilder.toString(), nextLevel, isRequired,
- responseFieldMap, isResp, registryClasses, projectBuilder, groupClasses, fieldPid));
+ responseFieldMap, isResp, registryClasses, projectBuilder, groupClasses, fieldPid, jsonRequest));
}
} else if (JavaClassValidateUtil.isMap(simple)) {
String valType = DocClassUtil.getMapKeyValueType(gicName)[1];
if (!JavaClassValidateUtil.isPrimitive(valType)) {
paramList.addAll(buildParams(valType, preBuilder.toString(), nextLevel, isRequired,
- responseFieldMap, isResp, registryClasses, projectBuilder, groupClasses, fieldPid));
+ responseFieldMap, isResp, registryClasses, projectBuilder, groupClasses, fieldPid, jsonRequest));
}
} else {
paramList.addAll(buildParams(gicName, preBuilder.toString(), nextLevel, isRequired,
- responseFieldMap, isResp, registryClasses, projectBuilder, groupClasses, fieldPid));
+ responseFieldMap, isResp, registryClasses, projectBuilder, groupClasses, fieldPid, jsonRequest));
}
} else {
paramList.addAll(buildParams(gicName, preBuilder.toString(), nextLevel, isRequired,
- responseFieldMap, isResp, registryClasses, projectBuilder, groupClasses, fieldPid));
+ responseFieldMap, isResp, registryClasses, projectBuilder, groupClasses, fieldPid, jsonRequest));
}
} else {
paramList.addAll(buildParams(subTypeName, preBuilder.toString(), nextLevel, isRequired,
- responseFieldMap, isResp, registryClasses, projectBuilder, groupClasses, fieldPid));
+ responseFieldMap, isResp, registryClasses, projectBuilder, groupClasses, fieldPid, jsonRequest));
}
}
} else if (JavaClassValidateUtil.isArray(subTypeName)) {
@@ -436,14 +436,14 @@ public static List buildParams(String className, String pre, int level
//do nothing
} else if (!JavaClassValidateUtil.isPrimitive(fieldGicName)) {
paramList.addAll(buildParams(fieldGicName, preBuilder.toString(), nextLevel, isRequired,
- responseFieldMap, isResp, registryClasses, projectBuilder, groupClasses, fieldPid));
+ responseFieldMap, isResp, registryClasses, projectBuilder, groupClasses, fieldPid, jsonRequest));
}
} else if (simpleName.equals(subTypeName)) {
//do nothing
} else {
if (!javaClass.isEnum()) {
paramList.addAll(buildParams(fieldGicName, preBuilder.toString(), nextLevel, isRequired,
- responseFieldMap, isResp, registryClasses, projectBuilder, groupClasses, fieldPid));
+ responseFieldMap, isResp, registryClasses, projectBuilder, groupClasses, fieldPid, jsonRequest));
}
}
}
diff --git a/src/main/java/com/power/doc/template/IDocBuildTemplate.java b/src/main/java/com/power/doc/template/IDocBuildTemplate.java
index 9bd64d58..fc7b1e41 100644
--- a/src/main/java/com/power/doc/template/IDocBuildTemplate.java
+++ b/src/main/java/com/power/doc/template/IDocBuildTemplate.java
@@ -133,7 +133,7 @@ default List buildReturnApiParams(DocJavaMethod docJavaMethod, Project
return new ArrayList<>(0);
}
return ParamsBuildHelper.buildParams(gicName, "", 0, null, projectBuilder.getCustomRespFieldMap(),
- Boolean.TRUE, new HashMap<>(), projectBuilder, null, 0);
+ Boolean.TRUE, new HashMap<>(), projectBuilder, null, 0, Boolean.FALSE);
} else {
return new ArrayList<>(0);
}
@@ -148,11 +148,11 @@ default List buildReturnApiParams(DocJavaMethod docJavaMethod, Project
return new ArrayList<>(0);
}
return ParamsBuildHelper.buildParams(keyValue[1], "", 0, null, projectBuilder.getCustomRespFieldMap(),
- Boolean.TRUE, new HashMap<>(), projectBuilder, null, 0);
+ Boolean.TRUE, new HashMap<>(), projectBuilder, null, 0, Boolean.FALSE);
}
if (StringUtil.isNotEmpty(returnType)) {
return ParamsBuildHelper.buildParams(returnType, "", 0, null, projectBuilder.getCustomRespFieldMap(),
- Boolean.TRUE, new HashMap<>(), projectBuilder, null, 0);
+ Boolean.TRUE, new HashMap<>(), projectBuilder, null, 0, Boolean.FALSE);
}
return new ArrayList<>(0);
}
diff --git a/src/main/java/com/power/doc/template/RpcDocBuildTemplate.java b/src/main/java/com/power/doc/template/RpcDocBuildTemplate.java
index 3b2fa9a2..b5ca7926 100644
--- a/src/main/java/com/power/doc/template/RpcDocBuildTemplate.java
+++ b/src/main/java/com/power/doc/template/RpcDocBuildTemplate.java
@@ -202,7 +202,8 @@ private List requestParams(final JavaMethod javaMethod, ProjectDocConf
.setType(processedType);
paramList.add(param);
} else {
- paramList.addAll(ParamsBuildHelper.buildParams(gicNameArr[0], paramPre, 0, "true", responseFieldMap, Boolean.FALSE, new HashMap<>(), builder, groupClasses, 0));
+ paramList.addAll(ParamsBuildHelper.buildParams(gicNameArr[0], paramPre, 0, "true",
+ responseFieldMap, Boolean.FALSE, new HashMap<>(), builder, groupClasses, 0, Boolean.FALSE));
}
} else if (JavaClassValidateUtil.isPrimitive(fullTypeName)) {
ApiParam param = ApiParam.of().setField(paramName)
@@ -217,13 +218,15 @@ private List requestParams(final JavaMethod javaMethod, ProjectDocConf
continue;
}
String[] gicNameArr = DocClassUtil.getSimpleGicName(typeName);
- paramList.addAll(ParamsBuildHelper.buildParams(gicNameArr[1], paramPre, 0, "true", responseFieldMap, Boolean.FALSE, new HashMap<>(), builder, groupClasses, 0));
+ paramList.addAll(ParamsBuildHelper.buildParams(gicNameArr[1], paramPre, 0, "true",
+ responseFieldMap, Boolean.FALSE, new HashMap<>(), builder, groupClasses, 0, Boolean.FALSE));
} else if (javaClass.isEnum()) {
ApiParam param = ApiParam.of().setField(paramName)
.setType("Enum").setDesc(comment).setRequired(true).setVersion(DocGlobalConstants.DEFAULT_VERSION);
paramList.add(param);
} else {
- paramList.addAll(ParamsBuildHelper.buildParams(typeName, paramPre, 0, "true", responseFieldMap, Boolean.FALSE, new HashMap<>(), builder, groupClasses, 0));
+ paramList.addAll(ParamsBuildHelper.buildParams(typeName, paramPre, 0, "true",
+ responseFieldMap, Boolean.FALSE, new HashMap<>(), builder, groupClasses, 0, Boolean.FALSE));
}
}
return paramList;
diff --git a/src/main/java/com/power/doc/template/SpringBootDocBuildTemplate.java b/src/main/java/com/power/doc/template/SpringBootDocBuildTemplate.java
index 0ae372a9..1c82ffd7 100644
--- a/src/main/java/com/power/doc/template/SpringBootDocBuildTemplate.java
+++ b/src/main/java/com/power/doc/template/SpringBootDocBuildTemplate.java
@@ -684,7 +684,8 @@ private ApiMethodReqParam requestParams(final DocJavaMethod docJavaMethod, Proje
if (requestBodyCounter > 0) {
//for json
paramList.addAll(ParamsBuildHelper.buildParams(gicNameArr[0], DocGlobalConstants.EMPTY, 0,
- "true", responseFieldMap, Boolean.FALSE, new HashMap<>(), builder, groupClasses, 0));
+ "true", responseFieldMap, Boolean.FALSE, new HashMap<>(), builder,
+ groupClasses, 0, Boolean.TRUE));
} else {
throw new RuntimeException("Spring MVC can't support binding Collection on method "
+ javaMethod.getName() + ",Check it in " + javaMethod.getDeclaringClass().getCanonicalName());
@@ -733,7 +734,8 @@ private ApiMethodReqParam requestParams(final DocJavaMethod docJavaMethod, Proje
}
} else {
paramList.addAll(ParamsBuildHelper.buildParams(gicNameArr[1], DocGlobalConstants.EMPTY, 0,
- "true", responseFieldMap, Boolean.FALSE, new HashMap<>(), builder, groupClasses, 0));
+ "true", responseFieldMap, Boolean.FALSE, new HashMap<>(),
+ builder, groupClasses, 0, Boolean.FALSE));
}
}
@@ -752,7 +754,8 @@ else if (javaClass.isEnum()) {
.setEnumValues(JavaClassUtil.getEnumValues(javaClass));
paramList.add(param);
} else {
- paramList.addAll(ParamsBuildHelper.buildParams(typeName, DocGlobalConstants.EMPTY, 0, "true", responseFieldMap, Boolean.FALSE, new HashMap<>(), builder, groupClasses, 0));
+ paramList.addAll(ParamsBuildHelper.buildParams(typeName, DocGlobalConstants.EMPTY, 0,
+ "true", responseFieldMap, Boolean.FALSE, new HashMap<>(), builder, groupClasses, 0, Boolean.FALSE));
}
}
List pathParams = new ArrayList<>();
diff --git a/src/main/resources/template/js/debug.js b/src/main/resources/template/js/debug.js
index 574a423f..2541df75 100644
--- a/src/main/resources/template/js/debug.js
+++ b/src/main/resources/template/js/debug.js
@@ -84,7 +84,8 @@ $("button").on("click", function () {
body = queryParamData;
ajaxOptions.processData = false;
ajaxOptions.contentType = false;
- } else if ("POST" == method && contentType !== "multipart/form-data") {
+ } else if ("POST" == method && contentType !== "multipart/form-data"
+ && contentType !== "application/json; charset=utf-8") {
finalUrl = castToGetUri(url, pathParamData);
queryParamData = getInputData($queryElement)
body = queryParamData;