diff --git a/mall-oms/oms-boot/pom.xml b/mall-oms/oms-boot/pom.xml index 41db2efe12084fe8bf4a10bcad21dc446057a714..063adcb7dcd36939b0bf0f31f3c01c780a0bc983 100644 --- a/mall-oms/oms-boot/pom.xml +++ b/mall-oms/oms-boot/pom.xml @@ -48,7 +48,10 @@ test - + + com.github.binarywang + weixin-java-pay + com.youlai @@ -86,13 +89,13 @@ - com.github.binarywang - weixin-java-pay + com.youlai + common-seata com.youlai - common-seata + common-apidoc diff --git a/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/config/SwaggerConfig.java b/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/config/SwaggerConfig.java deleted file mode 100644 index c8c54b870540d33103bf4afd5b1eaa62ea644b79..0000000000000000000000000000000000000000 --- a/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/config/SwaggerConfig.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.youlai.mall.oms.config; - -import io.swagger.v3.oas.models.Components; -import io.swagger.v3.oas.models.OpenAPI; -import io.swagger.v3.oas.models.info.Info; -import io.swagger.v3.oas.models.info.License; -import io.swagger.v3.oas.models.security.OAuthFlows; -import io.swagger.v3.oas.models.security.Scopes; -import io.swagger.v3.oas.models.security.SecurityScheme; -import org.springdoc.core.models.GroupedOpenApi; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * Swagger 配置 - *

- * Spring Doc FAQ: https://springdoc.org/#faq - * - * @author haoxr - * @since 2023/2/17 - */ -@Configuration -public class SwaggerConfig { - - /** - * 认证服务地址 - */ - @Value("${knife4j.oauth2.token-url}") - private String tokenUrl ; - - /** - * 接口信息 - */ - @Bean - public OpenAPI apiInfo() { - return new OpenAPI() - .components(new Components() - .addSecuritySchemes("Authorization", - new SecurityScheme() - .name("Authorization") - .type(SecurityScheme.Type.OAUTH2) - .flows(new OAuthFlows() - .password( - new io.swagger.v3.oas.models.security.OAuthFlow() - .tokenUrl(tokenUrl) - .refreshUrl(tokenUrl) - .scopes( - new Scopes() - .addString("all", "全部权限") - ) - ) - ) - .scheme("bearer") - .in(SecurityScheme.In.HEADER) - .bearerFormat("JWT") - ) - ) - .info(new Info() - .title("订单服务") - .version("3.0.0") - .description("订单、购物车等接口") - .license(new License().name("Apache 2.0") - .url("https://www.apache.org/licenses/LICENSE-2.0")) - ); - } - - -} diff --git a/mall-pms/pms-boot/pom.xml b/mall-pms/pms-boot/pom.xml index b8f3b3e2dc96f313754077dac64ca7edc46ea5e0..fa3dfa9dff9d47bc65a19bcb027b2eea470fac41 100644 --- a/mall-pms/pms-boot/pom.xml +++ b/mall-pms/pms-boot/pom.xml @@ -92,6 +92,11 @@ common-seata + + com.youlai + common-apidoc + + diff --git a/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/config/SwaggerConfig.java b/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/config/SwaggerConfig.java deleted file mode 100644 index 8dfdfa9938fe7cb9c513fcff9859ad5ecb7892f4..0000000000000000000000000000000000000000 --- a/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/config/SwaggerConfig.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.youlai.mall.pms.config; - -import io.swagger.v3.oas.models.Components; -import io.swagger.v3.oas.models.OpenAPI; -import io.swagger.v3.oas.models.info.Info; -import io.swagger.v3.oas.models.info.License; -import io.swagger.v3.oas.models.security.OAuthFlows; -import io.swagger.v3.oas.models.security.Scopes; -import io.swagger.v3.oas.models.security.SecurityScheme; -import org.springdoc.core.models.GroupedOpenApi; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * Swagger 配置 - *

- * Spring Doc FAQ: https://springdoc.org/#faq - * - * @author haoxr - * @since 2023/2/17 - */ -@Configuration -public class SwaggerConfig { - - /** - * 认证服务地址 - */ - @Value("${knife4j.oauth2.token-url}") - private String tokenUrl ; - - /** - * 接口信息 - */ - @Bean - public OpenAPI apiInfo() { - return new OpenAPI() - .components(new Components() - .addSecuritySchemes("Authorization", - new SecurityScheme() - .name("Authorization") - .type(SecurityScheme.Type.OAUTH2) - .flows(new OAuthFlows() - .password( - new io.swagger.v3.oas.models.security.OAuthFlow() - .tokenUrl(tokenUrl) - .refreshUrl(tokenUrl) - .scopes( - new Scopes() - .addString("all", "全部权限") - ) - ) - ) - .scheme("bearer") - .in(SecurityScheme.In.HEADER) - .bearerFormat("JWT") - ) - ) - .info(new Info() - .title("商品服务") - .version("3.0.0") - .description("库存、分类、品牌、规格、参数等接口") - .license(new License().name("Apache 2.0") - .url("https://www.apache.org/licenses/LICENSE-2.0")) - ); - } - - - -} diff --git a/mall-sms/sms-boot/pom.xml b/mall-sms/sms-boot/pom.xml index 4ba08308fa306b4e099259c8fd0fe4f2276e7516..d2584df7c5bdb6a6c07405ee209cb2c6baee519d 100644 --- a/mall-sms/sms-boot/pom.xml +++ b/mall-sms/sms-boot/pom.xml @@ -79,13 +79,13 @@ - org.mapstruct - mapstruct + com.youlai + common-security com.youlai - common-security + common-apidoc diff --git a/mall-sms/sms-boot/src/main/java/com/youlai/mall/sms/config/SwaggerConfig.java b/mall-sms/sms-boot/src/main/java/com/youlai/mall/sms/config/SwaggerConfig.java deleted file mode 100644 index f0403d36426a972df5ec5345fc57c96dfb228390..0000000000000000000000000000000000000000 --- a/mall-sms/sms-boot/src/main/java/com/youlai/mall/sms/config/SwaggerConfig.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.youlai.mall.sms.config; - -import io.swagger.v3.oas.models.Components; -import io.swagger.v3.oas.models.OpenAPI; -import io.swagger.v3.oas.models.info.Info; -import io.swagger.v3.oas.models.info.License; -import io.swagger.v3.oas.models.security.OAuthFlows; -import io.swagger.v3.oas.models.security.Scopes; -import io.swagger.v3.oas.models.security.SecurityScheme; -import org.springdoc.core.models.GroupedOpenApi; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * Swagger 配置 - *

- * Spring Doc FAQ: https://springdoc.org/#faq - * - * @author haoxr - * @since 2023/2/17 - */ -@Configuration -public class SwaggerConfig { - - /** - * 认证服务地址 - */ - @Value("${knife4j.oauth2.token-url}") - private String tokenUrl ; - - /** - * 接口信息 - */ - @Bean - public OpenAPI apiInfo() { - return new OpenAPI() - .components(new Components() - .addSecuritySchemes("Authorization", - new SecurityScheme() - .name("Authorization") - .type(SecurityScheme.Type.OAUTH2) - .flows(new OAuthFlows() - .password( - new io.swagger.v3.oas.models.security.OAuthFlow() - .tokenUrl(tokenUrl) - .refreshUrl(tokenUrl) - .scopes( - new Scopes() - .addString("all", "全部权限") - ) - ) - ) - .scheme("bearer") - .in(SecurityScheme.In.HEADER) - .bearerFormat("JWT") - ) - ) - .info(new Info() - .title("营销服务") - .version("3.0.0") - .description("广告、优惠券等接口") - .license(new License().name("Apache 2.0") - .url("https://www.apache.org/licenses/LICENSE-2.0")) - ); - } - -} diff --git a/mall-ums/ums-boot/pom.xml b/mall-ums/ums-boot/pom.xml index 5331669aaa29671c5247b10f10bc5a9c5c119531..0030b8c88b9e9479fc49dec93ee1b67e671ba86c 100644 --- a/mall-ums/ums-boot/pom.xml +++ b/mall-ums/ums-boot/pom.xml @@ -78,6 +78,11 @@ common-seata + + com.youlai + common-apidoc + + diff --git a/mall-ums/ums-boot/src/main/java/com/youlai/mall/ums/config/SwaggerConfig.java b/mall-ums/ums-boot/src/main/java/com/youlai/mall/ums/config/SwaggerConfig.java deleted file mode 100644 index a1442f631d63196d59a396f6ea7626ea79aa93f7..0000000000000000000000000000000000000000 --- a/mall-ums/ums-boot/src/main/java/com/youlai/mall/ums/config/SwaggerConfig.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.youlai.mall.ums.config; - -import io.swagger.v3.oas.models.Components; -import io.swagger.v3.oas.models.OpenAPI; -import io.swagger.v3.oas.models.info.Info; -import io.swagger.v3.oas.models.info.License; -import io.swagger.v3.oas.models.security.OAuthFlows; -import io.swagger.v3.oas.models.security.Scopes; -import io.swagger.v3.oas.models.security.SecurityScheme; -import org.springdoc.core.models.GroupedOpenApi; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * Swagger 配置 - *

- * Spring Doc FAQ: https://springdoc.org/#faq - * - * @author haoxr - * @since 2023/2/17 - */ -@Configuration -public class SwaggerConfig { - - - /** - * 认证服务地址 - */ - @Value("${knife4j.oauth2.token-url}") - private String tokenUrl ; - - /** - * 接口信息 - */ - @Bean - public OpenAPI apiInfo() { - return new OpenAPI() - .components(new Components() - .addSecuritySchemes("Authorization", - new SecurityScheme() - .name("Authorization") - .type(SecurityScheme.Type.OAUTH2) - .flows(new OAuthFlows() - .password( - new io.swagger.v3.oas.models.security.OAuthFlow() - .tokenUrl(tokenUrl) - .refreshUrl(tokenUrl) - .scopes( - new Scopes() - .addString("all", "全部权限") - ) - ) - ) - .scheme("bearer") - .in(SecurityScheme.In.HEADER) - .bearerFormat("JWT") - ) - ) - .info(new Info() - .title("会员服务") - .version("3.0.0") - .description("会员、地址等接口") - .license(new License().name("Apache 2.0") - .url("https://www.apache.org/licenses/LICENSE-2.0")) - ); - } - -} diff --git a/youlai-auth/src/main/java/com/youlai/auth/config/SwaggerConfig.java b/youlai-auth/src/main/java/com/youlai/auth/config/SwaggerConfig.java deleted file mode 100644 index 39b124dcbf8b52b87cddf63b60558a576d5ebd9b..0000000000000000000000000000000000000000 --- a/youlai-auth/src/main/java/com/youlai/auth/config/SwaggerConfig.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.youlai.auth.config; - -import io.swagger.v3.oas.models.Components; -import io.swagger.v3.oas.models.OpenAPI; -import io.swagger.v3.oas.models.info.Info; -import io.swagger.v3.oas.models.info.License; -import io.swagger.v3.oas.models.security.OAuthFlows; -import io.swagger.v3.oas.models.security.Scopes; -import io.swagger.v3.oas.models.security.SecurityScheme; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * Swagger 配置 - * - * @author haoxr - * @since 2023/2/17 - */ -@Configuration -public class SwaggerConfig { - - /** - * 认证服务地址 - */ - @Value("${knife4j.oauth2.token-url}") - private String tokenUrl ; - - /** - * 接口信息 - */ - @Bean - public OpenAPI apiInfo() { - return new OpenAPI() - .components(new Components() - .addSecuritySchemes("Authorization", - new SecurityScheme() - .name("Authorization") - .type(SecurityScheme.Type.OAUTH2) - .flows(new OAuthFlows() - .password( - new io.swagger.v3.oas.models.security.OAuthFlow() - .tokenUrl(tokenUrl) - .refreshUrl(tokenUrl) - .scopes( - new Scopes() - .addString("all", "全部权限") - ) - ) - ) - .scheme("bearer") - .in(SecurityScheme.In.HEADER) - .bearerFormat("JWT") - ) - ) - .info(new Info() - .title("认证中心") - .version("3.0.0") - .description("认证接口") - .license(new License().name("Apache 2.0") - .url("https://www.apache.org/licenses/LICENSE-2.0")) - ); - } - -} diff --git a/youlai-common/common-apidoc/pom.xml b/youlai-common/common-apidoc/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..7aa31aada90a146b1d072af002ae7840dccf5d71 --- /dev/null +++ b/youlai-common/common-apidoc/pom.xml @@ -0,0 +1,36 @@ + + + 4.0.0 + + com.youlai + youlai-mall + 3.0.0 + ../../pom.xml + + + common-apidoc + + + 17 + 17 + UTF-8 + + + + + + com.github.xiaoymin + knife4j-openapi3-jakarta-spring-boot-starter + + + + + org.springframework.boot + spring-boot-starter-web + + + + + \ No newline at end of file diff --git a/youlai-common/common-apidoc/src/main/java/com/youlai/common/apidoc/config/ApiDocInfoProperties.java b/youlai-common/common-apidoc/src/main/java/com/youlai/common/apidoc/config/ApiDocInfoProperties.java new file mode 100644 index 0000000000000000000000000000000000000000..1b300e5254d5d8db4390f96f0be6ededa46254d5 --- /dev/null +++ b/youlai-common/common-apidoc/src/main/java/com/youlai/common/apidoc/config/ApiDocInfoProperties.java @@ -0,0 +1,73 @@ +package com.youlai.common.apidoc.config; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; + +/** + * API 信息属性 + * + * @author haoxr + * @since 2023/10/30 + */ +@Data +@ConfigurationProperties(prefix = "springdoc.info") +public class ApiDocInfoProperties { + + /** + * API文档标题 + */ + private String title; + + /** + * API文档版本 + */ + private String version; + + /** + * API文档描述 + */ + private String description; + + /** + * 联系人信息 + */ + private Contact contact; + + /** + * 许可证信息 + */ + private License license; + + @Data + public static class Contact { + /** + * 联系人姓名 + */ + private String name; + /** + * 联系人主页 + */ + private String url; + /** + * 联系人邮箱 + */ + private String email; + + } + + /** + * 许可证信息 + */ + @Data + public static class License{ + /** + * 许可证名称 + */ + private String name; + /** + * 许可证URL + */ + private String url; + } + +} diff --git a/youlai-common/common-apidoc/src/main/java/com/youlai/common/apidoc/config/OpenApiConfig.java b/youlai-common/common-apidoc/src/main/java/com/youlai/common/apidoc/config/OpenApiConfig.java new file mode 100644 index 0000000000000000000000000000000000000000..2037c476f05a68c2e3c7e03ade9a99418109d364 --- /dev/null +++ b/youlai-common/common-apidoc/src/main/java/com/youlai/common/apidoc/config/OpenApiConfig.java @@ -0,0 +1,86 @@ +package com.youlai.common.apidoc.config; + +import io.swagger.v3.oas.models.Components; +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.info.Contact; +import io.swagger.v3.oas.models.info.Info; +import io.swagger.v3.oas.models.info.License; +import io.swagger.v3.oas.models.security.OAuthFlow; +import io.swagger.v3.oas.models.security.OAuthFlows; +import io.swagger.v3.oas.models.security.SecurityRequirement; +import io.swagger.v3.oas.models.security.SecurityScheme; +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.HttpHeaders; + +/** + * OpenAPI 配置类 + *

+ * 基于 OpenAPI 3.0 规范 + SpringDoc 实现 + knife4j 增强 + * + * @author haoxr + * @since 3.0.0 + */ +@Configuration +@RequiredArgsConstructor +@EnableConfigurationProperties(ApiDocInfoProperties.class) +public class OpenApiConfig { + + /** + * OAuth2 认证 endpoint + */ + @Value("${spring.security.oauth2.authorizationserver.token-uri}") + private String tokenUrl; + + /** + * API 文档信息属性 + */ + private final ApiDocInfoProperties apiDocInfoProperties; + + + /** + * OpenAPI 配置(元信息、安全协议) + */ + @Bean + public OpenAPI apiInfo() { + return new OpenAPI() + .components(new Components() + .addSecuritySchemes(HttpHeaders.AUTHORIZATION, + new SecurityScheme() + // OAuth2 授权模式 + .type(SecurityScheme.Type.OAUTH2) + .name(HttpHeaders.AUTHORIZATION) + .flows(new OAuthFlows() + .password( + new OAuthFlow() + .tokenUrl(tokenUrl) + .refreshUrl(tokenUrl) + ) + ) + // 安全模式使用Bearer令牌(即JWT) + .in(SecurityScheme.In.HEADER) + .scheme("Bearer") + .bearerFormat("JWT") + ) + ) + // 接口全局添加 Authorization 参数 + .addSecurityItem(new SecurityRequirement().addList(HttpHeaders.AUTHORIZATION)) + // 接口文档信息(不重要) + .info(new Info() + .title(apiDocInfoProperties.getTitle()) + .version(apiDocInfoProperties.getVersion()) + .description(apiDocInfoProperties.getDescription()) + .contact(new Contact() + .name(apiDocInfoProperties.getContact().getName()) + .url(apiDocInfoProperties.getContact().getUrl()) + .email(apiDocInfoProperties.getContact().getEmail()) + ) + .license(new License().name(apiDocInfoProperties.getLicense().getName()) + .url(apiDocInfoProperties.getLicense().getUrl()) + )); + } + +} diff --git a/youlai-common/common-apidoc/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/youlai-common/common-apidoc/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 0000000000000000000000000000000000000000..3af97aff5a7fcef48d9efb6bbc3ff9a231e848b8 --- /dev/null +++ b/youlai-common/common-apidoc/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1 @@ + com.youlai.common.apidoc.config.OpenApiConfig diff --git a/youlai-common/common-web/pom.xml b/youlai-common/common-web/pom.xml index db690160aebaa2ac4f4e44fe17a9b352b373a28b..0ca6148f1d7cbe8844c46d66b0b33d7efbe9ad0d 100644 --- a/youlai-common/common-web/pom.xml +++ b/youlai-common/common-web/pom.xml @@ -12,6 +12,7 @@ common-web + com.youlai common-core @@ -48,12 +49,6 @@ true - - io.swagger.core.v3 - swagger-annotations - - - org.mapstruct mapstruct @@ -69,12 +64,6 @@ spring-boot-starter-validation - - - com.github.xiaoymin - knife4j-openapi3-jakarta-spring-boot-starter - - com.youlai common-security diff --git a/youlai-common/pom.xml b/youlai-common/pom.xml index d70b2f4fdd2926342bbfc2e6fa56aa4719f9d3b7..2f4996656b3dea1c4a3e33114b31cc75c0fb4822 100644 --- a/youlai-common/pom.xml +++ b/youlai-common/pom.xml @@ -14,6 +14,7 @@ pom + common-apidoc common-core common-redis common-web diff --git a/youlai-system/system-boot/pom.xml b/youlai-system/system-boot/pom.xml index 0104061f6d9d45d88fc234a0bee0f24adda5a7bc..e3f02f26ad769536f668f42161206ab6740d4bc2 100644 --- a/youlai-system/system-boot/pom.xml +++ b/youlai-system/system-boot/pom.xml @@ -112,6 +112,11 @@ common-security + + com.youlai + common-apidoc + + diff --git a/youlai-system/system-boot/src/main/java/com/youlai/system/config/SwaggerConfig.java b/youlai-system/system-boot/src/main/java/com/youlai/system/config/SwaggerConfig.java deleted file mode 100644 index 386e97d8be26b35f1c04aa03dd3486598b524128..0000000000000000000000000000000000000000 --- a/youlai-system/system-boot/src/main/java/com/youlai/system/config/SwaggerConfig.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.youlai.system.config; - -import io.swagger.v3.oas.models.Components; -import io.swagger.v3.oas.models.OpenAPI; -import io.swagger.v3.oas.models.info.Info; -import io.swagger.v3.oas.models.info.License; -import io.swagger.v3.oas.models.security.OAuthFlows; -import io.swagger.v3.oas.models.security.Scopes; -import io.swagger.v3.oas.models.security.SecurityScheme; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * Swagger 配置 - * - * @author haoxr - * @since 3.0.0 - */ -@Configuration -public class SwaggerConfig { - - /** - * 认证服务地址 - */ - @Value("${knife4j.oauth2.token-url}") - private String tokenUrl ; - - /** - * 接口信息 - */ - @Bean - public OpenAPI apiInfo() { - return new OpenAPI() - .components(new Components() - .addSecuritySchemes("Authorization", - new SecurityScheme() - .name("Authorization") - .type(SecurityScheme.Type.OAUTH2) - .flows(new OAuthFlows() - .password( - new io.swagger.v3.oas.models.security.OAuthFlow() - .tokenUrl(tokenUrl) - .refreshUrl(tokenUrl) - .scopes( - new Scopes() - .addString("all", "全部权限") - ) - ) - ) - .scheme("bearer") - .in(SecurityScheme.In.HEADER) - .bearerFormat("JWT") - ) - ) - .info(new Info() - .title("系统服务") - .version("3.0.0") - .description("用户、角色、菜单、部门、字典等接口") - .license(new License().name("Apache 2.0") - .url("https://www.apache.org/licenses/LICENSE-2.0")) - ); - } - - -}