fix set enum default value error
This commit is contained in:
parent
608651e657
commit
915f425a31
|
@ -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
|
||||
- 更新内容:
|
||||
|
|
2
pom.xml
2
pom.xml
|
@ -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>
|
||||
|
|
|
@ -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);
|
||||
|
@ -95,12 +95,12 @@ public class ParamsBuildHelper {
|
|||
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 class ParamsBuildHelper {
|
|||
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 class ParamsBuildHelper {
|
|||
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 class ParamsBuildHelper {
|
|||
}
|
||||
}
|
||||
//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 class ParamsBuildHelper {
|
|||
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 class ParamsBuildHelper {
|
|||
}
|
||||
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 class ParamsBuildHelper {
|
|||
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 class ParamsBuildHelper {
|
|||
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 class ParamsBuildHelper {
|
|||
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 class ParamsBuildHelper {
|
|||
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 class ParamsBuildHelper {
|
|||
//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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -133,7 +133,7 @@ public interface IDocBuildTemplate<T> {
|
|||
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 @@ public interface IDocBuildTemplate<T> {
|
|||
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);
|
||||
}
|
||||
|
|
|
@ -202,7 +202,8 @@ public class RpcDocBuildTemplate implements IDocBuildTemplate<RpcApiDoc> {
|
|||
.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 @@ public class RpcDocBuildTemplate implements IDocBuildTemplate<RpcApiDoc> {
|
|||
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;
|
||||
|
|
|
@ -684,7 +684,8 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate<ApiDoc> {
|
|||
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 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate<ApiDoc> {
|
|||
}
|
||||
} 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 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate<ApiDoc> {
|
|||
.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<>();
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue