diff --git a/CHANGELOG.md b/CHANGELOG.md index bc8cdafb76a0dafe6eb5019035584fc2ace89a62..dd593113b47b6a4fbb4496e4bc9c456294a1d199 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ 4. 切换网关组件为Spring CLoud Gateway 5. 增加nacos_cofig.zip配置,nacos可以一键导入 6. 将file_storage的表file_type修改为file_classify +7. 网关增加聚合接口文档,更方便接口文档的查看和对接 --- ###### v9.0.0-RELEASE diff --git a/roncoo-education-app-gateway/src/main/java/com/roncoo/education/app/gateway/swagger/SwaggerHandler.java b/roncoo-education-app-gateway/src/main/java/com/roncoo/education/app/gateway/swagger/SwaggerHandler.java new file mode 100644 index 0000000000000000000000000000000000000000..b3f1731fe6e6bea7da8f622587a44dd68170afb7 --- /dev/null +++ b/roncoo-education-app-gateway/src/main/java/com/roncoo/education/app/gateway/swagger/SwaggerHandler.java @@ -0,0 +1,50 @@ +package com.roncoo.education.app.gateway.swagger; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; +import reactor.core.publisher.Mono; +import springfox.documentation.swagger.web.*; + +import java.util.Optional; + +@RestController +public class SwaggerHandler { + + @Autowired(required = false) + private SecurityConfiguration securityConfiguration; + + @Autowired(required = false) + private UiConfiguration uiConfiguration; + + private final SwaggerResourcesProvider swaggerResources; + + @Autowired + public SwaggerHandler(SwaggerResourcesProvider swaggerResources) { + this.swaggerResources = swaggerResources; + } + + @GetMapping("/swagger-resources/configuration/security") + public Mono> securityConfiguration() { + return Mono.just( + new ResponseEntity<>( + Optional.ofNullable(securityConfiguration) + .orElse(SecurityConfigurationBuilder.builder().build()), + HttpStatus.OK)); + } + + @GetMapping("/swagger-resources/configuration/ui") + public Mono> uiConfiguration() { + return Mono.just( + new ResponseEntity<>( + Optional.ofNullable(uiConfiguration).orElse(UiConfigurationBuilder.builder().build()), + HttpStatus.OK)); + } + + @GetMapping("/swagger-resources") + public Mono swaggerResources() { + return Mono.just((new ResponseEntity<>(swaggerResources.get(), HttpStatus.OK))); + } +} diff --git a/roncoo-education-app-gateway/src/main/java/com/roncoo/education/app/gateway/swagger/SwaggerResourceConfig.java b/roncoo-education-app-gateway/src/main/java/com/roncoo/education/app/gateway/swagger/SwaggerResourceConfig.java new file mode 100644 index 0000000000000000000000000000000000000000..ff807a340523cddd23f1f374be78e8270c05014d --- /dev/null +++ b/roncoo-education-app-gateway/src/main/java/com/roncoo/education/app/gateway/swagger/SwaggerResourceConfig.java @@ -0,0 +1,47 @@ +package com.roncoo.education.app.gateway.swagger; + +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.cloud.gateway.config.GatewayProperties; +import org.springframework.cloud.gateway.route.RouteLocator; +import org.springframework.context.annotation.Primary; +import org.springframework.stereotype.Component; +import springfox.documentation.swagger.web.SwaggerResource; +import springfox.documentation.swagger.web.SwaggerResourcesProvider; + +import java.util.ArrayList; +import java.util.List; + +@Slf4j +@Component +@Primary +@AllArgsConstructor +public class SwaggerResourceConfig implements SwaggerResourcesProvider { + + private final RouteLocator routeLocator; + private final GatewayProperties gatewayProperties; + + @Override + public List get() { + List resources = new ArrayList<>(); + List routes = new ArrayList<>(); + routeLocator.getRoutes().subscribe(route -> routes.add(route.getId())); + gatewayProperties.getRoutes().stream() + .filter(routeDefinition -> routes.contains(routeDefinition.getId())) + .forEach( + route -> { + route.getPredicates().forEach( + predicateDefinition -> + resources.add(swaggerResource(route.getId(), "/v2/api-docs"))); + }); + return resources; + } + + private SwaggerResource swaggerResource(String name, String location) { + SwaggerResource swaggerResource = new SwaggerResource(); + swaggerResource.setName(name); + swaggerResource.setLocation("/" + name + location); + swaggerResource.setSwaggerVersion("2.0"); + return swaggerResource; + } +} diff --git a/roncoo-education-common/roncoo-education-common-core/src/main/resources/config.properties b/roncoo-education-common/roncoo-education-common-core/src/main/resources/config.properties index 760e18cae7c75d167f2a83bc5051f1e3eb9e7c94..79be1759311e9ab336ff7241885d29227af37850 100644 --- a/roncoo-education-common/roncoo-education-common-core/src/main/resources/config.properties +++ b/roncoo-education-common/roncoo-education-common-core/src/main/resources/config.properties @@ -1,3 +1 @@ env=local -# 环境配置,这里可以放置不同环境的配置 - diff --git a/roncoo-education-common/roncoo-education-common-core/src/main/resources/config/test/config.properties b/roncoo-education-common/roncoo-education-common-core/src/main/resources/config/test/config.properties index c3a03d4a8dbf2a3168d46887b8aa3d41626525d8..0596f6222c3b822a561aebf1149d85829694aa51 100644 --- a/roncoo-education-common/roncoo-education-common-core/src/main/resources/config/test/config.properties +++ b/roncoo-education-common/roncoo-education-common-core/src/main/resources/config/test/config.properties @@ -1,2 +1 @@ env=test -# 测试环境的配置,打包的时候,会根据环境覆盖 diff --git a/roncoo-education-common/roncoo-education-common-core/src/main/resources/system.properties b/roncoo-education-common/roncoo-education-common-core/src/main/resources/system.properties index b5d4dd4fd70ead2d943c807c337f47d777c9867f..52a4cc3515749bf9bc33ee411de3a704480974c1 100644 --- a/roncoo-education-common/roncoo-education-common-core/src/main/resources/system.properties +++ b/roncoo-education-common/roncoo-education-common-core/src/main/resources/system.properties @@ -1,13 +1,13 @@ -# 视频存放路径 +# ?????? period_video_path=/home/roncoo/file/video/ pic_path=/home/roncoo/file/pic/ -#本地上传文档路径 +#???????? doc_storage_path=C:/RonCoo/doc/ -#本地上传路径路径 +#???????? pic_storage_path=C:/RonCoo/pic/ -#测试课程id +#????id test_course=1085453180200448002 -# 保利威视 +# ???? polyv_uploadVideo=http://v.polyv.net/uc/services/rest?method=uploadfile polyv_deleteVideo=http://api.polyv.net/v2/video/{userid}/del-video polyv_question=http://v.polyv.net/uc/services/rest