optimize the code ,remove duplication

This commit is contained in:
oppofind 2020-08-08 00:22:02 +08:00
parent 54b0c07661
commit ed30182872
1 changed files with 14 additions and 16 deletions

View File

@ -264,14 +264,7 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate<ApiDoc> {
if (null != annotationDefaultVal) {
mockValue = StringUtil.removeQuotes(annotationDefaultVal.toString());
}
AnnotationValue annotationValue = annotation.getProperty(DocAnnotationConstants.VALUE_PROP);
if (null != annotationValue) {
paramName = StringUtil.removeQuotes(annotationValue.toString());
}
AnnotationValue annotationOfName = annotation.getProperty(DocAnnotationConstants.NAME_PROP);
if (null != annotationOfName) {
paramName = StringUtil.removeQuotes(annotationOfName.toString());
}
paramName = getParamName(paramName, annotation);
for (Map.Entry<String, String> entry : constantsMap.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
@ -476,14 +469,7 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate<ApiDoc> {
}
if (SpringMvcAnnotations.REQUEST_PARAM.equals(annotationName) ||
DocAnnotationConstants.SHORT_PATH_VARIABLE.equals(annotationName)) {
AnnotationValue annotationValue = annotation.getProperty(DocAnnotationConstants.VALUE_PROP);
if (null != annotationValue) {
paramName = StringUtil.removeQuotes(annotationValue.toString());
}
AnnotationValue annotationOfName = annotation.getProperty(DocAnnotationConstants.NAME_PROP);
if (null != annotationOfName) {
paramName = StringUtil.removeQuotes(annotationOfName.toString());
}
paramName = getParamName(paramName, annotation);
for (Map.Entry<String, String> entry : constantsMap.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
@ -560,6 +546,18 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate<ApiDoc> {
return paramList;
}
private String getParamName(String paramName, JavaAnnotation annotation) {
AnnotationValue annotationValue = annotation.getProperty(DocAnnotationConstants.VALUE_PROP);
if (null != annotationValue) {
paramName = StringUtil.removeQuotes(annotationValue.toString());
}
AnnotationValue annotationOfName = annotation.getProperty(DocAnnotationConstants.NAME_PROP);
if (null != annotationOfName) {
paramName = StringUtil.removeQuotes(annotationOfName.toString());
}
return paramName;
}
private boolean checkController(JavaClass cls) {
List<JavaAnnotation> classAnnotations = cls.getAnnotations();
for (JavaAnnotation annotation : classAnnotations) {