This commit is contained in:
yusun4 2020-10-23 22:54:43 +08:00
parent bd134394cf
commit 1a9a64eb03
4 changed files with 62 additions and 12 deletions

View File

@ -1,12 +1,13 @@
## smart-doc版本 ## smart-doc版本
版本小于1.0都属于试用正式1.0起始发布将会等到文中提到的问题解决后才发布。 版本小于1.0都属于试用正式1.0起始发布将会等到文中提到的问题解决后才发布。
#### 版本号1.9.7 #### 版本号1.9.7
- 更新日期: 2020-10-19 - 更新日期: 2020-10-24
- 更新内容: - 更新内容:
1. 修复restful接口泛型中使用?时的解析错误。 1. 修复restful接口泛型中使用?时的解析错误。
2. 优化rpc html非all in one的问题。 2. 优化rpc html非all in one的问题。
3. 对rest query参数自动添加描述增加可读性。 3. 对rest query参数自动添加描述增加可读性。
4. support ali dubbo,#I22CF7 . 4. support ali dubbo,#I22CF7 .
5. support @RequestMapping headers.
#### 版本号1.9.6 #### 版本号1.9.6
- 更新日期: 2020-10-09 - 更新日期: 2020-10-09
- 更新内容: - 更新内容:

View File

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>smart-doc</artifactId> <artifactId>smart-doc</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>
<version>1.9.6</version> <version>1.9.7</version>
<name>smart-doc</name> <name>smart-doc</name>
<url>https://github.com/smart-doc-group/smart-doc.git</url> <url>https://github.com/smart-doc-group/smart-doc.git</url>

View File

@ -23,19 +23,18 @@
package com.power.doc.handler; package com.power.doc.handler;
import com.power.common.util.StringUtil; import com.power.common.util.StringUtil;
import com.power.doc.constants.DocAnnotationConstants; import com.power.doc.constants.*;
import com.power.doc.constants.DocTags;
import com.power.doc.constants.SpringMvcAnnotations;
import com.power.doc.model.ApiReqHeader; import com.power.doc.model.ApiReqHeader;
import com.power.doc.utils.DocClassUtil; import com.power.doc.utils.DocClassUtil;
import com.power.doc.utils.DocUtil; import com.power.doc.utils.DocUtil;
import com.thoughtworks.qdox.model.JavaAnnotation; import com.thoughtworks.qdox.model.JavaAnnotation;
import com.thoughtworks.qdox.model.JavaMethod; import com.thoughtworks.qdox.model.JavaMethod;
import com.thoughtworks.qdox.model.JavaParameter; import com.thoughtworks.qdox.model.JavaParameter;
import com.thoughtworks.qdox.model.expression.AnnotationValue;
import java.util.ArrayList; import java.util.*;
import java.util.List; import java.util.stream.Collectors;
import java.util.Map; import java.util.stream.Stream;
/** /**
* @author yu 2019/12/22. * @author yu 2019/12/22.
@ -49,7 +48,42 @@ public class SpringMVCRequestHeaderHandler {
* @return list of ApiReqHeader * @return list of ApiReqHeader
*/ */
public List<ApiReqHeader> handle(JavaMethod method) { public List<ApiReqHeader> handle(JavaMethod method) {
List<ApiReqHeader> apiReqHeaders = new ArrayList<>(); List<ApiReqHeader> mappingHeaders = new ArrayList<>();
List<JavaAnnotation> annotations = method.getAnnotations();
for (JavaAnnotation annotation : annotations) {
String annotationName = annotation.getType().getName();
if (!isMapping(annotationName)) {
continue;
}
Object headersObject = annotation.getNamedParameter("headers");
List<String> headers = (LinkedList) headersObject;
for (String str : headers) {
String header = StringUtil.removeQuotes(str);
if (header.startsWith("!")) {
continue;
}
if (header.contains("!=")) {
String headerName = header.substring(0, header.indexOf("!"));
ApiReqHeader apiReqHeader = ApiReqHeader.builder().setName(headerName)
.setRequired(true).setValue(null).setDesc(header).setType("string");
mappingHeaders.add(apiReqHeader);
} else {
String headerName;
String headerValue = null;
if (header.contains("=")) {
int index = header.indexOf("=");
headerName = header.substring(0, header.indexOf("="));
headerValue = header.substring(index + 1);
} else {
headerName = header;
}
ApiReqHeader apiReqHeader = ApiReqHeader.builder().setName(headerName)
.setRequired(true).setValue(headerValue).setDesc(header).setType("string");
mappingHeaders.add(apiReqHeader);
}
}
}
List<ApiReqHeader> reqHeaders = new ArrayList<>();
for (JavaParameter javaParameter : method.getParameters()) { for (JavaParameter javaParameter : method.getParameters()) {
List<JavaAnnotation> javaAnnotations = javaParameter.getAnnotations(); List<JavaAnnotation> javaAnnotations = javaParameter.getAnnotations();
String className = method.getDeclaringClass().getCanonicalName(); String className = method.getDeclaringClass().getCanonicalName();
@ -84,11 +118,27 @@ public class SpringMVCRequestHeaderHandler {
} }
String typeName = javaParameter.getType().getValue().toLowerCase(); String typeName = javaParameter.getType().getValue().toLowerCase();
apiReqHeader.setType(DocClassUtil.processTypeNameForParams(typeName)); apiReqHeader.setType(DocClassUtil.processTypeNameForParams(typeName));
apiReqHeaders.add(apiReqHeader); reqHeaders.add(apiReqHeader);
break; break;
} }
} }
} }
return apiReqHeaders; List<ApiReqHeader> allApiReqHeaders = Stream.of(mappingHeaders, reqHeaders)
.flatMap(Collection::stream).distinct().collect(Collectors.toList());
return allApiReqHeaders;
}
private boolean isMapping(String annotationName) {
switch (annotationName) {
case "GetMapping":
case "RequestMapping":
case "PostMapping":
case "PutMapping":
case "PatchMapping":
case "DeleteMapping":
return true;
default:
return false;
}
} }
} }

View File

@ -163,7 +163,6 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate<ApiDoc> {
.handle(projectBuilder.getServerUrl(), baseUrl, method, constantsMap); .handle(projectBuilder.getServerUrl(), baseUrl, method, constantsMap);
//handle headers //handle headers
List<ApiReqHeader> apiReqHeaders = new SpringMVCRequestHeaderHandler().handle(method); List<ApiReqHeader> apiReqHeaders = new SpringMVCRequestHeaderHandler().handle(method);
apiMethodDoc.setRequestHeaders(apiReqHeaders);
if (Objects.nonNull(requestMapping)) { if (Objects.nonNull(requestMapping)) {
if (null != method.getTagByName(IGNORE)) { if (null != method.getTagByName(IGNORE)) {
continue; continue;