Skip to content

Commit

Permalink
修改checkController方法 报错问题
Browse files Browse the repository at this point in the history
  • Loading branch information
netdied committed May 22, 2021
1 parent e4ba5ec commit 660eb38
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
## smart-doc版本
#### 版本号2.1.9
- 更新日期
- 更新内容
1.添加@JsonProperty支持

#### 版本号:2.1.8

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,6 @@ public interface DocAnnotationConstants {
String JSON_CREATOR = "JsonCreator";

String MAX = "max";

String JSON_PROPERTY = "JsonProperty";
}
8 changes: 8 additions & 0 deletions src/main/java/com/power/doc/constants/DocGlobalConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,12 @@ public interface DocGlobalConstants {
String DUBBO_SWAGGER = "org.apache.dubbo.rpc.protocol.rest.integration.swagger.DubboSwaggerApiListingResource";

String ARRAY = "array";

String JSON_PROPERTY_READ_WRITE = "JsonProperty.Access.READ_WRITE";

String JSON_PROPERTY_READ_ONLY = "JsonProperty.Access.READ_ONLY";

String JSON_PROPERTY_WRITE_ONLY = "JsonProperty.Access.WRITE_ONLY";


}
14 changes: 14 additions & 0 deletions src/main/java/com/power/doc/helper/JsonBuildHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@
import com.power.doc.model.*;
import com.power.doc.utils.*;
import com.thoughtworks.qdox.model.*;
import com.thoughtworks.qdox.model.expression.AnnotationValue;

import java.util.*;

import static com.power.doc.constants.DocGlobalConstants.JSON_PROPERTY_READ_ONLY;
import static com.power.doc.constants.DocGlobalConstants.JSON_PROPERTY_WRITE_ONLY;
import static com.power.doc.constants.DocTags.IGNORE_RESPONSE_BODY_ADVICE;


Expand Down Expand Up @@ -214,6 +217,17 @@ public static String buildJson(String typeName, String genericCanonicalName,
List<JavaAnnotation> annotations = docField.getAnnotations();
for (JavaAnnotation annotation : annotations) {
String annotationName = annotation.getType().getValue();
if(DocAnnotationConstants.JSON_PROPERTY.equalsIgnoreCase(annotationName)){
AnnotationValue value = annotation.getProperty("access");
if(Objects.nonNull(value)){
if(JSON_PROPERTY_READ_ONLY.equals(value.getParameterValue()) && !isResp){
continue out;
}
if(JSON_PROPERTY_WRITE_ONLY.equals(value.getParameterValue()) && isResp){
continue out;
}
}
}
if (DocAnnotationConstants.SHORT_JSON_IGNORE.equals(annotationName)) {
continue out;
} else if (DocAnnotationConstants.SHORT_JSON_FIELD.equals(annotationName)) {
Expand Down
16 changes: 14 additions & 2 deletions src/main/java/com/power/doc/helper/ParamsBuildHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import com.thoughtworks.qdox.model.JavaClass;
import com.thoughtworks.qdox.model.JavaField;
import com.thoughtworks.qdox.model.JavaMethod;
import com.thoughtworks.qdox.model.expression.AnnotationValue;
import org.apache.commons.lang3.StringUtils;

import java.util.*;
Expand Down Expand Up @@ -153,7 +154,7 @@ public static List<ApiParam> buildParams(String className, String pre, int level
CustomField customResponseField = responseFieldMap.get(fieldName);
if (customResponseField != null && JavaClassUtil.isTargetChildClass(simpleName, customResponseField.getOwnerClassName())
&& (customResponseField.isIgnore()) && isResp) {
continue;
continue ;
}
CustomField customRequestField = projectBuilder.getCustomReqFieldMap().get(fieldName);
if (customRequestField != null && JavaClassUtil.isTargetChildClass(simpleName, customRequestField.getOwnerClassName())
Expand All @@ -163,9 +164,20 @@ public static List<ApiParam> buildParams(String className, String pre, int level
an:
for (JavaAnnotation annotation : javaAnnotations) {
String simpleAnnotationName = annotation.getType().getValue();
if ("max".equalsIgnoreCase(simpleAnnotationName)) {
if (DocAnnotationConstants.MAX.equalsIgnoreCase(simpleAnnotationName)) {
maxLength = annotation.getProperty(DocAnnotationConstants.VALUE_PROP).toString();
}
if(DocAnnotationConstants.JSON_PROPERTY.equalsIgnoreCase(simpleAnnotationName)){
AnnotationValue value = annotation.getProperty("access");
if(Objects.nonNull(value)){
if(JSON_PROPERTY_READ_ONLY.equals(value.getParameterValue()) && !isResp){
continue out;
}
if(JSON_PROPERTY_WRITE_ONLY.equals(value.getParameterValue()) && isResp){
continue out;
}
}
}
if (DocAnnotationConstants.SHORT_JSON_IGNORE.equals(simpleAnnotationName)) {
continue out;
} else if (DocAnnotationConstants.SHORT_JSON_FIELD.equals(simpleAnnotationName)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,6 @@ private ApiRequestExample buildReqJson(DocJavaMethod javaMethod, ApiMethodDoc ap
private ApiMethodReqParam requestParams(final DocJavaMethod docJavaMethod, ProjectDocConfigBuilder builder) {
JavaMethod javaMethod = docJavaMethod.getJavaMethod();
boolean isStrict = builder.getApiConfig().isStrict();
Map<String, CustomField> responseFieldMap = new HashMap<>();
String className = javaMethod.getDeclaringClass().getCanonicalName();
Map<String, String> replacementMap = builder.getReplaceClassMap();
Map<String, String> paramTagMap = DocUtil.getParamsComments(javaMethod, DocTags.PARAM, className);
Expand Down Expand Up @@ -828,7 +827,7 @@ private boolean checkController(JavaClass cls) {
}
JavaClass superClass = cls.getSuperJavaClass();
List<JavaAnnotation> classAnnotations = new ArrayList<>();
if (Objects.nonNull(superClass)) {
if(Objects.nonNull(superClass)) {
classAnnotations.addAll(superClass.getAnnotations());
}
classAnnotations.addAll(cls.getAnnotations());
Expand Down

0 comments on commit 660eb38

Please sign in to comment.