|
@@ -21,6 +21,7 @@ import springfox.documentation.service.SecurityScheme;
|
|
|
import springfox.documentation.spi.DocumentationType;
|
|
|
import springfox.documentation.spi.service.contexts.SecurityContext;
|
|
|
import springfox.documentation.spring.web.plugins.Docket;
|
|
|
+import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;
|
|
|
|
|
|
/**
|
|
|
* Swagger2的接口配置
|
|
@@ -28,6 +29,7 @@ import springfox.documentation.spring.web.plugins.Docket;
|
|
|
* @author ygp
|
|
|
*/
|
|
|
@Configuration
|
|
|
+@EnableSwagger2WebMvc
|
|
|
public class SwaggerConfig
|
|
|
{
|
|
|
/** 系统基础配置 */
|
|
@@ -42,68 +44,109 @@ public class SwaggerConfig
|
|
|
@Value("${swagger.pathMapping}")
|
|
|
private String pathMapping;
|
|
|
|
|
|
- /**
|
|
|
- * 创建API
|
|
|
- */
|
|
|
+
|
|
|
+
|
|
|
@Bean
|
|
|
- public Docket createRestApi()
|
|
|
- {
|
|
|
- return new Docket(DocumentationType.OAS_30)
|
|
|
- // 是否启用Swagger
|
|
|
+ public Docket defaultApi1() {
|
|
|
+ return new Docket(DocumentationType.SWAGGER_2)
|
|
|
+ .enable(enabled)
|
|
|
+ .apiInfo(apiInfo())
|
|
|
+ .groupName("管理端接口")
|
|
|
+ .select()
|
|
|
+ .apis(RequestHandlerSelectors.basePackage("com.qs.mp.web.controller.api.admin"))
|
|
|
+ .paths(PathSelectors.any())
|
|
|
+ .build();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Bean
|
|
|
+ public Docket defaultApi2() {
|
|
|
+ return new Docket(DocumentationType.SWAGGER_2)
|
|
|
.enable(enabled)
|
|
|
- // 用来创建该API的基本信息,展示在文档的页面中(自定义展示的信息)
|
|
|
.apiInfo(apiInfo())
|
|
|
- // 设置哪些接口暴露给Swagger展示
|
|
|
+ .groupName("用户端接口")
|
|
|
.select()
|
|
|
- // 扫描所有有注解的api,用这种方式更灵活
|
|
|
- .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
|
|
|
- // 扫描指定包中的swagger注解
|
|
|
- // .apis(RequestHandlerSelectors.basePackage("com.qs.mp.project.tool.swagger"))
|
|
|
- // 扫描所有 .apis(RequestHandlerSelectors.any())
|
|
|
+ .apis(RequestHandlerSelectors.basePackage("com.qs.mp.web.controller.api.user"))
|
|
|
.paths(PathSelectors.any())
|
|
|
- .build()
|
|
|
- /* 设置安全模式,swagger可以设置访问token */
|
|
|
- .securitySchemes(securitySchemes())
|
|
|
- .securityContexts(securityContexts())
|
|
|
- .pathMapping(pathMapping);
|
|
|
+ .build();
|
|
|
+
|
|
|
}
|
|
|
|
|
|
+ @Bean
|
|
|
+ public Docket defaultApi3() {
|
|
|
+ return new Docket(DocumentationType.SWAGGER_2)
|
|
|
+ .enable(enabled)
|
|
|
+ .apiInfo(apiInfo())
|
|
|
+ .groupName("渠道端接口")
|
|
|
+ .select()
|
|
|
+ .apis(RequestHandlerSelectors.basePackage("com.qs.mp.web.controller.api.channel"))
|
|
|
+ .paths(PathSelectors.any())
|
|
|
+ .build();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
- * 安全模式,这里指定token通过Authorization头请求头传递
|
|
|
+ * 创建API
|
|
|
*/
|
|
|
- private List<SecurityScheme> securitySchemes()
|
|
|
- {
|
|
|
- List<SecurityScheme> apiKeyList = new ArrayList<SecurityScheme>();
|
|
|
- apiKeyList.add(new ApiKey("Authorization", "Authorization", In.HEADER.toValue()));
|
|
|
- return apiKeyList;
|
|
|
- }
|
|
|
+// @Bean
|
|
|
+// public Docket createRestApi()
|
|
|
+// {
|
|
|
+// return new Docket(DocumentationType.SWAGGER_2)
|
|
|
+// // 是否启用Swagger
|
|
|
+// .enable(enabled)
|
|
|
+// // 用来创建该API的基本信息,展示在文档的页面中(自定义展示的信息)
|
|
|
+// .apiInfo(apiInfo())
|
|
|
+// // 设置哪些接口暴露给Swagger展示
|
|
|
+// .select()
|
|
|
+// // 扫描所有有注解的api,用这种方式更灵活
|
|
|
+// .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
|
|
|
+// // 扫描指定包中的swagger注解
|
|
|
+// // .apis(RequestHandlerSelectors.basePackage("com.qs.mp.project.tool.swagger"))
|
|
|
+// // 扫描所有 .apis(RequestHandlerSelectors.any())
|
|
|
+// .paths(PathSelectors.any())
|
|
|
+// .build()
|
|
|
+//
|
|
|
+// .pathMapping(pathMapping);
|
|
|
+// }
|
|
|
|
|
|
/**
|
|
|
- * 安全上下文
|
|
|
+ * 安全模式,这里指定token通过Authorization头请求头传递
|
|
|
*/
|
|
|
- private List<SecurityContext> securityContexts()
|
|
|
- {
|
|
|
- List<SecurityContext> securityContexts = new ArrayList<>();
|
|
|
- securityContexts.add(
|
|
|
- SecurityContext.builder()
|
|
|
- .securityReferences(defaultAuth())
|
|
|
- .operationSelector(o -> o.requestMappingPattern().matches("/.*"))
|
|
|
- .build());
|
|
|
- return securityContexts;
|
|
|
- }
|
|
|
+// private List<SecurityScheme> securitySchemes()
|
|
|
+// {
|
|
|
+// List<SecurityScheme> apiKeyList = new ArrayList<SecurityScheme>();
|
|
|
+// apiKeyList.add(new ApiKey("Authorization", "Authorization", In.HEADER.toValue()));
|
|
|
+// return apiKeyList;
|
|
|
+// }
|
|
|
|
|
|
/**
|
|
|
- * 默认的安全上引用
|
|
|
+ * 安全上下文
|
|
|
*/
|
|
|
- private List<SecurityReference> defaultAuth()
|
|
|
- {
|
|
|
- AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything");
|
|
|
- AuthorizationScope[] authorizationScopes = new AuthorizationScope[1];
|
|
|
- authorizationScopes[0] = authorizationScope;
|
|
|
- List<SecurityReference> securityReferences = new ArrayList<>();
|
|
|
- securityReferences.add(new SecurityReference("Authorization", authorizationScopes));
|
|
|
- return securityReferences;
|
|
|
- }
|
|
|
+// private List<SecurityContext> securityContexts()
|
|
|
+// {
|
|
|
+// List<SecurityContext> securityContexts = new ArrayList<>();
|
|
|
+// securityContexts.add(
|
|
|
+// SecurityContext.builder()
|
|
|
+// .securityReferences(defaultAuth())
|
|
|
+// .operationSelector(o -> o.requestMappingPattern().matches("/.*"))
|
|
|
+// .build());
|
|
|
+// return securityContexts;
|
|
|
+// }
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 默认的安全上引用
|
|
|
+// */
|
|
|
+// private List<SecurityReference> defaultAuth()
|
|
|
+// {
|
|
|
+// AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything");
|
|
|
+// AuthorizationScope[] authorizationScopes = new AuthorizationScope[1];
|
|
|
+// authorizationScopes[0] = authorizationScope;
|
|
|
+// List<SecurityReference> securityReferences = new ArrayList<>();
|
|
|
+// securityReferences.add(new SecurityReference("Authorization", authorizationScopes));
|
|
|
+// return securityReferences;
|
|
|
+// }
|
|
|
|
|
|
/**
|
|
|
* 添加摘要信息
|
|
@@ -113,9 +156,9 @@ public class SwaggerConfig
|
|
|
// 用ApiInfoBuilder进行定制
|
|
|
return new ApiInfoBuilder()
|
|
|
// 设置标题
|
|
|
- .title("标题:旺铺管家_接口文档")
|
|
|
+ .title("标题:盲票_接口文档")
|
|
|
// 描述
|
|
|
- .description("描述:用于管理集团旗下公司的人员信息,具体包括XXX,XXX模块...")
|
|
|
+ .description("描述:用于管理盲票各端接口信息...")
|
|
|
// 作者信息
|
|
|
.contact(new Contact(mpConfig.getName(), null, null))
|
|
|
// 版本
|