修复rpc泛型嵌套参数显示不正确的问题

This commit is contained in:
xingzi 2020-07-29 23:22:09 +08:00
parent c1908d1329
commit 068904f304
3 changed files with 20 additions and 14 deletions

View File

@ -237,7 +237,12 @@ public class ParamsBuildHelper {
}
//如果已经设置返回类型 不需要再次设置
if (param.getType() == null) {
String processedType = isShowJavaType ? typeSimpleName : DocClassUtil.processTypeNameForParams(typeSimpleName.toLowerCase());
String processedType;
if (typeSimpleName.length() == 1) {
processedType = DocClassUtil.processTypeNameForParams(typeSimpleName.toLowerCase());
} else {
processedType = isShowJavaType ? typeSimpleName : DocClassUtil.processTypeNameForParams(typeSimpleName.toLowerCase());
}
param.setType(processedType);
}
if (!isResp && javaClass.isEnum()) {
@ -304,7 +309,7 @@ public class ParamsBuildHelper {
if (gName.length() == 1) {
int len = globGicName.length;
if (len > 0) {
String gicName = genericMap.get(gName);
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));
}

View File

@ -97,13 +97,14 @@ public class RpcDocBuildTemplate implements IDocBuildTemplate<RpcApiDoc> {
throw new RuntimeException("Unable to find comment for method " + method.getName() + " in " + cls.getCanonicalName());
}
boolean deprecated = false;
List<JavaAnnotation> annotations = method.getAnnotations();
for (JavaAnnotation annotation : annotations) {
String annotationName = annotation.getType().getName();
if (DocAnnotationConstants.DEPRECATED.equals(annotationName)) {
deprecated = true;
}
}
//RPC没有注解
// List<JavaAnnotation> annotations = method.getAnnotations();
// for (JavaAnnotation annotation : annotations) {
// String annotationName = annotation.getType().getName();
// if (DocAnnotationConstants.DEPRECATED.equals(annotationName)) {
// deprecated = true;
// }
// }
methodOrder++;
JavaMethodDoc apiMethodDoc = new JavaMethodDoc();
String methodDefine = methodDefinition(method);
@ -184,7 +185,7 @@ public class RpcDocBuildTemplate implements IDocBuildTemplate<RpcApiDoc> {
} else {
paramList.addAll(ParamsBuildHelper.buildParams(gicNameArr[0], paramPre, 0, "true", responseFieldMap, Boolean.FALSE, new HashMap<>(), builder, groupClasses));
}
} else if (JavaClassValidateUtil.isPrimitive(simpleName)) {
} else if (JavaClassValidateUtil.isPrimitive(fullTypeName)) {
ApiParam param = ApiParam.of().setField(paramName)
.setType(JavaClassUtil.getClassSimpleName(typeName))
.setDesc(comment).setRequired(required).setVersion(DocGlobalConstants.DEFAULT_VERSION);
@ -274,7 +275,10 @@ public class RpcDocBuildTemplate implements IDocBuildTemplate<RpcApiDoc> {
if(str.contains("[")){
str = str.substring(0,str.indexOf("["));
}
returnClass = returnClass.replaceAll(str, JavaClassUtil.getClassSimpleName(str));
String[] generics = str.split("<");
for (String generic : generics) {
returnClass = returnClass.replaceAll(generic, JavaClassUtil.getClassSimpleName(generic));
}
}
methodBuilder.append(returnClass).append(" ");
List<String> params = new ArrayList<>();

View File

@ -205,9 +205,6 @@ public class JavaClassUtil {
int index = className.indexOf("[");
className = className.substring(0, index);
}
if (className.contains(">")) {
className = className.substring(0,className.length() - 1);
}
return className;
}