optimized code and upgrade dependencies

This commit is contained in:
oppofind 2020-01-04 00:24:05 +08:00
parent ad15c7d366
commit 9277bf3add
11 changed files with 159 additions and 50 deletions

View File

@ -32,7 +32,7 @@
</developers>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<flexmark.version>0.50.40</flexmark.version>
<flexmark.version>0.50.46</flexmark.version>
</properties>
<dependencies>
<dependency>
@ -44,7 +44,7 @@
<dependency>
<groupId>com.ibeetl</groupId>
<artifactId>beetl</artifactId>
<version>3.0.15.RELEASE</version>
<version>3.0.16.RELEASE</version>
</dependency>
<dependency>
<groupId>com.thoughtworks.qdox</groupId>
@ -106,7 +106,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.1.0</version>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>

View File

@ -66,7 +66,7 @@ public class DocBuilderTemplate {
public ApiAllData getApiData(ApiConfig config, JavaProjectBuilder javaProjectBuilder) {
ApiAllData apiAllData = new ApiAllData();
apiAllData.setProjectName(config.getProjectName());
apiAllData.setProjectId(DocUtil.handleId(config.getProjectName()));
apiAllData.setProjectId(DocUtil.generateId(config.getProjectName()));
apiAllData.setLanguage(config.getLanguage().getCode());
apiAllData.setApiDocList(listOfApiData(config, javaProjectBuilder));
apiAllData.setErrorCodeList(errorCodeDictToList(config));

View File

@ -1376,13 +1376,13 @@ public class SourceBuilder {
*/
private void handControllerAlias(ApiDoc apiDoc) {
if (isUseMD5) {
String name = DocUtil.handleId(apiDoc.getName());
String name = DocUtil.generateId(apiDoc.getName());
apiDoc.setAlias(name);
}
}
private void handleMethodUid(ApiMethodDoc methodDoc, String methodName) {
String name = DocUtil.handleId(methodName);
String name = DocUtil.generateId(methodName);
methodDoc.setMethodId(name);
}

View File

@ -70,10 +70,7 @@ public class FormDataBuildHelper {
String subTypeName = field.getType().getFullyQualifiedName();
String fieldGicName = field.getType().getGenericCanonicalName();
JavaClass javaClass = builder.getJavaProjectBuilder().getClassByName(subTypeName);
boolean ignoreField = field.getModifiers().stream()
.anyMatch(str -> str.equals(DocGlobalConstants.STATIC) || str.equals(DocGlobalConstants.FINAL));
if (ignoreField || "this$0".equals(fieldName) ||
"serialVersionUID".equals(fieldName) ||
if (field.isStatic() || "this$0".equals(fieldName) ||
JavaClassValidateUtil.isIgnoreFieldTypes(subTypeName)) {
continue;
}

View File

@ -137,11 +137,7 @@ public class JsonBuildHelper {
for (JavaField field : fields) {
String subTypeName = field.getType().getFullyQualifiedName();
String fieldName = field.getName();
boolean ignoreField = field.getModifiers().stream()
.anyMatch(str -> str.equals(DocGlobalConstants.STATIC) || str.equals(DocGlobalConstants.FINAL));
if (ignoreField || "this$0".equals(fieldName) ||
"serialVersionUID".equals(fieldName) ||
if (field.isStatic() || "this$0".equals(fieldName) ||
JavaClassValidateUtil.isIgnoreFieldTypes(subTypeName)) {
continue;
}

View File

@ -68,10 +68,7 @@ public class ParamsBuildHelper {
for (JavaField field : fields) {
String fieldName = field.getName();
String subTypeName = field.getType().getFullyQualifiedName();
boolean ignoreField = field.getModifiers().stream()
.anyMatch(str -> str.equals(DocGlobalConstants.STATIC) || str.equals(DocGlobalConstants.FINAL));
if (ignoreField || "this$0".equals(fieldName) ||
"serialVersionUID".equals(fieldName) ||
if (field.isStatic() || "this$0".equals(fieldName) ||
JavaClassValidateUtil.isIgnoreFieldTypes(subTypeName)) {
continue;
}

View File

@ -10,7 +10,10 @@ import com.power.doc.utils.DocUtil;
import com.power.doc.utils.JavaClassValidateUtil;
import com.thoughtworks.qdox.model.JavaClass;
import com.thoughtworks.qdox.model.JavaMethod;
import com.thoughtworks.qdox.model.JavaType;
import com.thoughtworks.qdox.model.JavaTypeVariable;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@ -60,7 +63,7 @@ public interface IDocBuildTemplate {
apiDoc.setName(controllerName);
apiDoc.setAlias(controllerName);
if (isUseMD5) {
String name = DocUtil.handleId(apiDoc.getName());
String name = DocUtil.generateId(apiDoc.getName());
apiDoc.setAlias(name);
}
apiDoc.setDesc(cls.getComment());
@ -88,7 +91,7 @@ public interface IDocBuildTemplate {
if (JavaClassValidateUtil.isPrimitive(gicName)) {
return ParamsBuildHelper.primitiveReturnRespComment("array of " + DocClassUtil.processTypeNameForParams(gicName));
}
return ParamsBuildHelper.buildParams(gicName, "", 0, null, projectBuilder.getCustomRespFieldMap(), true, new HashMap<>(), projectBuilder);
return ParamsBuildHelper.buildParams(gicName, "", 0, null, projectBuilder.getCustomRespFieldMap(), Boolean.TRUE, new HashMap<>(), projectBuilder);
} else {
return null;
}
@ -101,10 +104,10 @@ public interface IDocBuildTemplate {
if (JavaClassValidateUtil.isPrimitive(keyValue[1])) {
return ParamsBuildHelper.primitiveReturnRespComment("key value");
}
return ParamsBuildHelper.buildParams(keyValue[1], "", 0, null, projectBuilder.getCustomRespFieldMap(), true, new HashMap<>(), projectBuilder);
return ParamsBuildHelper.buildParams(keyValue[1], "", 0, null, projectBuilder.getCustomRespFieldMap(), Boolean.TRUE, new HashMap<>(), projectBuilder);
}
if (StringUtil.isNotEmpty(returnType)) {
return ParamsBuildHelper.buildParams(returnType, "", 0, null, projectBuilder.getCustomRespFieldMap(), true, new HashMap<>(), projectBuilder);
return ParamsBuildHelper.buildParams(returnType, "", 0, null, projectBuilder.getCustomRespFieldMap(), Boolean.TRUE, new HashMap<>(), projectBuilder);
}
return null;
}

View File

@ -87,7 +87,7 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate {
List<ApiMethodDoc> methodDocList = new ArrayList<>(methods.size());
int methodOrder = 0;
for (JavaMethod method : methods) {
if (method.getModifiers().contains("private")) {
if (method.isPrivate()) {
continue;
}
if (StringUtil.isEmpty(method.getComment()) && apiConfig.isStrict()) {
@ -98,7 +98,7 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate {
apiMethodDoc.setOrder(methodOrder);
apiMethodDoc.setDesc(method.getComment());
apiMethodDoc.setName(method.getName());
String methodUid = DocUtil.handleId(clazName + method.getName());
String methodUid = DocUtil.generateId(clazName + method.getName());
apiMethodDoc.setMethodId(methodUid);
String apiNoteValue = DocUtil.getNormalTagComments(method, DocTags.API_NOTE, cls.getName());
if (StringUtil.isEmpty(apiNoteValue)) {
@ -261,7 +261,7 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate {
gicName = gicName.substring(0, gicName.indexOf("["));
}
if (!JavaClassValidateUtil.isPrimitive(gicName)) {
throw new RuntimeException("FormData can't support binding Collection<T> on method "
throw new RuntimeException("Spring MVC can't support binding Collection on method "
+ method.getName() + "Check it in " + method.getDeclaringClass().getCanonicalName());
}
FormData formData = new FormData();

View File

@ -363,7 +363,7 @@ public class DocUtil {
* @param value value
* @return String
*/
public static String handleId(String value) {
public static String generateId(String value) {
if (StringUtil.isEmpty(value)) {
return null;
}

View File

@ -0,0 +1,50 @@
{
"serverUrl": "http://127.0.0.1",
"isStrict": false,
"allInOne": true,
"outPath": "D://md2",
"coverOld": true,
"packageFilters": "",
"md5EncryptedHtmlName": false,
"projectName": "smart-doc",
"skipTransientField": true,
"revisionLogs": [
{
"version": "1.0",
"status": "use",
"author": "author",
"revisionTime": "2019-10-12",
"remarks": "desc"
}
],
"errorCodes": [
{
"value": "200",
"type": "string",
"desc": "desc"
}
],
"customResponseFields": [
{
"name": "name",
"desc": "desc",
"ownerClassName": "ownerClassName",
"value": "value"
}
],
"requestHeaders": [
{
"name": "token",
"type": "string",
"desc": "desc",
"required": false,
"since": "-"
}
],
"sourceCodePaths": [
{
"path": "src/main/java",
"desc": "测试"
}
]
}

View File

@ -0,0 +1,66 @@
{
"serverUrl": "http://127.0.0.1",
"isStrict": false,
"allInOne": true,
"outPath": "D://md2",
"coverOld": true,
"packageFilters": "",
"md5EncryptedHtmlName": false,
"projectName": "smart-doc",
"skipTransientField": true,
"dataDictionaries": [
{
"title": "title",
"enumClassName": "com.data.Enum",
"codeField": "codeField",
"descField": "descField"
}
],
"errorCodeDictionaries": [
{
"title": "title",
"enumClassName": "com.data.Enum",
"codeField": "codeField",
"descField": "descField"
}
],
"revisionLogs": [
{
"version": "1.0",
"status": "use",
"author": "author",
"revisionTime": "2019-10-12",
"remarks": "desc"
}
],
"errorCodes": [
{
"value": "200",
"type": "string",
"desc": "desc"
}
],
"customResponseFields": [
{
"name": "name",
"desc": "desc",
"ownerClassName": "ownerClassName",
"value": "value"
}
],
"requestHeaders": [
{
"name": "token",
"type": "string",
"desc": "desc",
"required": false,
"since": "-"
}
],
"sourceCodePaths": [
{
"path": "src/main/java",
"desc": "测试"
}
]
}