Skip to content

Commit

Permalink
fix set enum default value error
Browse files Browse the repository at this point in the history
  • Loading branch information
shalousun committed Apr 11, 2021
1 parent 608651e commit 915f425
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 37 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
- 更新内容:
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>smart-doc</artifactId>
<packaging>jar</packaging>
<version>2.1.2</version>
<version>2.1.3</version>

<name>smart-doc</name>
<url>https://github.com/smart-doc-group/smart-doc.git</url>
Expand Down
50 changes: 25 additions & 25 deletions src/main/java/com/power/doc/helper/ParamsBuildHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class ParamsBuildHelper {
public static List<ApiParam> buildParams(String className, String pre, int level, String isRequired,
Map<String, CustomField> responseFieldMap, boolean isResp,
Map<String, String> registryClasses, ProjectDocConfigBuilder projectBuilder,
List<String> groupClasses, int pid) {
List<String> groupClasses, int pid, boolean jsonRequest) {
String maxLength = null;
//存储泛型所对应的实体类
Map<String, String> genericMap = new HashMap<>(10);
Expand Down Expand Up @@ -95,12 +95,12 @@ public static List<ApiParam> 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);
Expand All @@ -112,8 +112,8 @@ public static List<ApiParam> 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();
Expand Down Expand Up @@ -151,11 +151,11 @@ public static List<ApiParam> 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:
Expand Down Expand Up @@ -211,8 +211,8 @@ public static List<ApiParam> 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
Expand All @@ -222,11 +222,11 @@ public static List<ApiParam> 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);
Expand Down Expand Up @@ -315,7 +315,7 @@ public static List<ApiParam> 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);
Expand All @@ -333,7 +333,7 @@ public static List<ApiParam> 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)
Expand All @@ -347,11 +347,11 @@ public static List<ApiParam> 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)) {
Expand All @@ -375,11 +375,11 @@ public static List<ApiParam> 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 {
Expand Down Expand Up @@ -409,25 +409,25 @@ public static List<ApiParam> 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)) {
Expand All @@ -436,14 +436,14 @@ public static List<ApiParam> 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));
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/power/doc/template/IDocBuildTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ default List<ApiParam> 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);
}
Expand All @@ -148,11 +148,11 @@ default List<ApiParam> 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);
}
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/com/power/doc/template/RpcDocBuildTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ private List<ApiParam> 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)
Expand All @@ -217,13 +218,15 @@ private List<ApiParam> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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));
}

}
Expand All @@ -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<ApiParam> pathParams = new ArrayList<>();
Expand Down
Loading

0 comments on commit 915f425

Please sign in to comment.