修改changelog

This commit is contained in:
Forget 2021-06-17 23:28:49 +08:00
parent 3c5330e8f3
commit ed273cebf4
6 changed files with 164 additions and 3 deletions

View File

@ -7,6 +7,7 @@
1. 修复参数多行注释时注释提取错误gitee #I3TYYP.
2. 修复部分代码可能出现的空指针问题。
3. 添加@response tag。支持自己设置response example
4. 修复推送到torna请求或返回为数组时示例显示错误
#### 版本号2.1.9
- 更新日期: 2020-05-29

View File

@ -203,6 +203,8 @@ public interface DocGlobalConstants {
String ARRAY = "array";
String OBJECT = "object";
String JSON_PROPERTY_READ_WRITE = "JsonProperty.Access.READ_WRITE";
String JSON_PROPERTY_READ_ONLY = "JsonProperty.Access.READ_ONLY";

View File

@ -181,12 +181,59 @@ public class ApiMethodDoc implements Serializable {
* mark page
*/
private String page = "";
/**
* torna request is array
*/
private Integer isRequestArray;
/**
* torna request is array-type
*/
private String requestArrayType;
/**
* torna response is array
*/
private Integer isResponseArray;
/**
* torna request is array
*/
private String responseArrayType;
/**
* 是否为List数据 openApi
*/
private boolean listParam = false;
public Integer getIsRequestArray() {
return isRequestArray;
}
public void setIsRequestArray(Integer isRequestArray) {
this.isRequestArray = isRequestArray;
}
public String getRequestArrayType() {
return requestArrayType;
}
public void setRequestArrayType(String requestArrayType) {
this.requestArrayType = requestArrayType;
}
public Integer getIsResponseArray() {
return isResponseArray;
}
public void setIsResponseArray(Integer isResponseArray) {
this.isResponseArray = isResponseArray;
}
public String getResponseArrayType() {
return responseArrayType;
}
public void setResponseArrayType(String responseArrayType) {
this.responseArrayType = responseArrayType;
}
public boolean isListParam() {
return listParam;
}

View File

@ -46,6 +46,42 @@ public class Apis {
private List<HttpParam> responseParams;
private String errorCodeParams;
private List<Apis> items;
private Integer isRequestArray;
private String requestArrayType;
private Integer isResponseArray;
private String responseArrayType;
public Integer getIsRequestArray() {
return isRequestArray;
}
public void setIsRequestArray(Integer isRequestArray) {
this.isRequestArray = isRequestArray;
}
public String getRequestArrayType() {
return requestArrayType;
}
public void setRequestArrayType(String requestArrayType) {
this.requestArrayType = requestArrayType;
}
public Integer getIsResponseArray() {
return isResponseArray;
}
public void setIsResponseArray(Integer isResponseArray) {
this.isResponseArray = isResponseArray;
}
public String getResponseArrayType() {
return responseArrayType;
}
public void setResponseArrayType(String responseArrayType) {
this.responseArrayType = responseArrayType;
}
public Integer getOrderIndex() {
return orderIndex;

View File

@ -44,8 +44,8 @@ import java.util.logging.Logger;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static com.power.doc.constants.DocGlobalConstants.FILE_CONTENT_TYPE;
import static com.power.doc.constants.DocGlobalConstants.JSON_CONTENT_TYPE;
import static com.power.doc.constants.DocAnnotationConstants.MAX;
import static com.power.doc.constants.DocGlobalConstants.*;
import static com.power.doc.constants.DocTags.IGNORE;
import static com.power.doc.constants.DocTags.IGNORE_REQUEST_BODY_ADVICE;
@ -202,6 +202,10 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate<ApiDoc> {
apiMethodDoc.setServerUrl(projectBuilder.getServerUrl());
apiMethodDoc.setPath(requestMapping.getShortUrl());
apiMethodDoc.setDeprecated(requestMapping.isDeprecated());
List<JavaParameter> javaParameters = method.getParameters();
setTornaArrayTags(javaParameters,apiMethodDoc, docJavaMethod.getJavaMethod().getReturns());
// apiMethodDoc.setIsRequestArray();
ApiMethodReqParam apiMethodReqParam = requestParams(docJavaMethod, projectBuilder);
// build request params
if (paramsDataToTree) {
@ -943,4 +947,71 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate<ApiDoc> {
}
return annotationsList;
}
private static void setTornaArrayTags(List<JavaParameter> javaParameters, ApiMethodDoc apiMethodDoc, JavaClass returnClass) {
apiMethodDoc.setIsResponseArray(0);
apiMethodDoc.setIsRequestArray(0);
//response tags
if (JavaClassValidateUtil.isCollection(returnClass.getFullyQualifiedName()) ||
JavaClassValidateUtil.isArray(returnClass.getFullyQualifiedName())) {
apiMethodDoc.setIsResponseArray(1);
String gicType;
String simpleGicType;
String typeName = returnClass.getGenericFullyQualifiedName();
gicType = getType(typeName);
simpleGicType = gicType.substring(gicType.lastIndexOf(".") + 1).toLowerCase();
apiMethodDoc.setResponseArrayType(JavaClassValidateUtil.isPrimitive(gicType) ? simpleGicType : OBJECT);
}
//request tags
if (CollectionUtil.isNotEmpty(javaParameters)) {
for (JavaParameter parameter : javaParameters) {
String gicType;
String simpleGicType;
String typeName = parameter.getType().getGenericFullyQualifiedName();
String name = parameter.getType().getFullyQualifiedName();
gicType = getType(typeName);
simpleGicType = gicType.substring(gicType.lastIndexOf(".") + 1).toLowerCase();
// is array
if (JavaClassValidateUtil.isCollection(name) || JavaClassValidateUtil.isArray(name)) {
boolean hasRequestBody = false;
//param has @RequestBody ?
List<JavaAnnotation> annotations = parameter.getAnnotations();
for (JavaAnnotation annotation : annotations) {
if (REQUEST_BODY_FULLY.equals(annotation.getType().getName())) {
hasRequestBody = true;
break;
}
}
//formData - multiple data
if (!hasRequestBody && javaParameters.size() > 1) {
return;
}
else {
apiMethodDoc.setIsRequestArray(1);
if (JavaClassValidateUtil.isPrimitive(gicType)) {
apiMethodDoc.setRequestArrayType(simpleGicType);
} else {
apiMethodDoc.setRequestArrayType(OBJECT);
}
}
}
}
}
}
private static String getType(String typeName) {
String gicType;
//get generic type
if (typeName.contains("<")) {
gicType = typeName.substring(typeName.indexOf("<") + 1, typeName.lastIndexOf(">"));
} else {
gicType = typeName;
}
if (gicType.contains("[")) {
gicType = gicType.substring(0, gicType.indexOf("["));
}
return gicType;
}
}

View File

@ -96,6 +96,10 @@ public class TornaUtil {
methodApi.setHeaderParams(buildHerder(apiMethodDoc.getRequestHeaders()));
methodApi.setResponseParams(buildParams(apiMethodDoc.getResponseParams()));
methodApi.setIsRequestArray(apiMethodDoc.getIsRequestArray());
methodApi.setIsResponseArray(apiMethodDoc.getIsResponseArray());
methodApi.setRequestArrayType(apiMethodDoc.getRequestArrayType());
methodApi.setResponseArrayType(apiMethodDoc.getResponseArrayType());
//Path
if (CollectionUtil.isNotEmpty(apiMethodDoc.getPathParams())) {
methodApi.setPathParams(buildParams(apiMethodDoc.getPathParams()));