From 9e6049931c065e6f4cdd7f776718f389a4bc9b44 Mon Sep 17 00:00:00 2001 From: yangzc Date: Fri, 7 Apr 2023 18:25:55 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=94=A8=E6=88=B7=E5=A6=82=E6=9E=9C?= =?UTF-8?q?=E6=B2=A1=E6=9C=89=E5=BC=95=E5=85=A5springfox=E6=97=B6=E8=B7=B3?= =?UTF-8?q?=E8=BF=87ApiIgnore=E7=9B=B8=E5=85=B3=E5=88=A4=E6=96=AD,=20?= =?UTF-8?q?=E5=9B=A0=E4=B8=BA=E8=BF=99=E6=84=8F=E5=91=B3=E7=9D=80=E4=BB=96?= =?UTF-8?q?=E6=9C=AC=E8=BA=AB=E6=B2=A1=E6=9C=89=E4=BD=BF=E7=94=A8springfox?= =?UTF-8?q?=E7=9A=84=E8=87=AA=E5=AE=9A=E4=B9=89=E6=B3=A8=E8=A7=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../swaggerplugin/SwaggerPluginService.java | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/plugin/swagger-plugin/src/main/java/cn/torna/swaggerplugin/SwaggerPluginService.java b/plugin/swagger-plugin/src/main/java/cn/torna/swaggerplugin/SwaggerPluginService.java index f3f12e0c..5207cd22 100644 --- a/plugin/swagger-plugin/src/main/java/cn/torna/swaggerplugin/SwaggerPluginService.java +++ b/plugin/swagger-plugin/src/main/java/cn/torna/swaggerplugin/SwaggerPluginService.java @@ -82,10 +82,17 @@ public class SwaggerPluginService { private final TornaConfig tornaConfig; private final OpenClient client; + private boolean existsApiIgnore = true; public SwaggerPluginService(TornaConfig tornaConfig) { this.tornaConfig = tornaConfig; client = new OpenClient(tornaConfig.getUrl()); + try { + Class.forName("springfox.documentation.annotations.ApiIgnore"); + } catch (ClassNotFoundException e) { + existsApiIgnore = false; + System.out.println("Warning: no 'springfox-core' dependency is imported, 'ApiIgnore' check will be skipped."); + } } public void pushDoc() { @@ -283,12 +290,14 @@ public class SwaggerPluginService { protected DocItem buildDocItem(RequestInfoBuilder requestInfoBuilder) throws HiddenException, IgnoreException { Method method = requestInfoBuilder.getMethod(); ApiOperation apiOperation = method.getAnnotation(ApiOperation.class); - ApiIgnore apiIgnore = method.getAnnotation(ApiIgnore.class); if (apiOperation.hidden()) { throw new HiddenException("Hidden API(@ApiOperation.hidden=true):" + apiOperation.value()); } - if (apiIgnore != null) { - throw new IgnoreException("Ignore API(@ApiIgnore):" + apiOperation.value()); + if (existsApiIgnore) { + ApiIgnore apiIgnore = method.getAnnotation(ApiIgnore.class); + if (apiIgnore != null) { + throw new IgnoreException("Ignore API(@ApiIgnore):" + apiOperation.value()); + } } return doBuildDocItem(requestInfoBuilder); } @@ -837,12 +846,14 @@ public class SwaggerPluginService { private ControllerInfo buildControllerInfo(Class controllerClass) throws HiddenException, IgnoreException { Api api = AnnotationUtils.findAnnotation(controllerClass, Api.class); - ApiIgnore apiIgnore = AnnotationUtils.findAnnotation(controllerClass, ApiIgnore.class); if (api != null && api.hidden()) { throw new HiddenException("Hidden doc(@Api.hidden=true):" + api.value()); } - if (apiIgnore != null) { - throw new IgnoreException("Ignore doc(@ApiIgnore):" + controllerClass.getName()); + if (existsApiIgnore) { + ApiIgnore apiIgnore = AnnotationUtils.findAnnotation(controllerClass, ApiIgnore.class); + if (apiIgnore != null) { + throw new IgnoreException("Ignore doc(@ApiIgnore):" + controllerClass.getName()); + } } String name, description; int position = 0; -- Gitee