fix gitee #I3R9P2 .

This commit is contained in:
shalousun 2021-05-15 21:46:49 +08:00
parent 9e419fbac9
commit 40be476c48
3 changed files with 40 additions and 16 deletions

View File

@ -1,4 +1,9 @@
## smart-doc版本
#### 版本号2.1.8
- 更新日期: 2020-05-17
- 更新内容:
1. 修复推送接口到torna丢失部分mock值的问题。
2. 修复在参数注释中配置类替换时将非类名解析成类名的bug 。
#### 版本号2.1.7
- 更新日期: 2020-05-12
- 更新内容:

View File

@ -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) +
"]";
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

View File

@ -848,11 +848,12 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate<ApiDoc> {
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 replacementMap.get(fullTypeName);
}
private String createMockValue(Map<String, String> paramsComments, String paramName, String typeName, String simpleTypeName) {
String mockValue = "";