add support for Future,Callable and Web flux
This commit is contained in:
parent
a96560ce62
commit
7c5add6352
|
@ -213,7 +213,7 @@ public class SourceBuilder {
|
|||
|
||||
public List<ApiMethodDoc> buildControllerMethod(final JavaClass cls) {
|
||||
List<JavaAnnotation> classAnnotations = cls.getAnnotations();
|
||||
String baseUrl = null;
|
||||
String baseUrl = "";
|
||||
for (JavaAnnotation annotation : classAnnotations) {
|
||||
String annotationName = annotation.getType().getName();
|
||||
if (REQUEST_MAPPING.equals(annotationName) || DocGlobalConstants.REQUEST_MAPPING_FULLY.equals(annotationName)) {
|
||||
|
@ -320,8 +320,9 @@ public class SourceBuilder {
|
|||
}
|
||||
|
||||
private String buildMethodReturn(JavaMethod method, String controllerName) {
|
||||
String returnType = method.getReturnType().getGenericCanonicalName();
|
||||
String typeName = method.getReturnType().getFullyQualifiedName();
|
||||
ApiReturn apiReturn = DocClassUtil.processReturnType( method.getReturnType().getGenericCanonicalName());
|
||||
String returnType = apiReturn.getGenericCanonicalName();
|
||||
String typeName = apiReturn.getSimpleName();
|
||||
if (DocClassUtil.isMvcIgnoreParams(typeName)) {
|
||||
if (DocGlobalConstants.MODE_AND_VIEW_FULLY.equals(typeName)) {
|
||||
return null;
|
||||
|
@ -634,8 +635,9 @@ public class SourceBuilder {
|
|||
if ("void".equals(method.getReturnType().getFullyQualifiedName())) {
|
||||
return "this api return nothing.";
|
||||
}
|
||||
String returnType = method.getReturnType().getGenericCanonicalName();
|
||||
String typeName = method.getReturnType().getFullyQualifiedName();
|
||||
ApiReturn apiReturn = DocClassUtil.processReturnType(method.getReturnType().getGenericCanonicalName());
|
||||
String returnType = apiReturn.getGenericCanonicalName();
|
||||
String typeName = apiReturn.getSimpleName();
|
||||
return JsonFormatUtil.formatJson(buildJson(typeName, returnType, responseFieldMap, true));
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
package com.power.doc.model;
|
||||
|
||||
/**
|
||||
* @since 1.7 +
|
||||
* @author yu 2019/9/22.
|
||||
*/
|
||||
public class ApiReturn {
|
||||
|
||||
/**
|
||||
* return type generic name
|
||||
*/
|
||||
private String genericCanonicalName;
|
||||
|
||||
/**
|
||||
* return type simple name
|
||||
*/
|
||||
private String simpleName;
|
||||
|
||||
public String getGenericCanonicalName() {
|
||||
return genericCanonicalName;
|
||||
}
|
||||
|
||||
public void setGenericCanonicalName(String genericCanonicalName) {
|
||||
this.genericCanonicalName = genericCanonicalName;
|
||||
}
|
||||
|
||||
public String getSimpleName() {
|
||||
return simpleName;
|
||||
}
|
||||
|
||||
public void setSimpleName(String simpleName) {
|
||||
this.simpleName = simpleName;
|
||||
}
|
||||
}
|
|
@ -1,5 +1,8 @@
|
|||
package com.power.doc.utils;
|
||||
|
||||
import com.power.doc.constants.DocGlobalConstants;
|
||||
import com.power.doc.model.ApiReturn;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -394,4 +397,54 @@ public class DocClassUtil {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* process return type
|
||||
*
|
||||
* @param fullyName fully name
|
||||
* @return ApiReturn
|
||||
*/
|
||||
public static ApiReturn processReturnType(String fullyName) {
|
||||
ApiReturn apiReturn = new ApiReturn();
|
||||
|
||||
//support web flux
|
||||
if (fullyName.startsWith("reactor.core.publisher.Flux")) {
|
||||
fullyName = fullyName.replace("reactor.core.publisher.Flux", DocGlobalConstants.JAVA_LIST_FULLY);
|
||||
apiReturn.setGenericCanonicalName(fullyName);
|
||||
apiReturn.setSimpleName(DocGlobalConstants.JAVA_LIST_FULLY);
|
||||
return apiReturn;
|
||||
}
|
||||
if (fullyName.startsWith("java.util.concurrent.Callable") ||
|
||||
fullyName.startsWith("java.util.concurrent.Future") ||
|
||||
fullyName.startsWith("java.util.concurrent.CompletableFuture") ||
|
||||
fullyName.startsWith("org.springframework.web.context.request.async.DeferredResult") ||
|
||||
fullyName.startsWith("org.springframework.web.context.request.async.WebAsyncTask") ||
|
||||
fullyName.startsWith("reactor.core.publisher.Mono")) {
|
||||
if (fullyName.contains("<")) {
|
||||
String[] strings = getSimpleGicName(fullyName);
|
||||
String newFullName = strings[0];
|
||||
if (newFullName.contains("<")) {
|
||||
apiReturn.setGenericCanonicalName(newFullName);
|
||||
apiReturn.setSimpleName(newFullName.substring(0, newFullName.indexOf("<")));
|
||||
} else {
|
||||
apiReturn.setGenericCanonicalName(newFullName);
|
||||
apiReturn.setSimpleName(newFullName);
|
||||
}
|
||||
} else {
|
||||
//directly return Java Object
|
||||
apiReturn.setGenericCanonicalName(DocGlobalConstants.JAVA_OBJECT_FULLY);
|
||||
apiReturn.setSimpleName(DocGlobalConstants.JAVA_OBJECT_FULLY);
|
||||
return apiReturn;
|
||||
}
|
||||
|
||||
} else {
|
||||
apiReturn.setGenericCanonicalName(fullyName);
|
||||
if (fullyName.contains("<")) {
|
||||
apiReturn.setSimpleName(fullyName.substring(0, fullyName.indexOf("<")));
|
||||
} else {
|
||||
apiReturn.setSimpleName(fullyName);
|
||||
}
|
||||
}
|
||||
return apiReturn;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue