Skip to content

Commit

Permalink
fix #337
Browse files Browse the repository at this point in the history
  • Loading branch information
shalousun committed Sep 2, 2022
1 parent 15bf922 commit 47e4b19
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 15 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
## smart-doc版本

### 版本号:2.5.2
- 更新日期: 2022-09-x
- 更新日期: 2022-09-02
- 更新内容:
1. 修复query参数推送到torna被设置到body中,[#336](https://github.com/smart-doc-group/smart-doc/issues/336)
2. 请求头参数支持mock值设置,[#337](https://github.com/smart-doc-group/smart-doc/issues/337)

### 版本号:2.5.1
- 更新日期: 2022-08-27
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@
import com.power.doc.model.ApiReqParam;
import com.power.doc.utils.DocClassUtil;
import com.power.doc.utils.DocUtil;
import com.power.doc.utils.JavaFieldUtil;
import com.thoughtworks.qdox.model.JavaAnnotation;
import com.thoughtworks.qdox.model.JavaMethod;
import com.thoughtworks.qdox.model.JavaParameter;
import com.thoughtworks.qdox.model.JavaType;

import java.util.*;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -80,6 +82,8 @@ public List<ApiReqParam> handle(JavaMethod method, ProjectDocConfigBuilder proje
String className = method.getDeclaringClass().getCanonicalName();
Map<String, String> paramMap = DocUtil.getCommentsByTag(method, DocTags.PARAM, className);
String paramName = javaParameter.getName();
JavaType javaType = javaParameter.getType();
String simpleTypeName = javaType.getValue();
ApiReqParam apiReqHeader;
for (JavaAnnotation annotation : javaAnnotations) {
String annotationName = annotation.getType().getValue();
Expand All @@ -104,7 +108,9 @@ public List<ApiReqParam> handle(JavaMethod method, ProjectDocConfigBuilder proje
}
StringBuilder desc = new StringBuilder();
String comments = paramMap.get(paramName);
desc.append(comments);
desc.append(DocUtil.paramCommentResolve(comments));
String mockValue = JavaFieldUtil.createMockValue(paramMap, paramName, javaType.getGenericCanonicalName(), simpleTypeName);
apiReqHeader.setValue(mockValue);

if (requestHeaderMap.get(DocAnnotationConstants.DEFAULT_VALUE_PROP) != null) {
apiReqHeader.setValue(StringUtil.removeQuotes((String) requestHeaderMap.get(DocAnnotationConstants.DEFAULT_VALUE_PROP)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -806,12 +806,7 @@ private boolean checkController(JavaClass cls) {
if (cls.isAnnotation() || cls.isEnum()) {
return false;
}
JavaClass superClass = cls.getSuperJavaClass();
List<JavaAnnotation> classAnnotations = new ArrayList<>();
if (Objects.nonNull(superClass)) {
classAnnotations.addAll(superClass.getAnnotations());
}
classAnnotations.addAll(cls.getAnnotations());
List<JavaAnnotation> classAnnotations = DocClassUtil.getAnnotations(cls);
for (JavaAnnotation annotation : classAnnotations) {
String annotationName = annotation.getType().getFullyQualifiedName();
if (JakartaJaxrsAnnotations.JAX_PATH_FULLY.equals(annotationName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -797,9 +797,9 @@ private ApiMethodReqParam requestParams(final DocJavaMethod docJavaMethod, Proje
javaType = actualTypesMap.get(javaType.getCanonicalName());
}
String typeName = javaType.getGenericCanonicalName();
String simpleTypeName = javaType.getValue();
String simpleName = javaType.getValue().toLowerCase();
String fullTypeName = javaType.getFullyQualifiedName();
String simpleTypeName = javaType.getValue();
String commentClass = paramTagMap.get(paramName);
String rewriteClassName = getRewriteClassName(replacementMap, fullTypeName, commentClass);
// rewrite class
Expand Down Expand Up @@ -1055,12 +1055,7 @@ private boolean checkController(JavaClass cls) {
if (cls.isAnnotation() || cls.isEnum()) {
return false;
}
JavaClass superClass = cls.getSuperJavaClass();
List<JavaAnnotation> classAnnotations = new ArrayList<>();
if (Objects.nonNull(superClass)) {
classAnnotations.addAll(superClass.getAnnotations());
}
classAnnotations.addAll(cls.getAnnotations());
List<JavaAnnotation> classAnnotations = DocClassUtil.getAnnotations(cls);
for (JavaAnnotation annotation : classAnnotations) {
String name = annotation.getType().getValue();
if (SpringMvcAnnotations.CONTROLLER.equals(name) || SpringMvcAnnotations.REST_CONTROLLER.equals(name)) {
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/com/power/doc/utils/DocClassUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@
import com.power.common.util.StringUtil;
import com.power.doc.filter.ReturnTypeProcessor;
import com.power.doc.model.ApiReturn;
import com.thoughtworks.qdox.model.JavaAnnotation;
import com.thoughtworks.qdox.model.JavaClass;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Stack;

/**
Expand Down Expand Up @@ -292,4 +295,19 @@ private static boolean isClassName(String className) {
}
return stack.isEmpty();
}

/**
* Get class annotations
* @param cls JavaClass
* @return List of JavaAnnotation
*/
public static List<JavaAnnotation> getAnnotations(JavaClass cls) {
JavaClass superClass = cls.getSuperJavaClass();
List<JavaAnnotation> classAnnotations = new ArrayList<>();
if (Objects.nonNull(superClass)) {
classAnnotations.addAll(superClass.getAnnotations());
}
classAnnotations.addAll(cls.getAnnotations());
return classAnnotations;
}
}
12 changes: 12 additions & 0 deletions src/main/java/com/power/doc/utils/DocUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import java.util.stream.Collectors;

import static com.power.doc.constants.DocGlobalConstants.JSON_CONTENT_TYPE;
import static com.power.doc.constants.DocGlobalConstants.NO_COMMENTS_FOUND;

/**
* Description:
Expand Down Expand Up @@ -922,4 +923,15 @@ public static boolean filterPath(RequestMapping requestMapping, ApiReqParam apiR
, apiReqHeader.getExcludePathPatterns());

}

public static String paramCommentResolve(String comment) {
if (StringUtil.isEmpty(comment)) {
comment = NO_COMMENTS_FOUND;
} else {
if (comment.contains("|")) {
comment = comment.substring(0, comment.indexOf("|"));
}
}
return comment;
}
}

0 comments on commit 47e4b19

Please sign in to comment.