diff --git a/README.md b/README.md index d1c9077c..cc5965ea 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ - 提供 lambda 、stream api 、webflux 的生产实践 -部署文档 | 前端解决方案 | 1.0 版本 | PigX在线体验 +部署文档 | 前端解决方案 | 1.0 版本 | PigX在线体验 | PigX白皮书 diff --git a/pig-common/pig-common-swagger/pom.xml b/pig-common/pig-common-swagger/pom.xml new file mode 100644 index 00000000..cbda8e9b --- /dev/null +++ b/pig-common/pig-common-swagger/pom.xml @@ -0,0 +1,50 @@ + + + + + 4.0.0 + + com.pig4cloud + pig-common + 2.5.2.snapshot + + + pig-common-swagger + jar + + pig 接口文档 + + + + + + io.springfox + springfox-swagger2 + ${swagger.fox.version} + + + + com.github.xiaoymin + knife4j-micro-spring-boot-starter + ${knife4j.version} + + + diff --git a/pig-common/pig-common-swagger/src/main/java/com/pig4cloud/pigx/common/swagger/annotation/EnablePigSwagger2.java b/pig-common/pig-common-swagger/src/main/java/com/pig4cloud/pigx/common/swagger/annotation/EnablePigSwagger2.java new file mode 100644 index 00000000..7339b1a4 --- /dev/null +++ b/pig-common/pig-common-swagger/src/main/java/com/pig4cloud/pigx/common/swagger/annotation/EnablePigSwagger2.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pigx.common.swagger.annotation; + +import com.pig4cloud.pigx.common.swagger.config.SwaggerAutoConfiguration; +import org.springframework.context.annotation.Import; + +import java.lang.annotation.*; + +/** + * @author lengleng + * @date 2018/7/21 + * 开启pig swagger + */ +@Target({ElementType.TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@Import({SwaggerAutoConfiguration.class}) +public @interface EnablePigSwagger2 { +} diff --git a/pig-common/pig-common-swagger/src/main/java/com/pig4cloud/pigx/common/swagger/config/SwaggerAutoConfiguration.java b/pig-common/pig-common-swagger/src/main/java/com/pig4cloud/pigx/common/swagger/config/SwaggerAutoConfiguration.java new file mode 100644 index 00000000..e715ffdd --- /dev/null +++ b/pig-common/pig-common-swagger/src/main/java/com/pig4cloud/pigx/common/swagger/config/SwaggerAutoConfiguration.java @@ -0,0 +1,140 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ +package com.pig4cloud.pigx.common.swagger.config; + + +import com.google.common.base.Predicate; +import com.google.common.base.Predicates; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import springfox.documentation.builders.ApiInfoBuilder; +import springfox.documentation.builders.PathSelectors; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.service.*; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spi.service.contexts.SecurityContext; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.annotations.EnableSwagger2; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +/** + * @author lengleng + * swagger配置 + */ +@Configuration +@EnableSwagger2 +@EnableAutoConfiguration +@ConditionalOnProperty(name = "swagger.enabled", matchIfMissing = true) +public class SwaggerAutoConfiguration { + + /** + * 默认的排除路径,排除Spring Boot默认的错误处理路径和端点 + */ + private static final List DEFAULT_EXCLUDE_PATH = Arrays.asList("/error","/actuator/**"); + private static final String BASE_PATH = "/**"; + + @Bean + @ConditionalOnMissingBean + public SwaggerProperties swaggerProperties() { + return new SwaggerProperties(); + } + + @Bean + public Docket api(SwaggerProperties swaggerProperties) { + // base-path处理 + if (swaggerProperties.getBasePath().isEmpty()) { + swaggerProperties.getBasePath().add(BASE_PATH); + } + //noinspection unchecked + List> basePath = new ArrayList(); + swaggerProperties.getBasePath().forEach(path -> basePath.add(PathSelectors.ant(path))); + + // exclude-path处理 + if (swaggerProperties.getExcludePath().isEmpty()) { + swaggerProperties.getExcludePath().addAll(DEFAULT_EXCLUDE_PATH); + } + List> excludePath = new ArrayList<>(); + swaggerProperties.getExcludePath().forEach(path -> excludePath.add(PathSelectors.ant(path))); + + //noinspection Guava + return new Docket(DocumentationType.SWAGGER_2) + .host(swaggerProperties.getHost()) + .apiInfo(apiInfo(swaggerProperties)).select() + .apis(RequestHandlerSelectors.basePackage(swaggerProperties.getBasePackage())) + .paths(Predicates.and(Predicates.not(Predicates.or(excludePath)), Predicates.or(basePath))) + .build() + .securitySchemes(Collections.singletonList(securitySchema())) + .securityContexts(Collections.singletonList(securityContext())) + .pathMapping("/"); + } + + /** + * 配置默认的全局鉴权策略的开关,通过正则表达式进行匹配;默认匹配所有URL + * + * @return + */ + private SecurityContext securityContext() { + return SecurityContext.builder() + .securityReferences(defaultAuth()) + .forPaths(PathSelectors.regex(swaggerProperties().getAuthorization().getAuthRegex())) + .build(); + } + + /** + * 默认的全局鉴权策略 + * + * @return + */ + private List defaultAuth() { + ArrayList authorizationScopeList = new ArrayList<>(); + swaggerProperties().getAuthorization().getAuthorizationScopeList().forEach(authorizationScope -> authorizationScopeList.add(new AuthorizationScope(authorizationScope.getScope(), authorizationScope.getDescription()))); + AuthorizationScope[] authorizationScopes = new AuthorizationScope[authorizationScopeList.size()]; + return Collections.singletonList(SecurityReference.builder() + .reference(swaggerProperties().getAuthorization().getName()) + .scopes(authorizationScopeList.toArray(authorizationScopes)) + .build()); + } + + + private OAuth securitySchema() { + ArrayList authorizationScopeList = new ArrayList<>(); + swaggerProperties().getAuthorization().getAuthorizationScopeList().forEach(authorizationScope -> authorizationScopeList.add(new AuthorizationScope(authorizationScope.getScope(), authorizationScope.getDescription()))); + ArrayList grantTypes = new ArrayList<>(); + swaggerProperties().getAuthorization().getTokenUrlList().forEach(tokenUrl -> grantTypes.add(new ResourceOwnerPasswordCredentialsGrant(tokenUrl))); + return new OAuth(swaggerProperties().getAuthorization().getName(), authorizationScopeList, grantTypes); + } + + private ApiInfo apiInfo(SwaggerProperties swaggerProperties) { + return new ApiInfoBuilder() + .title(swaggerProperties.getTitle()) + .description(swaggerProperties.getDescription()) + .license(swaggerProperties.getLicense()) + .licenseUrl(swaggerProperties.getLicenseUrl()) + .termsOfServiceUrl(swaggerProperties.getTermsOfServiceUrl()) + .contact(new Contact(swaggerProperties.getContact().getName(), swaggerProperties.getContact().getUrl(), swaggerProperties.getContact().getEmail())) + .version(swaggerProperties.getVersion()) + .build(); + } + +} diff --git a/pig-common/pig-common-swagger/src/main/java/com/pig4cloud/pigx/common/swagger/config/SwaggerProperties.java b/pig-common/pig-common-swagger/src/main/java/com/pig4cloud/pigx/common/swagger/config/SwaggerProperties.java new file mode 100644 index 00000000..38468231 --- /dev/null +++ b/pig-common/pig-common-swagger/src/main/java/com/pig4cloud/pigx/common/swagger/config/SwaggerProperties.java @@ -0,0 +1,145 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ +package com.pig4cloud.pigx.common.swagger.config; + +import lombok.Data; +import lombok.NoArgsConstructor; +import org.springframework.boot.context.properties.ConfigurationProperties; + +import java.util.ArrayList; +import java.util.List; + +/** + * SwaggerProperties + * + * @author: lengleng + * @date: 2018/7/25 14:00 + */ +@Data +@ConfigurationProperties("swagger") +public class SwaggerProperties { + /** + * 是否开启swagger + */ + private Boolean enabled; + /** + * swagger会解析的包路径 + **/ + private String basePackage = ""; + /** + * swagger会解析的url规则 + **/ + private List basePath = new ArrayList<>(); + /** + * 在basePath基础上需要排除的url规则 + **/ + private List excludePath = new ArrayList<>(); + /** + * 标题 + **/ + private String title = ""; + /** + * 描述 + **/ + private String description = ""; + /** + * 版本 + **/ + private String version = ""; + /** + * 许可证 + **/ + private String license = ""; + /** + * 许可证URL + **/ + private String licenseUrl = ""; + /** + * 服务条款URL + **/ + private String termsOfServiceUrl = ""; + + /** + * host信息 + **/ + private String host = ""; + /** + * 联系人信息 + */ + private Contact contact = new Contact(); + /** + * 全局统一鉴权配置 + **/ + private Authorization authorization = new Authorization(); + + @Data + @NoArgsConstructor + public static class Contact { + + /** + * 联系人 + **/ + private String name = ""; + /** + * 联系人url + **/ + private String url = ""; + /** + * 联系人email + **/ + private String email = ""; + + } + + @Data + @NoArgsConstructor + public static class Authorization { + + /** + * 鉴权策略ID,需要和SecurityReferences ID保持一致 + */ + private String name = ""; + + /** + * 需要开启鉴权URL的正则 + */ + private String authRegex = "^.*$"; + + /** + * 鉴权作用域列表 + */ + private List authorizationScopeList = new ArrayList<>(); + + private List tokenUrlList = new ArrayList<>(); + } + + @Data + @NoArgsConstructor + public static class AuthorizationScope { + + /** + * 作用域名称 + */ + private String scope = ""; + + /** + * 作用域描述 + */ + private String description = ""; + + } +} diff --git a/pig-common/pom.xml b/pig-common/pom.xml index e144470b..8b608d7b 100755 --- a/pig-common/pom.xml +++ b/pig-common/pom.xml @@ -33,5 +33,6 @@ pig-common-core pig-common-log pig-common-security + pig-common-swagger diff --git a/pig-config/src/main/resources/config/application-dev.yml b/pig-config/src/main/resources/config/application-dev.yml index 5c8facaa..fa7bd2fc 100755 --- a/pig-config/src/main/resources/config/application-dev.yml +++ b/pig-config/src/main/resources/config/application-dev.yml @@ -70,3 +70,21 @@ security: resource: loadBalanced: true token-info-uri: http://pig-auth/oauth/check_token + +# swagger 配置 +swagger: + title: Pig Swagger API + license: Powered By pig4cloud + licenseUrl: https://pig4cloud.com + terms-of-service-url: https://pig4cloud.com + contact: + email: wangiegie@gmail.com + url: https://pig4cloud.com + authorization: + name: pig4cloud OAuth + auth-regex: ^.*$ + authorization-scope-list: + - scope: server + description: server all + token-url-list: + - http://${GATEWAY-HOST:pig-gateway}:${GATEWAY-PORT:9999}/auth/oauth/token diff --git a/pig-config/src/main/resources/config/pig-codegen-dev.yml b/pig-config/src/main/resources/config/pig-codegen-dev.yml index a675d157..271650b7 100755 --- a/pig-config/src/main/resources/config/pig-codegen-dev.yml +++ b/pig-config/src/main/resources/config/pig-codegen-dev.yml @@ -20,4 +20,5 @@ spring: # 直接放行URL ignore: urls: + - /v2/api-docs - /actuator/** diff --git a/pig-config/src/main/resources/config/pig-upms-dev.yml b/pig-config/src/main/resources/config/pig-upms-dev.yml index 28b042c9..e40df853 100755 --- a/pig-config/src/main/resources/config/pig-upms-dev.yml +++ b/pig-config/src/main/resources/config/pig-upms-dev.yml @@ -17,6 +17,7 @@ spring: # 直接放行URL ignore: urls: + - /v2/api-docs - /actuator/** - /user/info/* - /log/** diff --git a/pig-gateway/pom.xml b/pig-gateway/pom.xml index 3932e38f..9587483c 100755 --- a/pig-gateway/pom.xml +++ b/pig-gateway/pom.xml @@ -56,6 +56,17 @@ pig-common-core 2.5.2.snapshot + + + io.springfox + springfox-swagger-ui + ${swagger.fox.version} + + + com.pig4cloud + pig-common-swagger + 2.5.2.snapshot + diff --git a/pig-gateway/src/main/java/com/pig4cloud/pig/gateway/config/RouterFunctionConfiguration.java b/pig-gateway/src/main/java/com/pig4cloud/pig/gateway/config/RouterFunctionConfiguration.java index 2d7f44a3..69747673 100755 --- a/pig-gateway/src/main/java/com/pig4cloud/pig/gateway/config/RouterFunctionConfiguration.java +++ b/pig-gateway/src/main/java/com/pig4cloud/pig/gateway/config/RouterFunctionConfiguration.java @@ -18,6 +18,9 @@ package com.pig4cloud.pig.gateway.config; import com.pig4cloud.pig.gateway.handler.HystrixFallbackHandler; import com.pig4cloud.pig.gateway.handler.ImageCodeHandler; +import com.pig4cloud.pig.gateway.handler.SwaggerResourceHandler; +import com.pig4cloud.pig.gateway.handler.SwaggerSecurityHandler; +import com.pig4cloud.pig.gateway.handler.SwaggerUiHandler; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.context.annotation.Bean; @@ -38,6 +41,10 @@ import org.springframework.web.reactive.function.server.RouterFunctions; public class RouterFunctionConfiguration { private final HystrixFallbackHandler hystrixFallbackHandler; private final ImageCodeHandler imageCodeHandler; + private final SwaggerResourceHandler swaggerResourceHandler; + private final SwaggerSecurityHandler swaggerSecurityHandler; + private final SwaggerUiHandler swaggerUiHandler; + @Bean public RouterFunction routerFunction() { @@ -45,7 +52,13 @@ public class RouterFunctionConfiguration { RequestPredicates.path("/fallback") .and(RequestPredicates.accept(MediaType.TEXT_PLAIN)), hystrixFallbackHandler) .andRoute(RequestPredicates.GET("/code") - .and(RequestPredicates.accept(MediaType.TEXT_PLAIN)), imageCodeHandler); + .and(RequestPredicates.accept(MediaType.TEXT_PLAIN)), imageCodeHandler) + .andRoute(RequestPredicates.GET("/swagger-resources") + .and(RequestPredicates.accept(MediaType.ALL)), swaggerResourceHandler) + .andRoute(RequestPredicates.GET("/swagger-resources/configuration/ui") + .and(RequestPredicates.accept(MediaType.ALL)), swaggerUiHandler) + .andRoute(RequestPredicates.GET("/swagger-resources/configuration/security") + .and(RequestPredicates.accept(MediaType.ALL)), swaggerSecurityHandler); } diff --git a/pig-gateway/src/main/java/com/pig4cloud/pig/gateway/config/SwaggerProviderConfiguration.java b/pig-gateway/src/main/java/com/pig4cloud/pig/gateway/config/SwaggerProviderConfiguration.java new file mode 100644 index 00000000..ed13518d --- /dev/null +++ b/pig-gateway/src/main/java/com/pig4cloud/pig/gateway/config/SwaggerProviderConfiguration.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pig.gateway.config; + +import lombok.AllArgsConstructor; +import org.springframework.cloud.gateway.config.GatewayProperties; +import org.springframework.cloud.gateway.route.RouteLocator; +import org.springframework.cloud.gateway.support.NameUtils; +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; + +/** + * @author lengleng + * @date 2019-11-28 + */ +@Component +@Primary +@AllArgsConstructor +public class SwaggerProviderConfiguration implements SwaggerResourcesProvider { + private static final String API_URI = "/v2/api-docs"; + 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(routeDefinition -> routeDefinition.getPredicates().stream() + .filter(predicateDefinition -> "Path".equalsIgnoreCase(predicateDefinition.getName())) + .filter(predicateDefinition -> !"pig-auth".equalsIgnoreCase(routeDefinition.getId())) + .forEach(predicateDefinition -> resources.add(swaggerResource(routeDefinition.getId(), + predicateDefinition.getArgs().get(NameUtils.GENERATED_NAME_PREFIX + "0") + .replace("/**", API_URI))))); + return resources; + } + + private SwaggerResource swaggerResource(String name, String location) { + SwaggerResource swaggerResource = new SwaggerResource(); + swaggerResource.setName(name); + swaggerResource.setLocation(location); + swaggerResource.setSwaggerVersion("2.0"); + return swaggerResource; + } +} diff --git a/pig-gateway/src/main/java/com/pig4cloud/pig/gateway/handler/SwaggerResourceHandler.java b/pig-gateway/src/main/java/com/pig4cloud/pig/gateway/handler/SwaggerResourceHandler.java new file mode 100644 index 00000000..4ca11831 --- /dev/null +++ b/pig-gateway/src/main/java/com/pig4cloud/pig/gateway/handler/SwaggerResourceHandler.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pig.gateway.handler; + +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Component; +import org.springframework.web.reactive.function.BodyInserters; +import org.springframework.web.reactive.function.server.HandlerFunction; +import org.springframework.web.reactive.function.server.ServerRequest; +import org.springframework.web.reactive.function.server.ServerResponse; +import reactor.core.publisher.Mono; +import springfox.documentation.swagger.web.SwaggerResourcesProvider; + +/** + * @author lengleng + * @date 2018-07-19 + * SwaggerResourceHandler + */ +@Slf4j +@Component +@AllArgsConstructor +public class SwaggerResourceHandler implements HandlerFunction { + private final SwaggerResourcesProvider swaggerResources; + + /** + * Handle the given request. + * + * @param request the request to handler + * @return the response + */ + @Override + public Mono handle(ServerRequest request) { + return ServerResponse.status(HttpStatus.OK) + .contentType(MediaType.APPLICATION_JSON) + .body(BodyInserters.fromValue(swaggerResources.get())); + } +} diff --git a/pig-gateway/src/main/java/com/pig4cloud/pig/gateway/handler/SwaggerSecurityHandler.java b/pig-gateway/src/main/java/com/pig4cloud/pig/gateway/handler/SwaggerSecurityHandler.java new file mode 100644 index 00000000..3c19e900 --- /dev/null +++ b/pig-gateway/src/main/java/com/pig4cloud/pig/gateway/handler/SwaggerSecurityHandler.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pig.gateway.handler; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Component; +import org.springframework.web.reactive.function.BodyInserters; +import org.springframework.web.reactive.function.server.HandlerFunction; +import org.springframework.web.reactive.function.server.ServerRequest; +import org.springframework.web.reactive.function.server.ServerResponse; +import reactor.core.publisher.Mono; +import springfox.documentation.swagger.web.SecurityConfiguration; +import springfox.documentation.swagger.web.SecurityConfigurationBuilder; + +import java.util.Optional; + +/** + * @author lengleng + * @date 2018-07-19 + * SwaggerSecurityHandler + */ +@Slf4j +@Component +public class SwaggerSecurityHandler implements HandlerFunction { + @Autowired(required = false) + private SecurityConfiguration securityConfiguration; + + /** + * Handle the given request. + * + * @param request the request to handler + * @return the response + */ + @Override + public Mono handle(ServerRequest request) { + return ServerResponse.status(HttpStatus.OK) + .contentType(MediaType.APPLICATION_JSON) + .body(BodyInserters.fromValue( + Optional.ofNullable(securityConfiguration) + .orElse(SecurityConfigurationBuilder.builder().build()))); + } +} diff --git a/pig-gateway/src/main/java/com/pig4cloud/pig/gateway/handler/SwaggerUiHandler.java b/pig-gateway/src/main/java/com/pig4cloud/pig/gateway/handler/SwaggerUiHandler.java new file mode 100644 index 00000000..465c756a --- /dev/null +++ b/pig-gateway/src/main/java/com/pig4cloud/pig/gateway/handler/SwaggerUiHandler.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pig.gateway.handler; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Component; +import org.springframework.web.reactive.function.BodyInserters; +import org.springframework.web.reactive.function.server.HandlerFunction; +import org.springframework.web.reactive.function.server.ServerRequest; +import org.springframework.web.reactive.function.server.ServerResponse; +import reactor.core.publisher.Mono; +import springfox.documentation.swagger.web.UiConfiguration; +import springfox.documentation.swagger.web.UiConfigurationBuilder; + +import java.util.Optional; + +/** + * @author lengleng + * @date 2018-07-19 + * SwaggerUiHandler + */ +@Slf4j +@Component +public class SwaggerUiHandler implements HandlerFunction { + @Autowired(required = false) + private UiConfiguration uiConfiguration; + + /** + * Handle the given request. + * + * @param request the request to handler + * @return the response + */ + @Override + public Mono handle(ServerRequest request) { + return ServerResponse.status(HttpStatus.OK) + .contentType(MediaType.APPLICATION_JSON) + .body(BodyInserters.fromValue( + Optional.ofNullable(uiConfiguration) + .orElse(UiConfigurationBuilder.builder().build()))); + } +} diff --git a/pig-upms/pig-upms-biz/pom.xml b/pig-upms/pig-upms-biz/pom.xml index 3b09f375..e44ba9ce 100644 --- a/pig-upms/pig-upms-biz/pom.xml +++ b/pig-upms/pig-upms-biz/pom.xml @@ -48,6 +48,12 @@ pig-common-log 2.5.2.snapshot + + + com.pig4cloud + pig-common-swagger + 2.5.2.snapshot + org.springframework.cloud diff --git a/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/PigAdminApplication.java b/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/PigAdminApplication.java index d4400469..e086b79b 100644 --- a/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/PigAdminApplication.java +++ b/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/PigAdminApplication.java @@ -19,6 +19,7 @@ package com.pig4cloud.pig.admin; import com.pig4cloud.pig.common.security.annotation.EnablePigFeignClients; import com.pig4cloud.pig.common.security.annotation.EnablePigResourceServer; +import com.pig4cloud.pigx.common.swagger.annotation.EnablePigSwagger2; import org.springframework.boot.SpringApplication; import org.springframework.cloud.client.SpringCloudApplication; @@ -27,6 +28,7 @@ import org.springframework.cloud.client.SpringCloudApplication; * @date 2018年06月21日 * 用户统一管理系统 */ +@EnablePigSwagger2 @EnablePigResourceServer @EnablePigFeignClients @SpringCloudApplication diff --git a/pig-upms/pig-upms-biz/src/main/resources/logback-spring.xml b/pig-upms/pig-upms-biz/src/main/resources/logback-spring.xml new file mode 100755 index 00000000..5e2b88bc --- /dev/null +++ b/pig-upms/pig-upms-biz/src/main/resources/logback-spring.xml @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + ${CONSOLE_LOG_PATTERN} + + + + + + ${log.path}/debug.log + + ${log.path}/%d{yyyy-MM, aux}/debug.%d{yyyy-MM-dd}.%i.log.gz + 50MB + 30 + + + %date [%thread] %-5level [%logger{50}] %file:%line - %msg%n + + + + + + ${log.path}/error.log + + ${log.path}/%d{yyyy-MM}/error.%d{yyyy-MM-dd}.%i.log.gz + 50MB + 30 + + + %date [%thread] %-5level [%logger{50}] %file:%line - %msg%n + + + ERROR + + + + + + + + + + diff --git a/pig-visual/pig-codegen/pom.xml b/pig-visual/pig-codegen/pom.xml index bafec15e..b55d22b0 100755 --- a/pig-visual/pig-codegen/pom.xml +++ b/pig-visual/pig-codegen/pom.xml @@ -31,6 +31,12 @@ 代码生成模块 + + + com.pig4cloud + pig-common-swagger + 2.5.2.snapshot + org.springframework.cloud diff --git a/pig-visual/pig-codegen/src/main/java/com/pig4cloud/pig/codegen/PigCodeGenApplication.java b/pig-visual/pig-codegen/src/main/java/com/pig4cloud/pig/codegen/PigCodeGenApplication.java index d5506821..d491179d 100755 --- a/pig-visual/pig-codegen/src/main/java/com/pig4cloud/pig/codegen/PigCodeGenApplication.java +++ b/pig-visual/pig-codegen/src/main/java/com/pig4cloud/pig/codegen/PigCodeGenApplication.java @@ -18,6 +18,7 @@ package com.pig4cloud.pig.codegen; import com.pig4cloud.pig.common.security.annotation.EnablePigFeignClients; import com.pig4cloud.pig.common.security.annotation.EnablePigResourceServer; +import com.pig4cloud.pigx.common.swagger.annotation.EnablePigSwagger2; import org.springframework.boot.SpringApplication; import org.springframework.cloud.client.SpringCloudApplication; @@ -26,6 +27,7 @@ import org.springframework.cloud.client.SpringCloudApplication; * @date 2019/2/1 * 代码生成模块 */ +@EnablePigSwagger2 @EnablePigFeignClients @EnablePigResourceServer @SpringCloudApplication diff --git a/pom.xml b/pom.xml index 9d9c26a8..add4e2de 100755 --- a/pom.xml +++ b/pom.xml @@ -34,7 +34,7 @@ 2.2.1.RELEASE - Hoxton.RC2 + Hoxton.RELEASE Cairo-SR8 UTF-8 1.8 @@ -45,6 +45,8 @@ 0.0.9 1.7 2.1.0 + 2.9.2 + 1.9.6 2.3.6.RELEASE @@ -183,14 +185,6 @@ - - spring-milestones - Spring Milestones - https://repo.spring.io/milestone - - false - - aliyun @@ -204,18 +198,4 @@ - - - - spring-plugin - spring-plugin - https://maven.aliyun.com/repository/spring-plugin - - true - - - false - - -