|
@@ -1,11 +1,14 @@
|
|
|
package com.lantone.qc.kernel.web.config;
|
|
|
|
|
|
|
|
|
+import com.google.common.base.Function;
|
|
|
+import com.google.common.base.Optional;
|
|
|
+import com.google.common.base.Predicate;
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
+import springfox.documentation.RequestHandler;
|
|
|
import springfox.documentation.builders.ApiInfoBuilder;
|
|
|
import springfox.documentation.builders.PathSelectors;
|
|
|
-import springfox.documentation.builders.RequestHandlerSelectors;
|
|
|
import springfox.documentation.service.ApiInfo;
|
|
|
import springfox.documentation.service.Parameter;
|
|
|
import springfox.documentation.spi.DocumentationType;
|
|
@@ -25,6 +28,10 @@ import java.util.List;
|
|
|
//@ConditionalOnProperty(prefix = "swagger", value = { "enable" }, havingValue = "true")
|
|
|
@EnableSwagger2
|
|
|
public class SwaggerConfigurer {
|
|
|
+
|
|
|
+ // 定义分隔符
|
|
|
+ private static final String splitor = ";";
|
|
|
+
|
|
|
/**
|
|
|
* 全局参数
|
|
|
*
|
|
@@ -46,7 +53,10 @@ public class SwaggerConfigurer {
|
|
|
return new Docket(DocumentationType.SWAGGER_2)
|
|
|
.apiInfo(apiInfo())
|
|
|
.select()
|
|
|
- .apis(RequestHandlerSelectors.basePackage("com.lantone.qc.kernel.web"))
|
|
|
+// .apis(RequestHandlerSelectors.basePackage("com.lantone.qc.kernel.web"))
|
|
|
+ .apis(basePackage("com.lantone.qc.kernel.web"
|
|
|
+ + splitor
|
|
|
+ + "com.lantone.qc.dbanaly.controller"))
|
|
|
.paths(PathSelectors.any())
|
|
|
.build().globalOperationParameters(parameter());
|
|
|
//.securitySchemes(newArrayList(oauth()))
|
|
@@ -63,4 +73,25 @@ public class SwaggerConfigurer {
|
|
|
.build();
|
|
|
}
|
|
|
|
|
|
+ public static Predicate<RequestHandler> basePackage(final String basePackage) {
|
|
|
+ return input -> declaringClass(input).transform(handlerPackage(basePackage)).or(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Function<Class<?>, Boolean> handlerPackage(final String basePackage) {
|
|
|
+ return input -> {
|
|
|
+ // 循环判断匹配
|
|
|
+ for (String strPackage : basePackage.split(splitor)) {
|
|
|
+ boolean isMatch = input.getPackage().getName().startsWith(strPackage);
|
|
|
+ if (isMatch) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Optional<? extends Class<?>> declaringClass(RequestHandler input) {
|
|
|
+ return Optional.fromNullable(input.declaringClass());
|
|
|
+ }
|
|
|
+
|
|
|
}
|