From 332b9f0ac6f35e885d6add737f5adfe2468236ff Mon Sep 17 00:00:00 2001 From: oppofind <836575280@qq.com> Date: Sun, 29 Mar 2020 22:50:23 +0800 Subject: [PATCH] Optimized group verification support --- CHANGELOG.md | 2 +- README.md | 1 + README_CN.md | 4 +++- .../com/power/doc/utils/JavaClassUtil.java | 22 +++++++++++++++---- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 23a1dcb..f975b0c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ - 更新内容: 1. Controller新增时候@ignore tag,可适应该tag忽略不需要生成文档的controller[git #24](https://github.com/smart-doc-group/smart-doc/issues/24)。 2. 参数中包含 HttpSession时smart-doc卡主,[gitee #I1CA9M](https://gitee.com/sunyurepository/smart-doc/issues/I1CA9M) - 3. 增加对代码中@author tag的支持,支持多作者。 + 3. 解决一些复杂分组场景smart-doc报错的问题[gitee #I1CPSM](https://gitee.com/sunyurepository/smart-doc/issues/I1CPSM)。 #### 版本号:1.8.3 - 更新日期: 2020-03-21 - 更新内容: diff --git a/README.md b/README.md index 8c90207..4663e2d 100644 --- a/README.md +++ b/README.md @@ -180,6 +180,7 @@ Thanks to the following people who have submitted major pull requests: - [@su-qiu](https://github.com/su-qiu) - [@qinkangdeid](https://github.com/qinkangdeid) - [@br7roy](https://github.com/br7roy) +- [@caiqyxyx](https://gitee.com/cy-work) ## Other reference - [Smart-doc manual](https://github.com/shalousun/smart-doc/wiki) diff --git a/README_CN.md b/README_CN.md index 851721c..ad79478 100644 --- a/README_CN.md +++ b/README_CN.md @@ -9,7 +9,7 @@ smart-doc完全基于接口源码分析来生成接口文档,完全做到零 - 基于源代码接口定义自动推导,强大的返回结构推导。 - 支持Spring MVC,Spring Boot,Spring Boot Web Flux(controller书写方式)。 - 支持Callable,Future,CompletableFuture等异步接口返回的推导。 -- 支持JavaBean上的JSR303参数校验规范。 +- 支持JavaBean上的JSR303参数校验规范,包括分组验证。 - 对json请求参数的接口能够自动生成模拟json参数。 - 对一些常用字段定义能够生成有效的模拟值。 - 支持生成json返回值示例。 @@ -18,6 +18,7 @@ smart-doc完全基于接口源码分析来生成接口文档,完全做到零 - 轻易实现在Spring Boot服务上在线查看静态HTML5 api文档。 - 开放文档数据,可自由实现接入文档管理系统。 - 支持导出错误码和定义在代码中的各种字典码到接口文档。 +- 支持插件式轻松集成。 ## Getting started smart-doc使用和测试可参考[smart-doc demo](https://gitee.com/sunyurepository/api-doc-test.git)。 ``` @@ -163,6 +164,7 @@ mvn clean install -Dmaven.test.skip=true - [@su-qiu](https://github.com/su-qiu) - [@qinkangdeid](https://github.com/qinkangdeid) - [@br7roy](https://github.com/br7roy) +- [@caiqyxyx](https://gitee.com/cy-work) ## Other reference - [smart-doc功能使用介绍](https://my.oschina.net/u/1760791/blog/2250962) - [smart-doc官方wiki](https://gitee.com/sunyurepository/smart-doc/wikis/Home?sort_id=1652800) diff --git a/src/main/java/com/power/doc/utils/JavaClassUtil.java b/src/main/java/com/power/doc/utils/JavaClassUtil.java index 04feaf2..4ca3c1b 100644 --- a/src/main/java/com/power/doc/utils/JavaClassUtil.java +++ b/src/main/java/com/power/doc/utils/JavaClassUtil.java @@ -223,8 +223,8 @@ public class JavaClassUtil { /** * 通过name获取类标签的value * - * @param cls 类 - * @param tagName 需要获取的标签name + * @param cls 类 + * @param tagName 需要获取的标签name * @param checkComments 检查注释 * @return 类标签的value * @author songhaozhi @@ -267,11 +267,25 @@ public class JavaClassUtil { String simpleName = javaAnnotation.getType().getValue(); if (simpleName.equalsIgnoreCase(ValidatorAnnotations.VALIDATED)) { if (Objects.nonNull(javaAnnotation.getProperty(DocAnnotationConstants.VALUE_PROP))) { - annotationValueList = ((AnnotationValueList) javaAnnotation.getProperty(DocAnnotationConstants.VALUE_PROP)).getValueList(); + AnnotationValue v = javaAnnotation.getProperty(DocAnnotationConstants.VALUE_PROP); + if (v instanceof AnnotationValueList) { + annotationValueList = ((AnnotationValueList) v).getValueList(); + } + if (v instanceof TypeRef) { + annotationValueList = new ArrayList<>(); + annotationValueList.add(v); + } } } else if (validates.contains(simpleName)) { if (Objects.nonNull(javaAnnotation.getProperty(DocAnnotationConstants.GROUP_PROP))) { - annotationValueList = ((AnnotationValueList) javaAnnotation.getProperty(DocAnnotationConstants.GROUP_PROP)).getValueList(); + AnnotationValue v = javaAnnotation.getProperty(DocAnnotationConstants.GROUP_PROP); + if (v instanceof AnnotationValueList) { + annotationValueList = ((AnnotationValueList) v).getValueList(); + } + if (v instanceof TypeRef) { + annotationValueList = new ArrayList<>(); + annotationValueList.add(v); + } } } return annotationValueList;