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

Merge branch 'mica-v2.4.x'

......@@ -3,7 +3,7 @@
## 说明
`swagger``knife4j` 的封装,方便使用。
**注意**: 添加 `@Api` 注解的控制器会自动暴露给 `swagger`
**注意**: 添加 `@Api` 或 swagger v3 `@Tag` 注解的控制器会自动暴露给 `swagger`
## 使用
### maven
......
......@@ -17,6 +17,7 @@
package net.dreamlu.mica.swagger.config;
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.GrantTypes;
import net.dreamlu.mica.swagger.config.MicaSwaggerProperties.Oauth2;
......@@ -30,6 +31,7 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.lang.Nullable;
import org.springframework.util.AntPathMatcher;
import springfox.documentation.RequestHandler;
import springfox.documentation.builders.*;
import springfox.documentation.service.*;
import springfox.documentation.spi.DocumentationType;
......@@ -65,7 +67,7 @@ public class SwaggerConfiguration {
.useDefaultResponseMessages(false)
.globalRequestParameters(globalHeaders(properties))
.apiInfo(apiInfo(appName, properties)).select()
.apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
.apis(SwaggerConfiguration::isSwaggerController)
.paths(PathSelectors.any())
.build();
// 2. 如果开启 apiKey 认证
......@@ -85,6 +87,14 @@ public class SwaggerConfiguration {
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 的鉴权对象
*
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册