From 40be476c486d29d996aa3d4e0832344cd911d4ff Mon Sep 17 00:00:00 2001 From: shalousun Date: Sat, 15 May 2021 21:46:49 +0800 Subject: [PATCH] fix gitee #I3R9P2 . --- CHANGELOG.md | 5 +++ .../power/doc/helper/ParamsBuildHelper.java | 44 +++++++++++++------ .../template/SpringBootDocBuildTemplate.java | 7 +-- 3 files changed, 40 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b4c16a3..83d58eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,9 @@ ## smart-doc版本 +#### 版本号:2.1.8 +- 更新日期: 2020-05-17 +- 更新内容: + 1. 修复推送接口到torna丢失部分mock值的问题。 + 2. 修复在参数注释中配置类替换时将非类名解析成类名的bug 。 #### 版本号:2.1.7 - 更新日期: 2020-05-12 - 更新内容: diff --git a/src/main/java/com/power/doc/helper/ParamsBuildHelper.java b/src/main/java/com/power/doc/helper/ParamsBuildHelper.java index 7f66920..889049e 100644 --- a/src/main/java/com/power/doc/helper/ParamsBuildHelper.java +++ b/src/main/java/com/power/doc/helper/ParamsBuildHelper.java @@ -151,17 +151,17 @@ public class ParamsBuildHelper { boolean strRequired = false; int annotationCounter = 0; CustomField customResponseField = responseFieldMap.get(fieldName); - if (customResponseField != null && JavaClassUtil.isTargetChildClass(simpleName,customResponseField.getOwnerClassName()) && (customResponseField.isIgnore()) && isResp) { + if (customResponseField != null && JavaClassUtil.isTargetChildClass(simpleName, customResponseField.getOwnerClassName()) && (customResponseField.isIgnore()) && isResp) { continue; } CustomField customRequestField = projectBuilder.getCustomReqFieldMap().get(fieldName); - if (customRequestField != null && JavaClassUtil.isTargetChildClass(simpleName,customRequestField.getOwnerClassName())&& (customRequestField.isIgnore()) && !isResp) { + if (customRequestField != null && JavaClassUtil.isTargetChildClass(simpleName, customRequestField.getOwnerClassName()) && (customRequestField.isIgnore()) && !isResp) { continue; } an: for (JavaAnnotation annotation : javaAnnotations) { String simpleAnnotationName = annotation.getType().getValue(); - if ("max".equals(simpleAnnotationName.toLowerCase())) { + if ("max".equalsIgnoreCase(simpleAnnotationName)) { maxLength = annotation.getProperty(DocAnnotationConstants.VALUE_PROP).toString(); } if (DocAnnotationConstants.SHORT_JSON_IGNORE.equals(simpleAnnotationName)) { @@ -203,6 +203,16 @@ public class ParamsBuildHelper { break an; } } + String fieldValue = ""; + if (tagsMap.containsKey(DocTags.MOCK) && StringUtil.isNotEmpty(tagsMap.get(DocTags.MOCK))) { + fieldValue = tagsMap.get(DocTags.MOCK); + if (!DocUtil.javaPrimaryType(typeSimpleName) + && !JavaClassValidateUtil.isCollection(subTypeName) + && !JavaClassValidateUtil.isMap(subTypeName) + && !JavaClassValidateUtil.isArray(subTypeName)) { + fieldValue = DocUtil.handleJsonStr(fieldValue); + } + } if (annotationCounter < 1) { doc: if (tagsMap.containsKey(DocTags.REQUIRED)) { @@ -211,18 +221,18 @@ public class ParamsBuildHelper { } } //cover required - if (customRequestField != null && !isResp && JavaClassUtil.isTargetChildClass(simpleName,customRequestField.getOwnerClassName()) + if (customRequestField != null && !isResp && JavaClassUtil.isTargetChildClass(simpleName, customRequestField.getOwnerClassName()) && customRequestField.isRequire()) { strRequired = true; } //cover comment String comment = ""; if (null != customRequestField && StringUtil.isNotEmpty(customRequestField.getDesc()) - && JavaClassUtil.isTargetChildClass(simpleName,customRequestField.getOwnerClassName()) && !isResp) { + && JavaClassUtil.isTargetChildClass(simpleName, customRequestField.getOwnerClassName()) && !isResp) { comment = customRequestField.getDesc(); } if (null != customResponseField && StringUtil.isNotEmpty(customResponseField.getDesc()) - && JavaClassUtil.isTargetChildClass(simpleName,customResponseField.getOwnerClassName()) && isResp) { + && JavaClassUtil.isTargetChildClass(simpleName, customResponseField.getOwnerClassName()) && isResp) { comment = customResponseField.getDesc(); } if (StringUtils.isBlank(comment)) { @@ -241,10 +251,7 @@ public class ParamsBuildHelper { continue; } if (JavaClassValidateUtil.isPrimitive(subTypeName)) { - String fieldValue = ""; - if (tagsMap.containsKey(DocTags.MOCK) && StringUtil.isNotEmpty(tagsMap.get(DocTags.MOCK))) { - fieldValue = tagsMap.get(DocTags.MOCK); - } else { + if (StringUtil.isEmpty(fieldValue)) { fieldValue = DocUtil.getValByTypeAndFieldName(typeSimpleName, field.getName()); } ApiParam param = ApiParam.of().setField(pre + fieldName); @@ -315,7 +322,7 @@ public class ParamsBuildHelper { } index++; } - Object value = JavaClassUtil.getEnumValue(javaClass,!jsonRequest); + Object value = JavaClassUtil.getEnumValue(javaClass, !jsonRequest); param.setValue(String.valueOf(value)); param.setEnumValues(JavaClassUtil.getEnumValues(javaClass)); param.setType(DocGlobalConstants.ENUM); @@ -364,9 +371,16 @@ public class ParamsBuildHelper { continue out; } String gName = DocClassUtil.getSimpleGicName(gNameTemp)[0]; + if (!JavaClassValidateUtil.isPrimitive(gName)) { if (!simpleName.equals(gName) && !gName.equals(simpleName)) { - if (gName.length() == 1) { + JavaClass arraySubClass = projectBuilder.getJavaProjectBuilder().getClassByName(gName); + if (arraySubClass.isEnum()) { + Object value = JavaClassUtil.getEnumValue(arraySubClass, Boolean.FALSE); + StringBuilder sb = new StringBuilder(); + sb.append("[\"").append(value).append("\"]"); + param.setValue(sb.toString()); + } else if (gName.length() == 1) { // handle generic int len = globGicName.length; if (len < 1) { @@ -388,7 +402,11 @@ public class ParamsBuildHelper { "," + DocUtil.jsonValueByType(gName) + "]"; - param.setValue(DocUtil.handleJsonStr(builder)); + if (StringUtil.isEmpty(fieldValue)) { + param.setValue(DocUtil.handleJsonStr(builder)); + } else { + param.setValue(fieldValue); + } } } else if (subTypeName.length() == 1 || DocGlobalConstants.JAVA_OBJECT_FULLY.equals(subTypeName)) { // handle java generic or object diff --git a/src/main/java/com/power/doc/template/SpringBootDocBuildTemplate.java b/src/main/java/com/power/doc/template/SpringBootDocBuildTemplate.java index a29c9ce..37e505e 100644 --- a/src/main/java/com/power/doc/template/SpringBootDocBuildTemplate.java +++ b/src/main/java/com/power/doc/template/SpringBootDocBuildTemplate.java @@ -848,10 +848,11 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate { if (Objects.nonNull(commentClass) && !DocGlobalConstants.NO_COMMENTS_FOUND.equals(commentClass)) { String[] comments = commentClass.split("\\|"); rewriteClassName = comments[comments.length - 1]; - } else { - rewriteClassName = replacementMap.get(fullTypeName); + if (DocUtil.isClassName(rewriteClassName)) { + return rewriteClassName; + } } - return rewriteClassName; + return replacementMap.get(fullTypeName); } private String createMockValue(Map paramsComments, String paramName, String typeName, String simpleTypeName) {