| | |
| | | * @author ruoyi |
| | | */ |
| | | @Configuration |
| | | public class SwaggerConfig |
| | | { |
| | | public class SwaggerConfig { |
| | | |
| | | /** 系统基础配置 */ |
| | | @Autowired |
| | | private UavConfig uavConfig; |
| | | |
| | | /** |
| | | * 创建API |
| | | */ |
| | | private Docket createApiDocket(ApiGroup apiGroup) { |
| | | return new Docket(DocumentationType.SWAGGER_2) |
| | | .enable(true) |
| | | .groupName(apiGroup.getGroupName()) |
| | | .apiInfo(apiInfo(apiGroup.getTitle())) |
| | | .select() |
| | | .apis(requestHandler -> |
| | | requestHandler.declaringClass().getPackage().getName() |
| | | .startsWith(apiGroup.getPackagePath()) && |
| | | requestHandler.isAnnotatedWith(io.swagger.annotations.ApiOperation.class) |
| | | ) |
| | | .paths(PathSelectors.any()) |
| | | .build() |
| | | .securitySchemes(securitySchemes()) |
| | | .securityContexts(securityContexts()); |
| | | } |
| | | |
| | | @Bean |
| | | public Docket systemApi() { |
| | | return new Docket(DocumentationType.SWAGGER_2) |
| | | .enable(true) |
| | | .groupName("系统接口") // 分组名 |
| | | .apiInfo(apiInfo("系统接口")) |
| | | .select() |
| | | // 扫描指定包下,但只扫描加了 @ApiOperation 注解的方法 |
| | | .apis(requestHandler -> |
| | | requestHandler.declaringClass().getPackage().getName().startsWith("com.ard.web.controller.system") && |
| | | requestHandler.isAnnotatedWith(io.swagger.annotations.ApiOperation.class) |
| | | ) |
| | | .paths(PathSelectors.any()) |
| | | .build() |
| | | /* 设置安全模式,swagger可以设置访问token */ |
| | | .securitySchemes(securitySchemes()) |
| | | .securityContexts(securityContexts()); |
| | | return createApiDocket(ApiGroup.SYSTEM); |
| | | } |
| | | |
| | | @Bean |
| | | public Docket droneApi() { |
| | | return new Docket(DocumentationType.SWAGGER_2) |
| | | .enable(true) |
| | | .groupName("无人机接口") // 分组名 |
| | | .apiInfo(apiInfo("无人机管理接口")) |
| | | .select() |
| | | // 扫描指定包下,但只扫描加了 @ApiOperation 注解的方法 |
| | | .apis(requestHandler -> |
| | | requestHandler.declaringClass().getPackage().getName().startsWith("com.ard.web.controller.work") && |
| | | requestHandler.isAnnotatedWith(io.swagger.annotations.ApiOperation.class) |
| | | ) |
| | | .paths(PathSelectors.any()) |
| | | .build() |
| | | /* 设置安全模式,swagger可以设置访问token */ |
| | | .securitySchemes(securitySchemes()) |
| | | .securityContexts(securityContexts()); |
| | | return createApiDocket(ApiGroup.DRONE); |
| | | } |
| | | |
| | | @Bean |
| | | public Docket sampleApi() { |
| | | return new Docket(DocumentationType.SWAGGER_2) |
| | | .enable(true) |
| | | .groupName("机场接口") // 分组名 |
| | | .apiInfo(apiInfo("机场管理接口")) |
| | | .select() |
| | | // 扫描指定包下,但只扫描加了 @ApiOperation 注解的方法 |
| | | .apis(requestHandler -> |
| | | requestHandler.declaringClass().getPackage().getName().startsWith("com.ard.web.controller" + |
| | | ".sample") && |
| | | requestHandler.isAnnotatedWith(io.swagger.annotations.ApiOperation.class) |
| | | ) |
| | | .paths(PathSelectors.any()) |
| | | .build() |
| | | /* 设置安全模式,swagger可以设置访问token */ |
| | | .securitySchemes(securitySchemes()) |
| | | .securityContexts(securityContexts()); |
| | | return createApiDocket(ApiGroup.SAMPLE); |
| | | } |
| | | |
| | | @Bean |
| | | public Docket mediaMTXApi() { |
| | | return new Docket(DocumentationType.SWAGGER_2) |
| | | .enable(true) |
| | | .groupName("流媒体接口") // 分组名 |
| | | .apiInfo(apiInfo("流媒体管理接口")) |
| | | .select() |
| | | // 扫描指定包下,但只扫描加了 @ApiOperation 注解的方法 |
| | | .apis(requestHandler -> |
| | | requestHandler.declaringClass().getPackage().getName().startsWith("com.ard.web.controller" + |
| | | ".vtdu") && |
| | | requestHandler.isAnnotatedWith(io.swagger.annotations.ApiOperation.class) |
| | | ) |
| | | .paths(PathSelectors.any()) |
| | | .build() |
| | | /* 设置安全模式,swagger可以设置访问token */ |
| | | .securitySchemes(securitySchemes()) |
| | | .securityContexts(securityContexts()); |
| | | return createApiDocket(ApiGroup.MEDIA_MTX); |
| | | } |
| | | |
| | | @Bean |
| | | public Docket deviceApi() { |
| | | return new Docket(DocumentationType.SWAGGER_2) |
| | | .enable(true) |
| | | .groupName("设备接口") // 分组名 |
| | | .apiInfo(apiInfo("设备管理接口")) |
| | | .select() |
| | | // 扫描指定包下,但只扫描加了 @ApiOperation 注解的方法 |
| | | .apis(requestHandler -> |
| | | requestHandler.declaringClass().getPackage().getName().startsWith("com.ard.web.controller" + |
| | | ".device") && |
| | | requestHandler.isAnnotatedWith(io.swagger.annotations.ApiOperation.class) |
| | | ) |
| | | .paths(PathSelectors.any()) |
| | | .build() |
| | | /* 设置安全模式,swagger可以设置访问token */ |
| | | .securitySchemes(securitySchemes()) |
| | | .securityContexts(securityContexts()); |
| | | return createApiDocket(ApiGroup.DEVICE); |
| | | } |
| | | |
| | | @Bean |
| | | public Docket dataApi() { |
| | | return new Docket(DocumentationType.SWAGGER_2) |
| | | .enable(true) |
| | | .groupName("数据接口") // 分组名 |
| | | .apiInfo(apiInfo("数据管理接口")) |
| | | .select() |
| | | // 扫描指定包下,但只扫描加了 @ApiOperation 注解的方法 |
| | | .apis(requestHandler -> |
| | | requestHandler.declaringClass().getPackage().getName().startsWith("com.ard.web.controller" + |
| | | ".data") && |
| | | requestHandler.isAnnotatedWith(io.swagger.annotations.ApiOperation.class) |
| | | ) |
| | | .paths(PathSelectors.any()) |
| | | .build() |
| | | /* 设置安全模式,swagger可以设置访问token */ |
| | | .securitySchemes(securitySchemes()) |
| | | .securityContexts(securityContexts()); |
| | | return createApiDocket(ApiGroup.DATA); |
| | | } |
| | | |
| | | @Bean |
| | | public Docket storageApi() { |
| | | return createApiDocket(ApiGroup.STORAGE); |
| | | } |
| | | |
| | | @Bean |
| | | public Docket routeApi() { |
| | | return createApiDocket(ApiGroup.ROUTE); |
| | | } |
| | | |
| | | /** |
| | | * 安全模式,这里指定token通过Authorization头请求头传递 |
| | | */ |
| | | private List<SecurityScheme> securitySchemes() |
| | | { |
| | | private List<SecurityScheme> securitySchemes() { |
| | | List<SecurityScheme> apiKeyList = new ArrayList<SecurityScheme>(); |
| | | apiKeyList.add(new ApiKey("Authorization", "Authorization", In.HEADER.toValue())); |
| | | return apiKeyList; |
| | |
| | | /** |
| | | * 添加摘要信息 |
| | | */ |
| | | private ApiInfo apiInfo() |
| | | { |
| | | private ApiInfo apiInfo() { |
| | | // 用ApiInfoBuilder进行定制 |
| | | return new ApiInfoBuilder() |
| | | // 设置标题 |