From e96b685fdb1b5293e43f83c1983e44e601c22ad1 Mon Sep 17 00:00:00 2001 From: xingzi <1771761586@qq.com> Date: Thu, 20 Aug 2020 12:46:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=BF=BD=E7=95=A5=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E5=8F=82=E6=95=B0=E7=9A=84=E8=AE=BE=E7=BD=AE=20?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=20@param=20User=20user=E4=BF=A1=E6=81=AF=20@?= =?UTF-8?q?ignore=20=E5=BF=BD=E7=95=A5user=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/power/doc/builder/OpenApiBuilder.java | 2 -- .../power/doc/template/SpringBootDocBuildTemplate.java | 10 ++++++++++ .../java/com/power/doc/utils/ApiParamTreeUtil.java | 3 +++ src/test/java/com/power/doc/ApiDocTest.java | 2 +- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/power/doc/builder/OpenApiBuilder.java b/src/main/java/com/power/doc/builder/OpenApiBuilder.java index c63001b..b4b6c7f 100644 --- a/src/main/java/com/power/doc/builder/OpenApiBuilder.java +++ b/src/main/java/com/power/doc/builder/OpenApiBuilder.java @@ -378,8 +378,6 @@ public class OpenApiBuilder { requiredList.add(param.getField()); } String field = param.getField(); - //去除filed的前缀 - field = field.replaceAll("└─", "").replaceAll(" ", ""); propertiesData.put(field, buildPropertiesData(param)); } diff --git a/src/main/java/com/power/doc/template/SpringBootDocBuildTemplate.java b/src/main/java/com/power/doc/template/SpringBootDocBuildTemplate.java index 16df363..87663d2 100644 --- a/src/main/java/com/power/doc/template/SpringBootDocBuildTemplate.java +++ b/src/main/java/com/power/doc/template/SpringBootDocBuildTemplate.java @@ -47,6 +47,7 @@ import java.util.stream.Stream; import static com.power.doc.constants.DocGlobalConstants.FILE_CONTENT_TYPE; import static com.power.doc.constants.DocGlobalConstants.JSON_CONTENT_TYPE; import static com.power.doc.constants.DocTags.IGNORE; +import static com.power.doc.constants.DocTags.PARAM; /** * @author yu 2019/12/21. @@ -214,12 +215,18 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate { ApiRequestExample requestExample = ApiRequestExample.builder(); out: for (JavaParameter parameter : parameterList) { + JavaType javaType = parameter.getType(); String paramName = parameter.getName(); String typeName = javaType.getFullyQualifiedName(); String gicTypeName = javaType.getGenericCanonicalName(); String rewriteClassName = null; + String commentClass = paramsComments.get(paramName); + //过滤请求参数 + if(Objects.nonNull(commentClass) && commentClass.contains(IGNORE)){ + continue; + } if (Objects.nonNull(commentClass) && !DocGlobalConstants.NO_COMMENTS_FOUND.equals(commentClass)) { String[] comments = commentClass.split("\\|"); rewriteClassName = comments[comments.length - 1]; @@ -424,6 +431,9 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate { out: for (JavaParameter parameter : parameterList) { String paramName = parameter.getName(); + if(Objects.nonNull(paramTagMap.get(paramName)) && paramTagMap.get(paramName).contains(IGNORE)){ + continue; + } if (jsonParamSet.size() > 0 && !jsonParamSet.contains(paramName)) { continue; } diff --git a/src/main/java/com/power/doc/utils/ApiParamTreeUtil.java b/src/main/java/com/power/doc/utils/ApiParamTreeUtil.java index ec9b71a..89736c0 100644 --- a/src/main/java/com/power/doc/utils/ApiParamTreeUtil.java +++ b/src/main/java/com/power/doc/utils/ApiParamTreeUtil.java @@ -18,12 +18,15 @@ public class ApiParamTreeUtil { List params = new ArrayList<>(); // find root for (ApiParam apiParam : apiParamList) { + //去除filed的前缀 + apiParam.setField(apiParam.getField().replaceAll("└─", "").replaceAll(" ", "")); // pid == 0 if (apiParam.getPid() == 0) { params.add(apiParam); } } for (ApiParam apiParam : params) { + //去除filed的前缀 apiParam.setChildren(getChild(apiParam.getId(), apiParamList)); } return params; diff --git a/src/test/java/com/power/doc/ApiDocTest.java b/src/test/java/com/power/doc/ApiDocTest.java index 7eafd68..0f2f7c2 100644 --- a/src/test/java/com/power/doc/ApiDocTest.java +++ b/src/test/java/com/power/doc/ApiDocTest.java @@ -66,7 +66,7 @@ public class ApiDocTest { long start = System.currentTimeMillis(); - OpenApiBuilder.buildOpenApi(config); + // OpenApiBuilder.buildOpenApi(config); HtmlApiDocBuilder.buildApiDoc(config); long end = System.currentTimeMillis(); DateTimeUtil.printRunTime(end, start);