release 2.0.7
This commit is contained in:
parent
77784498b5
commit
29c308ae85
|
@ -1,6 +1,13 @@
|
|||
## smart-doc版本
|
||||
版本小于1.0都属于试用,正式1.0起始发布将会等到文中提到的问题解决后才发布。
|
||||
#### 版本号:2.0.6
|
||||
- 更新日期: 2020-01-24
|
||||
- 更新内容:
|
||||
1. 修复postman的url中不附加的context-path的问题。
|
||||
2. 修复带正则的path路径参数解析出现截取越界的问题。
|
||||
3. 添加对默认接口实现中get方法重写忽略的能力解析。
|
||||
4. 修改数组、map等字段类型的自定义mock值显示错误问题。
|
||||
#### 版本号:2.0.6
|
||||
- 更新日期: 2020-01-15
|
||||
- 更新内容:
|
||||
1. 修复带正则的path路径参数在postman中用例问题。
|
||||
|
|
2
pom.xml
2
pom.xml
|
@ -5,7 +5,7 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>smart-doc</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>2.0.6</version>
|
||||
<version>2.0.7</version>
|
||||
|
||||
<name>smart-doc</name>
|
||||
<url>https://github.com/smart-doc-group/smart-doc.git</url>
|
||||
|
|
|
@ -92,7 +92,7 @@ public class ProjectDocConfigBuilder {
|
|||
|
||||
public JavaClass getClassByName(String simpleName) {
|
||||
JavaClass cls = javaProjectBuilder.getClassByName(simpleName);
|
||||
List<DocJavaField> fieldList = JavaClassUtil.getFields(cls, 0, new HashSet<>());
|
||||
List<DocJavaField> fieldList = JavaClassUtil.getFields(cls, 0, new LinkedHashMap<>());
|
||||
// handle inner class
|
||||
if (Objects.isNull(cls.getFields()) || fieldList.isEmpty()) {
|
||||
cls = classFilesMap.get(simpleName);
|
||||
|
|
|
@ -37,10 +37,7 @@ import com.power.doc.utils.JavaClassValidateUtil;
|
|||
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;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author yu 2019/12/25.
|
||||
|
@ -79,7 +76,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, new HashSet<>());
|
||||
List<DocJavaField> fields = JavaClassUtil.getFields(cls, 0, new LinkedHashMap<>());
|
||||
|
||||
if (JavaClassValidateUtil.isPrimitive(simpleName)) {
|
||||
FormData formData = new FormData();
|
||||
|
|
|
@ -186,7 +186,7 @@ public class JsonBuildHelper {
|
|||
} else {
|
||||
boolean requestFieldToUnderline = builder.getApiConfig().isRequestFieldToUnderline();
|
||||
boolean responseFieldToUnderline = builder.getApiConfig().isResponseFieldToUnderline();
|
||||
List<DocJavaField> fields = JavaClassUtil.getFields(cls, 0, new HashSet<>());
|
||||
List<DocJavaField> fields = JavaClassUtil.getFields(cls, 0, new LinkedHashMap<>());
|
||||
boolean isGenerics = JavaFieldUtil.checkGenerics(fields);
|
||||
out:
|
||||
for (DocJavaField docField : fields) {
|
||||
|
@ -236,8 +236,9 @@ public class JsonBuildHelper {
|
|||
if (tagsMap.containsKey(DocTags.MOCK) && StringUtil.isNotEmpty(tagsMap.get(DocTags.MOCK))) {
|
||||
fieldValue = tagsMap.get(DocTags.MOCK);
|
||||
if (!DocUtil.javaPrimaryType(typeSimpleName)
|
||||
&& !JavaClassValidateUtil.isCollection(fieldGicName)
|
||||
&& !JavaClassValidateUtil.isMap(fieldGicName)) {
|
||||
&& !JavaClassValidateUtil.isCollection(subTypeName)
|
||||
&& !JavaClassValidateUtil.isMap(subTypeName)
|
||||
&& !JavaClassValidateUtil.isArray(subTypeName)) {
|
||||
fieldValue = DocUtil.handleJsonStr(fieldValue);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -80,7 +80,7 @@ public class ParamsBuildHelper {
|
|||
JavaClass cls = projectBuilder.getClassByName(simpleName);
|
||||
//如果存在泛型 则将泛型与类名的对应关系存起来
|
||||
JavaClassUtil.genericParamMap(genericMap, cls, globGicName);
|
||||
List<DocJavaField> fields = JavaClassUtil.getFields(cls, 0, new HashSet<>());
|
||||
List<DocJavaField> fields = JavaClassUtil.getFields(cls, 0, new LinkedHashMap<>());
|
||||
if (JavaClassValidateUtil.isPrimitive(simpleName)) {
|
||||
String processedType = isShowJavaType ? simpleName : DocClassUtil.processTypeNameForParams(simpleName.toLowerCase());
|
||||
paramList.addAll(primitiveReturnRespComment(processedType));
|
||||
|
|
|
@ -39,6 +39,7 @@ import com.thoughtworks.qdox.model.impl.DefaultJavaParameterizedType;
|
|||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Handle JavaClass
|
||||
|
@ -55,9 +56,9 @@ public class JavaClassUtil {
|
|||
* @param addedFields added fields,Field deduplication
|
||||
* @return list of JavaField
|
||||
*/
|
||||
public static List<DocJavaField> getFields(JavaClass cls1, int counter, Set<String> addedFields) {
|
||||
public static List<DocJavaField> getFields(JavaClass cls1, int counter, Map<String, DocJavaField> addedFields) {
|
||||
List<DocJavaField> fieldList = new ArrayList<>();
|
||||
if (Objects.isNull(cls1)) {
|
||||
if (null == cls1) {
|
||||
return fieldList;
|
||||
} else if ("Object".equals(cls1.getSimpleName()) || "Timestamp".equals(cls1.getSimpleName()) ||
|
||||
"Date".equals(cls1.getSimpleName()) || "Locale".equals(cls1.getSimpleName())
|
||||
|
@ -75,16 +76,15 @@ public class JavaClassUtil {
|
|||
int paramSize = javaMethod.getParameters().size();
|
||||
boolean enable = false;
|
||||
if (methodName.startsWith("get") && !"get".equals(methodName) && paramSize == 0) {
|
||||
methodName = StringUtil.firstToLowerCase(methodName.substring(3, methodName.length()));
|
||||
methodName = StringUtil.firstToLowerCase(methodName.substring(3));
|
||||
enable = true;
|
||||
} else if (methodName.startsWith("is") && !"is".equals(methodName) && paramSize == 0) {
|
||||
methodName = StringUtil.firstToLowerCase(methodName.substring(2, methodName.length()));
|
||||
methodName = StringUtil.firstToLowerCase(methodName.substring(2));
|
||||
enable = true;
|
||||
}
|
||||
if (!enable || addedFields.contains(methodName)) {
|
||||
if (!enable || addedFields.containsKey(methodName)) {
|
||||
continue;
|
||||
}
|
||||
addedFields.add(methodName);
|
||||
String comment = javaMethod.getComment();
|
||||
JavaField javaField = new DefaultJavaField(javaMethod.getReturns(), methodName);
|
||||
DocJavaField docJavaField = DocJavaField.builder()
|
||||
|
@ -94,30 +94,41 @@ public class JavaClassUtil {
|
|||
.setAnnotations(javaMethod.getAnnotations())
|
||||
.setFullyQualifiedName(javaField.getType().getFullyQualifiedName())
|
||||
.setGenericCanonicalName(javaField.getType().getGenericCanonicalName());
|
||||
|
||||
fieldList.add(docJavaField);
|
||||
addedFields.put(methodName, docJavaField);
|
||||
}
|
||||
}
|
||||
// ignore enum parent class
|
||||
if (!cls1.isEnum()) {
|
||||
JavaClass parentClass = cls1.getSuperJavaClass();
|
||||
fieldList.addAll(getFields(parentClass, counter, addedFields));
|
||||
getFields(parentClass, counter, addedFields);
|
||||
List<JavaType> implClasses = cls1.getImplements();
|
||||
for (JavaType type : implClasses) {
|
||||
JavaClass javaClass = (JavaClass) type;
|
||||
fieldList.addAll(getFields(javaClass, counter, addedFields));
|
||||
getFields(javaClass, counter, addedFields);
|
||||
}
|
||||
}
|
||||
Map<String, JavaType> actualJavaTypes = getActualTypesMap(cls1);
|
||||
List<DocJavaField> docJavaFields = new ArrayList<>();
|
||||
|
||||
List<JavaMethod> javaMethods = cls1.getMethods();
|
||||
for (JavaMethod method : javaMethods) {
|
||||
String methodName = method.getName();
|
||||
int paramSize = method.getParameters().size();
|
||||
if (methodName.startsWith("get") && !"get".equals(methodName) && paramSize == 0) {
|
||||
methodName = StringUtil.firstToLowerCase(methodName.substring(3));
|
||||
} else if (methodName.startsWith("is") && !"is".equals(methodName) && paramSize == 0) {
|
||||
methodName = StringUtil.firstToLowerCase(methodName.substring(2));
|
||||
}
|
||||
if (addedFields.containsKey(methodName)) {
|
||||
String comment = method.getComment();
|
||||
DocJavaField docJavaField = addedFields.get(methodName);
|
||||
docJavaField.setAnnotations(method.getAnnotations());
|
||||
docJavaField.setComment(comment);
|
||||
addedFields.put(methodName, docJavaField);
|
||||
}
|
||||
}
|
||||
for (JavaField javaField : cls1.getFields()) {
|
||||
String fieldName = javaField.getName();
|
||||
if (addedFields.contains(fieldName)) {
|
||||
continue;
|
||||
}
|
||||
boolean typeChecked = false;
|
||||
DocJavaField docJavaField = DocJavaField.builder();
|
||||
boolean typeChecked = false;
|
||||
String gicName = javaField.getType().getGenericCanonicalName();
|
||||
String subTypeName = javaField.getType().getFullyQualifiedName();
|
||||
String actualType = null;
|
||||
|
@ -148,17 +159,25 @@ public class JavaClassUtil {
|
|||
actualType = value.getFullyQualifiedName();
|
||||
}
|
||||
}
|
||||
addedFields.add(fieldName);
|
||||
docJavaFields.add(docJavaField.setComment(javaField.getComment())
|
||||
docJavaField.setComment(javaField.getComment())
|
||||
.setJavaField(javaField).setFullyQualifiedName(subTypeName)
|
||||
.setGenericCanonicalName(gicName).setActualJavaType(actualType));
|
||||
.setGenericCanonicalName(gicName).setActualJavaType(actualType)
|
||||
.setAnnotations(javaField.getAnnotations());
|
||||
if (addedFields.containsKey(fieldName)) {
|
||||
addedFields.put(fieldName, docJavaField);
|
||||
continue;
|
||||
}
|
||||
addedFields.put(fieldName, docJavaField);
|
||||
}
|
||||
fieldList.addAll(docJavaFields);
|
||||
List<DocJavaField> parentFieldList = addedFields.values().stream()
|
||||
.filter(v -> Objects.nonNull(v)).collect(Collectors.toList());
|
||||
fieldList.addAll(parentFieldList);
|
||||
}
|
||||
return fieldList;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* get enum value
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue