提交 34590a24 编写于 作者: 如梦技术's avatar 如梦技术 🐛

mica-swagger 添加 swagger v3 @Tag 支持。

上级 cd4a3f9a
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
package net.dreamlu.mica.swagger.config; package net.dreamlu.mica.swagger.config;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.tags.Tag;
import net.dreamlu.mica.swagger.config.MicaSwaggerProperties.Authorization; import net.dreamlu.mica.swagger.config.MicaSwaggerProperties.Authorization;
import net.dreamlu.mica.swagger.config.MicaSwaggerProperties.GrantTypes; import net.dreamlu.mica.swagger.config.MicaSwaggerProperties.GrantTypes;
import net.dreamlu.mica.swagger.config.MicaSwaggerProperties.Oauth2; import net.dreamlu.mica.swagger.config.MicaSwaggerProperties.Oauth2;
...@@ -30,6 +31,7 @@ import org.springframework.context.annotation.Configuration; ...@@ -30,6 +31,7 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.lang.Nullable; import org.springframework.lang.Nullable;
import org.springframework.util.AntPathMatcher; import org.springframework.util.AntPathMatcher;
import springfox.documentation.RequestHandler;
import springfox.documentation.builders.*; import springfox.documentation.builders.*;
import springfox.documentation.service.*; import springfox.documentation.service.*;
import springfox.documentation.spi.DocumentationType; import springfox.documentation.spi.DocumentationType;
...@@ -65,7 +67,7 @@ public class SwaggerConfiguration { ...@@ -65,7 +67,7 @@ public class SwaggerConfiguration {
.useDefaultResponseMessages(false) .useDefaultResponseMessages(false)
.globalRequestParameters(globalHeaders(properties)) .globalRequestParameters(globalHeaders(properties))
.apiInfo(apiInfo(appName, properties)).select() .apiInfo(apiInfo(appName, properties)).select()
.apis(RequestHandlerSelectors.withClassAnnotation(Api.class)) .apis(SwaggerConfiguration::isSwaggerController)
.paths(PathSelectors.any()) .paths(PathSelectors.any())
.build(); .build();
// 2. 如果开启 apiKey 认证 // 2. 如果开启 apiKey 认证
...@@ -85,6 +87,14 @@ public class SwaggerConfiguration { ...@@ -85,6 +87,14 @@ public class SwaggerConfiguration {
return docket; return docket;
} }
private static boolean isSwaggerController(RequestHandler requestHandler) {
Optional<Api> optional = requestHandler.findControllerAnnotation(Api.class);
if (optional.isPresent()) {
return true;
}
return requestHandler.findControllerAnnotation(Tag.class).isPresent();
}
/** /**
* 配置基于 ApiKey 的鉴权对象 * 配置基于 ApiKey 的鉴权对象
* *
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册