fix gitee #I1JHMW,Remove duplicate fields
This commit is contained in:
parent
b690ad7822
commit
6395eaf17e
|
@ -32,10 +32,7 @@ import com.thoughtworks.qdox.JavaProjectBuilder;
|
|||
import com.thoughtworks.qdox.model.JavaClass;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import static com.power.doc.constants.DocGlobalConstants.DEFAULT_SERVER_URL;
|
||||
|
@ -123,7 +120,7 @@ public class ProjectDocConfigBuilder {
|
|||
|
||||
public JavaClass getClassByName(String simpleName) {
|
||||
JavaClass cls = javaProjectBuilder.getClassByName(simpleName);
|
||||
List<DocJavaField> fieldList = JavaClassUtil.getFields(cls, 0);
|
||||
List<DocJavaField> fieldList = JavaClassUtil.getFields(cls, 0,new HashSet<>());
|
||||
// handle inner class
|
||||
if (Objects.isNull(cls.getFields()) || fieldList.isEmpty()) {
|
||||
cls = classFilesMap.get(simpleName);
|
||||
|
|
|
@ -36,6 +36,7 @@ import com.thoughtworks.qdox.model.JavaClass;
|
|||
import com.thoughtworks.qdox.model.JavaField;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -69,7 +70,7 @@ public class FormDataBuildHelper {
|
|||
String simpleName = DocClassUtil.getSimpleName(className);
|
||||
String[] globGicName = DocClassUtil.getSimpleGicName(className);
|
||||
JavaClass cls = builder.getJavaProjectBuilder().getClassByName(simpleName);
|
||||
List<DocJavaField> fields = JavaClassUtil.getFields(cls, 0);
|
||||
List<DocJavaField> fields = JavaClassUtil.getFields(cls, 0,new HashSet<>());
|
||||
|
||||
if (JavaClassValidateUtil.isPrimitive(simpleName)) {
|
||||
FormData formData = new FormData();
|
||||
|
|
|
@ -38,6 +38,7 @@ import com.thoughtworks.qdox.model.JavaField;
|
|||
import com.thoughtworks.qdox.model.JavaMethod;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -154,7 +155,7 @@ public class JsonBuildHelper {
|
|||
} else {
|
||||
boolean requestFieldToUnderline = builder.getApiConfig().isRequestFieldToUnderline();
|
||||
boolean responseFieldToUnderline = builder.getApiConfig().isResponseFieldToUnderline();
|
||||
List<DocJavaField> fields = JavaClassUtil.getFields(cls, 0);
|
||||
List<DocJavaField> fields = JavaClassUtil.getFields(cls, 0,new HashSet<>());
|
||||
boolean isGenerics = JavaFieldUtil.checkGenerics(fields);
|
||||
int i = 0;
|
||||
out:
|
||||
|
|
|
@ -36,6 +36,7 @@ import com.power.doc.utils.*;
|
|||
import com.thoughtworks.qdox.model.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -67,7 +68,7 @@ public class ParamsBuildHelper {
|
|||
String simpleName = DocClassUtil.getSimpleName(className);
|
||||
String[] globGicName = DocClassUtil.getSimpleGicName(className);
|
||||
JavaClass cls = projectBuilder.getClassByName(simpleName);
|
||||
List<DocJavaField> fields = JavaClassUtil.getFields(cls, 0);
|
||||
List<DocJavaField> fields = JavaClassUtil.getFields(cls, 0,new HashSet<>());
|
||||
int n = 0;
|
||||
if (JavaClassValidateUtil.isPrimitive(simpleName)) {
|
||||
String processedType = isShowJavaType ? simpleName : DocClassUtil.processTypeNameForParams(simpleName.toLowerCase());
|
||||
|
|
|
@ -38,6 +38,7 @@ import com.thoughtworks.qdox.model.impl.DefaultJavaParameterizedType;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Handle JavaClass
|
||||
|
@ -49,11 +50,12 @@ public class JavaClassUtil {
|
|||
/**
|
||||
* Get fields
|
||||
*
|
||||
* @param cls1 The JavaClass object
|
||||
* @param i Recursive counter
|
||||
* @param cls1 The JavaClass object
|
||||
* @param counter Recursive counter
|
||||
* @param addedFields added fields,Field deduplication
|
||||
* @return list of JavaField
|
||||
*/
|
||||
public static List<DocJavaField> getFields(JavaClass cls1, int i) {
|
||||
public static List<DocJavaField> getFields(JavaClass cls1, int counter, Set<String> addedFields) {
|
||||
List<DocJavaField> fieldList = new ArrayList<>();
|
||||
if (null == cls1) {
|
||||
return fieldList;
|
||||
|
@ -80,6 +82,7 @@ public class JavaClassUtil {
|
|||
if (!enable) {
|
||||
continue;
|
||||
}
|
||||
addedFields.add(methodName);
|
||||
String comment = javaMethod.getComment();
|
||||
JavaField javaField = new DefaultJavaField(javaMethod.getReturns(), methodName);
|
||||
DocJavaField docJavaField = DocJavaField.builder().setJavaField(javaField).setComment(comment);
|
||||
|
@ -89,16 +92,21 @@ public class JavaClassUtil {
|
|||
// ignore enum parent class
|
||||
if (!cls1.isEnum()) {
|
||||
JavaClass parentClass = cls1.getSuperJavaClass();
|
||||
fieldList.addAll(getFields(parentClass, i));
|
||||
fieldList.addAll(getFields(parentClass, counter, addedFields));
|
||||
List<JavaType> implClasses = cls1.getImplements();
|
||||
for (JavaType type : implClasses) {
|
||||
JavaClass javaClass = (JavaClass) type;
|
||||
fieldList.addAll(getFields(javaClass, i));
|
||||
fieldList.addAll(getFields(javaClass, counter, addedFields));
|
||||
}
|
||||
|
||||
}
|
||||
List<DocJavaField> docJavaFields = new ArrayList<>();
|
||||
for (JavaField javaField : cls1.getFields()) {
|
||||
String fieldName = javaField.getName();
|
||||
if (addedFields.contains(fieldName)) {
|
||||
continue;
|
||||
}
|
||||
addedFields.add(fieldName);
|
||||
docJavaFields.add(DocJavaField.builder().setComment(javaField.getComment()).setJavaField(javaField));
|
||||
}
|
||||
fieldList.addAll(docJavaFields);
|
||||
|
|
Loading…
Reference in New Issue