diff --git a/CHANGELOG.md b/CHANGELOG.md index 5fe6a04b..c9f365bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,8 @@ ## smart-doc版本 +#### 版本号2.1.9 +- 更新日期 +- 更新内容 + 1.添加@JsonProperty支持 #### 版本号:2.1.8 diff --git a/src/main/java/com/power/doc/constants/DocAnnotationConstants.java b/src/main/java/com/power/doc/constants/DocAnnotationConstants.java index cd63c0e3..a1d85c92 100644 --- a/src/main/java/com/power/doc/constants/DocAnnotationConstants.java +++ b/src/main/java/com/power/doc/constants/DocAnnotationConstants.java @@ -66,4 +66,6 @@ public interface DocAnnotationConstants { String JSON_CREATOR = "JsonCreator"; String MAX = "max"; + + String JSON_PROPERTY = "JsonProperty"; } diff --git a/src/main/java/com/power/doc/constants/DocGlobalConstants.java b/src/main/java/com/power/doc/constants/DocGlobalConstants.java index 45f66385..63f95fe5 100644 --- a/src/main/java/com/power/doc/constants/DocGlobalConstants.java +++ b/src/main/java/com/power/doc/constants/DocGlobalConstants.java @@ -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"; + + } diff --git a/src/main/java/com/power/doc/helper/JsonBuildHelper.java b/src/main/java/com/power/doc/helper/JsonBuildHelper.java index 409c12da..616ace4c 100644 --- a/src/main/java/com/power/doc/helper/JsonBuildHelper.java +++ b/src/main/java/com/power/doc/helper/JsonBuildHelper.java @@ -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; @@ -214,6 +217,17 @@ public static String buildJson(String typeName, String genericCanonicalName, List 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)) { diff --git a/src/main/java/com/power/doc/helper/ParamsBuildHelper.java b/src/main/java/com/power/doc/helper/ParamsBuildHelper.java index 391334f7..6bf9cc1e 100644 --- a/src/main/java/com/power/doc/helper/ParamsBuildHelper.java +++ b/src/main/java/com/power/doc/helper/ParamsBuildHelper.java @@ -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.*; @@ -153,7 +154,7 @@ public static List 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()) @@ -163,9 +164,20 @@ public static List 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)) { diff --git a/src/main/java/com/power/doc/template/SpringBootDocBuildTemplate.java b/src/main/java/com/power/doc/template/SpringBootDocBuildTemplate.java index 49ce501c..d1e10d8c 100644 --- a/src/main/java/com/power/doc/template/SpringBootDocBuildTemplate.java +++ b/src/main/java/com/power/doc/template/SpringBootDocBuildTemplate.java @@ -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 responseFieldMap = new HashMap<>(); String className = javaMethod.getDeclaringClass().getCanonicalName(); Map replacementMap = builder.getReplaceClassMap(); Map paramTagMap = DocUtil.getParamsComments(javaMethod, DocTags.PARAM, className); @@ -828,7 +827,7 @@ private boolean checkController(JavaClass cls) { } JavaClass superClass = cls.getSuperJavaClass(); List classAnnotations = new ArrayList<>(); - if (Objects.nonNull(superClass)) { + if(Objects.nonNull(superClass)) { classAnnotations.addAll(superClass.getAnnotations()); } classAnnotations.addAll(cls.getAnnotations());