Procházet zdrojové kódy

使用SpringDoc代替Swagger

RuoYi před 1 rokem
rodič
revize
3b499b1344
27 změnil soubory, kde provedl 319 přidání a 774 odebrání
  1. 2 2
      docker/copy.sh
  2. 5 11
      pom.xml
  3. 0 6
      ruoyi-common/ruoyi-common-core/pom.xml
  4. 3 4
      ruoyi-common/ruoyi-common-swagger/pom.xml
  5. 0 20
      ruoyi-common/ruoyi-common-swagger/src/main/java/com/ruoyi/common/swagger/annotation/EnableCustomSwagger2.java
  6. 63 0
      ruoyi-common/ruoyi-common-swagger/src/main/java/com/ruoyi/common/swagger/config/SpringDocAutoConfiguration.java
  7. 0 123
      ruoyi-common/ruoyi-common-swagger/src/main/java/com/ruoyi/common/swagger/config/SwaggerAutoConfiguration.java
  8. 0 52
      ruoyi-common/ruoyi-common-swagger/src/main/java/com/ruoyi/common/swagger/config/SwaggerBeanPostProcessor.java
  9. 0 343
      ruoyi-common/ruoyi-common-swagger/src/main/java/com/ruoyi/common/swagger/config/SwaggerProperties.java
  10. 0 20
      ruoyi-common/ruoyi-common-swagger/src/main/java/com/ruoyi/common/swagger/config/SwaggerWebConfiguration.java
  11. 135 0
      ruoyi-common/ruoyi-common-swagger/src/main/java/com/ruoyi/common/swagger/config/properties/SpringDocProperties.java
  12. 1 3
      ruoyi-common/ruoyi-common-swagger/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
  13. 4 9
      ruoyi-gateway/pom.xml
  14. 93 0
      ruoyi-gateway/src/main/java/com/ruoyi/gateway/config/SpringDocConfig.java
  15. 0 79
      ruoyi-gateway/src/main/java/com/ruoyi/gateway/config/SwaggerProvider.java
  16. 1 1
      ruoyi-gateway/src/main/java/com/ruoyi/gateway/filter/AuthFilter.java
  17. 0 56
      ruoyi-gateway/src/main/java/com/ruoyi/gateway/handler/SwaggerHandler.java
  18. 6 6
      ruoyi-modules/ruoyi-file/pom.xml
  19. 0 2
      ruoyi-modules/ruoyi-file/src/main/java/com/ruoyi/file/RuoYiFileApplication.java
  20. 0 7
      ruoyi-modules/ruoyi-gen/pom.xml
  21. 0 2
      ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/RuoYiGenApplication.java
  22. 0 1
      ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/domain/GenTableColumn.java
  23. 1 8
      ruoyi-modules/ruoyi-job/pom.xml
  24. 0 2
      ruoyi-modules/ruoyi-job/src/main/java/com/ruoyi/job/RuoYiJobApplication.java
  25. 1 8
      ruoyi-modules/ruoyi-system/pom.xml
  26. 0 2
      ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/RuoYiSystemApplication.java
  27. 4 7
      sql/ry_config_20240829.sql

+ 2 - 2
docker/copy.sh

@@ -9,8 +9,8 @@ usage() {
 
 # copy sql
 echo "begin copy sql "
-cp ../sql/ry_20231130.sql ./mysql/db
-cp ../sql/ry_config_20231204.sql ./mysql/db
+cp ../sql/ry_20240629.sql ./mysql/db
+cp ../sql/ry_config_20240829.sql ./mysql/db
 
 # copy html
 echo "begin copy html "

+ 5 - 11
pom.xml

@@ -22,8 +22,6 @@
         <spring-cloud-alibaba.version>2021.0.5.0</spring-cloud-alibaba.version>
         <spring-framework.version>5.3.33</spring-framework.version>
         <spring-boot-admin.version>2.7.15</spring-boot-admin.version>
-        <swagger.fox.version>3.0.0</swagger.fox.version>
-        <swagger.core.version>1.6.2</swagger.core.version>
         <tobato.version>1.27.2</tobato.version>
         <kaptcha.version>2.3.3</kaptcha.version>
         <pagehelper.boot.version>2.0.0</pagehelper.boot.version>
@@ -35,6 +33,7 @@
         <jjwt.version>0.9.1</jjwt.version>
         <minio.version>8.2.2</minio.version>
         <poi.version>4.1.2</poi.version>
+        <springdoc.version>1.6.9</springdoc.version>
         <transmittable-thread-local.version>2.14.4</transmittable-thread-local.version>
     </properties>
 
@@ -85,16 +84,11 @@
                 <version>${tobato.version}</version>
             </dependency>
 
-            <!-- Swagger 依赖配置 -->
+            <!-- Springdoc webmvc 依赖配置 -->
             <dependency>
-                <groupId>io.swagger</groupId>
-                <artifactId>swagger-models</artifactId>
-                <version>${swagger.core.version}</version>
-            </dependency>
-            <dependency>
-                <groupId>io.swagger</groupId>
-                <artifactId>swagger-annotations</artifactId>
-                <version>${swagger.core.version}</version>
+                <groupId>org.springdoc</groupId>
+                <artifactId>springdoc-openapi-ui</artifactId>
+                <version>${springdoc.version}</version>
             </dependency>
 
             <!-- 验证码 -->

+ 0 - 6
ruoyi-common/ruoyi-common-core/pom.xml

@@ -107,12 +107,6 @@
             <artifactId>javax.servlet-api</artifactId>
         </dependency>
 
-        <!-- Swagger -->
-        <dependency>
-            <groupId>io.swagger</groupId>
-            <artifactId>swagger-annotations</artifactId>
-        </dependency>
-
     </dependencies>
 
 </project>

+ 3 - 4
ruoyi-common/ruoyi-common-swagger/pom.xml

@@ -23,11 +23,10 @@
             <artifactId>spring-boot-starter-web</artifactId>
         </dependency>
 
-        <!-- Swagger -->
+        <!-- SpringDoc webmvc -->
         <dependency>
-            <groupId>io.springfox</groupId>
-            <artifactId>springfox-swagger2</artifactId>
-            <version>${swagger.fox.version}</version>
+            <groupId>org.springdoc</groupId>
+            <artifactId>springdoc-openapi-ui</artifactId>
         </dependency>
 
 	</dependencies>

+ 0 - 20
ruoyi-common/ruoyi-common-swagger/src/main/java/com/ruoyi/common/swagger/annotation/EnableCustomSwagger2.java

@@ -1,20 +0,0 @@
-package com.ruoyi.common.swagger.annotation;
-
-import java.lang.annotation.Documented;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Inherited;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-import org.springframework.context.annotation.Import;
-import com.ruoyi.common.swagger.config.SwaggerAutoConfiguration;
-
-@Target({ ElementType.TYPE })
-@Retention(RetentionPolicy.RUNTIME)
-@Documented
-@Inherited
-@Import({ SwaggerAutoConfiguration.class })
-public @interface EnableCustomSwagger2
-{
-
-}

+ 63 - 0
ruoyi-common/ruoyi-common-swagger/src/main/java/com/ruoyi/common/swagger/config/SpringDocAutoConfiguration.java

@@ -0,0 +1,63 @@
+package com.ruoyi.common.swagger.config;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import com.ruoyi.common.swagger.config.properties.SpringDocProperties;
+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.security.SecurityRequirement;
+import io.swagger.v3.oas.models.security.SecurityScheme;
+import io.swagger.v3.oas.models.servers.Server;
+
+/**
+ * Swagger 文档配置
+ *
+ * @author ruoyi
+ */
+@EnableConfigurationProperties(SpringDocProperties.class)
+@ConditionalOnProperty(name = "springdoc.api-docs.enabled", havingValue = "true", matchIfMissing = true)
+public class SpringDocAutoConfiguration
+{
+    @Bean
+    @ConditionalOnMissingBean(OpenAPI.class)
+    public OpenAPI openApi(SpringDocProperties properties)
+    {
+        return new OpenAPI().components(new Components()
+            // 设置认证的请求头
+            .addSecuritySchemes("apikey", securityScheme()))
+            .addSecurityItem(new SecurityRequirement().addList("apikey"))
+            .info(convertInfo(properties.getInfo()))
+            .servers(servers(properties.getGatewayUrl()));
+    }
+
+    public SecurityScheme securityScheme()
+    {
+        return new SecurityScheme().type(SecurityScheme.Type.APIKEY)
+            .name("Authorization")
+            .in(SecurityScheme.In.HEADER)
+            .scheme("Bearer");
+    }
+
+    private Info convertInfo(SpringDocProperties.InfoProperties infoProperties)
+    {
+        Info info = new Info();
+        info.setTitle(infoProperties.getTitle());
+        info.setDescription(infoProperties.getDescription());
+        info.setContact(infoProperties.getContact());
+        info.setLicense(infoProperties.getLicense());
+        info.setVersion(infoProperties.getVersion());
+        return info;
+    }
+
+    public List<Server> servers(String gatewayUrl)
+    {
+        List<Server> serverList = new ArrayList<>();
+        serverList.add(new Server().url(gatewayUrl));
+        return serverList;
+    }
+}

+ 0 - 123
ruoyi-common/ruoyi-common-swagger/src/main/java/com/ruoyi/common/swagger/config/SwaggerAutoConfiguration.java

@@ -1,123 +0,0 @@
-package com.ruoyi.common.swagger.config;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.function.Predicate;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
-import org.springframework.boot.context.properties.EnableConfigurationProperties;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.Import;
-import springfox.documentation.builders.ApiInfoBuilder;
-import springfox.documentation.builders.PathSelectors;
-import springfox.documentation.builders.RequestHandlerSelectors;
-import springfox.documentation.service.ApiInfo;
-import springfox.documentation.service.ApiKey;
-import springfox.documentation.service.AuthorizationScope;
-import springfox.documentation.service.Contact;
-import springfox.documentation.service.SecurityReference;
-import springfox.documentation.service.SecurityScheme;
-import springfox.documentation.spi.DocumentationType;
-import springfox.documentation.spi.service.contexts.SecurityContext;
-import springfox.documentation.spring.web.plugins.ApiSelectorBuilder;
-import springfox.documentation.spring.web.plugins.Docket;
-import springfox.documentation.swagger2.annotations.EnableSwagger2;
-
-@Configuration
-@EnableSwagger2
-@EnableConfigurationProperties(SwaggerProperties.class)
-@ConditionalOnProperty(name = "swagger.enabled", matchIfMissing = true)
-@Import({SwaggerBeanPostProcessor.class, SwaggerWebConfiguration.class})
-public class SwaggerAutoConfiguration
-{
-    /**
-     * 默认的排除路径,排除Spring Boot默认的错误处理路径和端点
-     */
-    private static final List<String> DEFAULT_EXCLUDE_PATH = Arrays.asList("/error", "/actuator/**");
-
-    private static final String BASE_PATH = "/**";
-
-    @Bean
-    public Docket api(SwaggerProperties swaggerProperties)
-    {
-        // base-path处理
-        if (swaggerProperties.getBasePath().isEmpty())
-        {
-            swaggerProperties.getBasePath().add(BASE_PATH);
-        }
-        // noinspection unchecked
-        List<Predicate<String>> basePath = new ArrayList<Predicate<String>>();
-        swaggerProperties.getBasePath().forEach(path -> basePath.add(PathSelectors.ant(path)));
-
-        // exclude-path处理
-        if (swaggerProperties.getExcludePath().isEmpty())
-        {
-            swaggerProperties.getExcludePath().addAll(DEFAULT_EXCLUDE_PATH);
-        }
-
-        List<Predicate<String>> excludePath = new ArrayList<>();
-        swaggerProperties.getExcludePath().forEach(path -> excludePath.add(PathSelectors.ant(path)));
-
-        ApiSelectorBuilder builder = new Docket(DocumentationType.SWAGGER_2).host(swaggerProperties.getHost())
-                .apiInfo(apiInfo(swaggerProperties)).select()
-                .apis(RequestHandlerSelectors.basePackage(swaggerProperties.getBasePackage()));
-
-        swaggerProperties.getBasePath().forEach(p -> builder.paths(PathSelectors.ant(p)));
-        swaggerProperties.getExcludePath().forEach(p -> builder.paths(PathSelectors.ant(p).negate()));
-
-        return builder.build().securitySchemes(securitySchemes()).securityContexts(securityContexts()).pathMapping("/");
-    }
-
-    /**
-     * 安全模式,这里指定token通过Authorization头请求头传递
-     */
-    private List<SecurityScheme> securitySchemes()
-    {
-        List<SecurityScheme> apiKeyList = new ArrayList<SecurityScheme>();
-        apiKeyList.add(new ApiKey("Authorization", "Authorization", "header"));
-        return apiKeyList;
-    }
-
-    /**
-     * 安全上下文
-     */
-    private List<SecurityContext> securityContexts()
-    {
-        List<SecurityContext> securityContexts = new ArrayList<>();
-        securityContexts.add(
-                SecurityContext.builder()
-                        .securityReferences(defaultAuth())
-                        .operationSelector(o -> o.requestMappingPattern().matches("/.*"))
-                        .build());
-        return securityContexts;
-    }
-
-    /**
-     * 默认的全局鉴权策略
-     *
-     * @return
-     */
-    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 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();
-    }
-}

+ 0 - 52
ruoyi-common/ruoyi-common-swagger/src/main/java/com/ruoyi/common/swagger/config/SwaggerBeanPostProcessor.java

@@ -1,52 +0,0 @@
-package com.ruoyi.common.swagger.config;
-
-import org.springframework.beans.BeansException;
-import org.springframework.beans.factory.config.BeanPostProcessor;
-import org.springframework.util.ReflectionUtils;
-import org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping;
-import springfox.documentation.spring.web.plugins.WebFluxRequestHandlerProvider;
-import springfox.documentation.spring.web.plugins.WebMvcRequestHandlerProvider;
-import java.lang.reflect.Field;
-import java.util.List;
-import java.util.stream.Collectors;
-
-/**
- * swagger 在 springboot 2.6.x 不兼容问题的处理
- *
- * @author ruoyi
- */
-public class SwaggerBeanPostProcessor implements BeanPostProcessor
-{
-    @Override
-    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException
-    {
-        if (bean instanceof WebMvcRequestHandlerProvider || bean instanceof WebFluxRequestHandlerProvider)
-        {
-            customizeSpringfoxHandlerMappings(getHandlerMappings(bean));
-        }
-        return bean;
-    }
-
-    private <T extends RequestMappingInfoHandlerMapping> void customizeSpringfoxHandlerMappings(List<T> mappings)
-    {
-        List<T> copy = mappings.stream().filter(mapping -> mapping.getPatternParser() == null)
-                .collect(Collectors.toList());
-        mappings.clear();
-        mappings.addAll(copy);
-    }
-
-    @SuppressWarnings("unchecked")
-    private List<RequestMappingInfoHandlerMapping> getHandlerMappings(Object bean)
-    {
-        try
-        {
-            Field field = ReflectionUtils.findField(bean.getClass(), "handlerMappings");
-            field.setAccessible(true);
-            return (List<RequestMappingInfoHandlerMapping>) field.get(bean);
-        }
-        catch (IllegalArgumentException | IllegalAccessException e)
-        {
-            throw new IllegalStateException(e);
-        }
-    }
-}

+ 0 - 343
ruoyi-common/ruoyi-common-swagger/src/main/java/com/ruoyi/common/swagger/config/SwaggerProperties.java

@@ -1,343 +0,0 @@
-package com.ruoyi.common.swagger.config;
-
-import java.util.ArrayList;
-import java.util.List;
-import org.springframework.boot.context.properties.ConfigurationProperties;
-
-@ConfigurationProperties("swagger")
-public class SwaggerProperties
-{
-    /**
-     * 是否开启swagger
-     */
-    private Boolean enabled;
-
-    /**
-     * swagger会解析的包路径
-     **/
-    private String basePackage = "";
-
-    /**
-     * swagger会解析的url规则
-     **/
-    private List<String> basePath = new ArrayList<>();
-
-    /**
-     * 在basePath基础上需要排除的url规则
-     **/
-    private List<String> 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();
-
-    public Boolean getEnabled()
-    {
-        return enabled;
-    }
-
-    public void setEnabled(Boolean enabled)
-    {
-        this.enabled = enabled;
-    }
-
-    public String getBasePackage()
-    {
-        return basePackage;
-    }
-
-    public void setBasePackage(String basePackage)
-    {
-        this.basePackage = basePackage;
-    }
-
-    public List<String> getBasePath()
-    {
-        return basePath;
-    }
-
-    public void setBasePath(List<String> basePath)
-    {
-        this.basePath = basePath;
-    }
-
-    public List<String> getExcludePath()
-    {
-        return excludePath;
-    }
-
-    public void setExcludePath(List<String> excludePath)
-    {
-        this.excludePath = excludePath;
-    }
-
-    public String getTitle()
-    {
-        return title;
-    }
-
-    public void setTitle(String title)
-    {
-        this.title = title;
-    }
-
-    public String getDescription()
-    {
-        return description;
-    }
-
-    public void setDescription(String description)
-    {
-        this.description = description;
-    }
-
-    public String getVersion()
-    {
-        return version;
-    }
-
-    public void setVersion(String version)
-    {
-        this.version = version;
-    }
-
-    public String getLicense()
-    {
-        return license;
-    }
-
-    public void setLicense(String license)
-    {
-        this.license = license;
-    }
-
-    public String getLicenseUrl()
-    {
-        return licenseUrl;
-    }
-
-    public void setLicenseUrl(String licenseUrl)
-    {
-        this.licenseUrl = licenseUrl;
-    }
-
-    public String getTermsOfServiceUrl()
-    {
-        return termsOfServiceUrl;
-    }
-
-    public void setTermsOfServiceUrl(String termsOfServiceUrl)
-    {
-        this.termsOfServiceUrl = termsOfServiceUrl;
-    }
-
-    public String getHost()
-    {
-        return host;
-    }
-
-    public void setHost(String host)
-    {
-        this.host = host;
-    }
-
-    public Contact getContact()
-    {
-        return contact;
-    }
-
-    public void setContact(Contact contact)
-    {
-        this.contact = contact;
-    }
-
-    public Authorization getAuthorization()
-    {
-        return authorization;
-    }
-
-    public void setAuthorization(Authorization authorization)
-    {
-        this.authorization = authorization;
-    }
-
-    public static class Contact
-    {
-        /**
-         * 联系人
-         **/
-        private String name = "";
-        /**
-         * 联系人url
-         **/
-        private String url = "";
-        /**
-         * 联系人email
-         **/
-        private String email = "";
-
-        public String getName()
-        {
-            return name;
-        }
-
-        public void setName(String name)
-        {
-            this.name = name;
-        }
-
-        public String getUrl()
-        {
-            return url;
-        }
-
-        public void setUrl(String url)
-        {
-            this.url = url;
-        }
-
-        public String getEmail()
-        {
-            return email;
-        }
-
-        public void setEmail(String email)
-        {
-            this.email = email;
-        }
-    }
-
-    public static class Authorization
-    {
-        /**
-         * 鉴权策略ID,需要和SecurityReferences ID保持一致
-         */
-        private String name = "";
-
-        /**
-         * 需要开启鉴权URL的正则
-         */
-        private String authRegex = "^.*$";
-
-        /**
-         * 鉴权作用域列表
-         */
-        private List<AuthorizationScope> authorizationScopeList = new ArrayList<>();
-
-        private List<String> tokenUrlList = new ArrayList<>();
-
-        public String getName()
-        {
-            return name;
-        }
-
-        public void setName(String name)
-        {
-            this.name = name;
-        }
-
-        public String getAuthRegex()
-        {
-            return authRegex;
-        }
-
-        public void setAuthRegex(String authRegex)
-        {
-            this.authRegex = authRegex;
-        }
-
-        public List<AuthorizationScope> getAuthorizationScopeList()
-        {
-            return authorizationScopeList;
-        }
-
-        public void setAuthorizationScopeList(List<AuthorizationScope> authorizationScopeList)
-        {
-            this.authorizationScopeList = authorizationScopeList;
-        }
-
-        public List<String> getTokenUrlList()
-        {
-            return tokenUrlList;
-        }
-
-        public void setTokenUrlList(List<String> tokenUrlList)
-        {
-            this.tokenUrlList = tokenUrlList;
-        }
-    }
-
-    public static class AuthorizationScope
-    {
-        /**
-         * 作用域名称
-         */
-        private String scope = "";
-
-        /**
-         * 作用域描述
-         */
-        private String description = "";
-
-        public String getScope()
-        {
-            return scope;
-        }
-
-        public void setScope(String scope)
-        {
-            this.scope = scope;
-        }
-
-        public String getDescription()
-        {
-            return description;
-        }
-
-        public void setDescription(String description)
-        {
-            this.description = description;
-        }
-    }
-}

+ 0 - 20
ruoyi-common/ruoyi-common-swagger/src/main/java/com/ruoyi/common/swagger/config/SwaggerWebConfiguration.java

@@ -1,20 +0,0 @@
-package com.ruoyi.common.swagger.config;
-
-import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
-import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
-
-/**
- * swagger 资源映射路径
- * 
- * @author ruoyi
- */
-public class SwaggerWebConfiguration implements WebMvcConfigurer
-{
-    @Override
-    public void addResourceHandlers(ResourceHandlerRegistry registry)
-    {
-        /** swagger-ui 地址 */
-        registry.addResourceHandler("/swagger-ui/**")
-                .addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/");
-    }
-}

+ 135 - 0
ruoyi-common/ruoyi-common-swagger/src/main/java/com/ruoyi/common/swagger/config/properties/SpringDocProperties.java

@@ -0,0 +1,135 @@
+package com.ruoyi.common.swagger.config.properties;
+
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.boot.context.properties.NestedConfigurationProperty;
+import io.swagger.v3.oas.models.info.Contact;
+import io.swagger.v3.oas.models.info.License;
+
+/**
+ * Swagger 配置属性
+ *
+ * @author ruoyi
+ */
+@ConfigurationProperties(prefix = "springdoc")
+public class SpringDocProperties
+{
+    /**
+     * 网关
+     */
+    private String gatewayUrl;
+
+    /**
+     * 文档基本信息
+     */
+    @NestedConfigurationProperty
+    private InfoProperties info = new InfoProperties();
+
+    /**
+     * <p>
+     * 文档的基础属性信息
+     * </p>
+     *
+     * @see io.swagger.v3.oas.models.info.Info
+     *
+     * 为了 springboot 自动生产配置提示信息,所以这里复制一个类出来
+     */
+    public static class InfoProperties
+    {
+        /**
+         * 标题
+         */
+        private String title = null;
+
+        /**
+         * 描述
+         */
+        private String description = null;
+
+        /**
+         * 联系人信息
+         */
+        @NestedConfigurationProperty
+        private Contact contact = null;
+
+        /**
+         * 许可证
+         */
+        @NestedConfigurationProperty
+        private License license = null;
+
+        /**
+         * 版本
+         */
+        private String version = null;
+
+        public String getTitle()
+        {
+            return title;
+        }
+
+        public void setTitle(String title)
+        {
+            this.title = title;
+        }
+
+        public String getDescription()
+        {
+            return description;
+        }
+
+        public void setDescription(String description)
+        {
+            this.description = description;
+        }
+
+        public Contact getContact()
+        {
+            return contact;
+        }
+
+        public void setContact(Contact contact)
+        {
+            this.contact = contact;
+        }
+
+        public License getLicense()
+        {
+            return license;
+        }
+
+        public void setLicense(License license)
+        {
+            this.license = license;
+        }
+
+        public String getVersion()
+        {
+            return version;
+        }
+
+        public void setVersion(String version)
+        {
+            this.version = version;
+        }
+    }
+
+    public String getGatewayUrl()
+    {
+        return gatewayUrl;
+    }
+
+    public void setGatewayUrl(String gatewayUrl)
+    {
+        this.gatewayUrl = gatewayUrl;
+    }
+
+    public InfoProperties getInfo()
+    {
+        return info;
+    }
+
+    public void setInfo(InfoProperties info)
+    {
+        this.info = info;
+    }
+}

+ 1 - 3
ruoyi-common/ruoyi-common-swagger/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports

@@ -1,3 +1 @@
-# com.ruoyi.common.swagger.config.SwaggerAutoConfiguration
-# com.ruoyi.common.swagger.config.SwaggerWebConfiguration
-# com.ruoyi.common.swagger.config.SwaggerBeanPostProcessor
+com.ruoyi.common.swagger.config.SpringDocAutoConfiguration

+ 4 - 9
ruoyi-gateway/pom.xml

@@ -76,16 +76,11 @@
             <artifactId>ruoyi-common-redis</artifactId>
         </dependency>
 
-        <!-- Swagger -->
+        <!-- Springdoc -->
         <dependency>
-            <groupId>io.springfox</groupId>
-            <artifactId>springfox-swagger-ui</artifactId>
-            <version>${swagger.fox.version}</version>
-        </dependency>
-        <dependency>
-            <groupId>io.springfox</groupId>
-            <artifactId>springfox-swagger2</artifactId>
-            <version>${swagger.fox.version}</version>
+            <groupId>org.springdoc</groupId>
+            <artifactId>springdoc-openapi-webflux-ui</artifactId>
+            <version>${springdoc.version}</version>
         </dependency>
 
     </dependencies>

+ 93 - 0
ruoyi-gateway/src/main/java/com/ruoyi/gateway/config/SpringDocConfig.java

@@ -0,0 +1,93 @@
+package com.ruoyi.gateway.config;
+
+import java.util.Set;
+import java.util.stream.Collectors;
+import org.springdoc.core.AbstractSwaggerUiConfigProperties;
+import org.springdoc.core.SwaggerUiConfigProperties;
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.cloud.client.discovery.DiscoveryClient;
+import org.springframework.context.annotation.Configuration;
+import com.alibaba.nacos.client.naming.event.InstancesChangeEvent;
+import com.alibaba.nacos.common.notify.Event;
+import com.alibaba.nacos.common.notify.NotifyCenter;
+import com.alibaba.nacos.common.notify.listener.Subscriber;
+import com.ruoyi.common.core.utils.StringUtils;
+
+/**
+ * SpringDoc配置类
+ *
+ * @author ruoyi
+ */
+@Configuration(proxyBeanMethods = false)
+@ConditionalOnProperty(value = "springdoc.api-docs.enabled", matchIfMissing = true)
+public class SpringDocConfig implements InitializingBean
+{
+    @Autowired
+    private SwaggerUiConfigProperties swaggerUiConfigProperties;
+
+    @Autowired
+    private DiscoveryClient discoveryClient;
+
+    /**
+     * 在初始化后调用的方法
+     */
+    @Override
+    public void afterPropertiesSet()
+    {
+        NotifyCenter.registerSubscriber(new SwaggerDocRegister(swaggerUiConfigProperties, discoveryClient));
+    }
+}
+
+/**
+ * Swagger文档注册器
+ */
+class SwaggerDocRegister extends Subscriber<InstancesChangeEvent>
+{
+    @Autowired
+    private SwaggerUiConfigProperties swaggerUiConfigProperties;
+
+    @Autowired
+    private DiscoveryClient discoveryClient;
+
+    private final static String[] EXCLUDE_ROUTES = new String[] { "ruoyi-gateway", "ruoyi-auth", "ruoyi-file", "ruoyi-monitor" };
+
+    public SwaggerDocRegister(SwaggerUiConfigProperties swaggerUiConfigProperties, DiscoveryClient discoveryClient)
+    {
+        this.swaggerUiConfigProperties = swaggerUiConfigProperties;
+        this.discoveryClient = discoveryClient;
+    }
+
+    /**
+     * 事件回调方法,处理InstancesChangeEvent事件
+     * @param event 事件对象
+     */
+    @Override
+    public void onEvent(InstancesChangeEvent event)
+    {
+        Set<AbstractSwaggerUiConfigProperties.SwaggerUrl> swaggerUrlSet = discoveryClient.getServices()
+            .stream()
+            .flatMap(serviceId -> discoveryClient.getInstances(serviceId).stream())
+            .filter(instance -> !StringUtils.equalsAnyIgnoreCase(instance.getServiceId(), EXCLUDE_ROUTES))
+            .map(instance -> {
+                AbstractSwaggerUiConfigProperties.SwaggerUrl swaggerUrl = new AbstractSwaggerUiConfigProperties.SwaggerUrl();
+                swaggerUrl.setName(instance.getServiceId());
+                swaggerUrl.setUrl(String.format("/%s/v3/api-docs", instance.getServiceId()));
+                return swaggerUrl;
+            })
+            .collect(Collectors.toSet());
+
+        swaggerUiConfigProperties.setUrls(swaggerUrlSet);
+    }
+
+    /**
+     * 订阅类型方法,返回订阅的事件类型
+     * @return 订阅的事件类型
+     */
+    @Override
+    public Class<? extends Event> subscribeType()
+    {
+        return InstancesChangeEvent.class;
+    }
+}

+ 0 - 79
ruoyi-gateway/src/main/java/com/ruoyi/gateway/config/SwaggerProvider.java

@@ -1,79 +0,0 @@
-package com.ruoyi.gateway.config;
-
-import java.util.ArrayList;
-import java.util.List;
-import org.springframework.beans.factory.annotation.Autowired;
-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.Lazy;
-import org.springframework.stereotype.Component;
-import org.springframework.web.reactive.config.ResourceHandlerRegistry;
-import org.springframework.web.reactive.config.WebFluxConfigurer;
-import springfox.documentation.swagger.web.SwaggerResource;
-import springfox.documentation.swagger.web.SwaggerResourcesProvider;
-
-/**
- * 聚合系统接口
- * 
- * @author ruoyi
- */
-@Component
-public class SwaggerProvider implements SwaggerResourcesProvider, WebFluxConfigurer
-{
-    /**
-     * Swagger2默认的url后缀
-     */
-    public static final String SWAGGER2URL = "/v2/api-docs";
-
-    /**
-     * 网关路由
-     */
-    @Lazy
-    @Autowired
-    private RouteLocator routeLocator;
-
-    @Autowired
-    private GatewayProperties gatewayProperties;
-
-    /**
-     * 聚合其他服务接口
-     * 
-     * @return
-     */
-    @Override
-    public List<SwaggerResource> get()
-    {
-        List<SwaggerResource> resourceList = new ArrayList<>();
-        List<String> routes = new ArrayList<>();
-        // 获取网关中配置的route
-        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 -> !"ruoyi-auth".equalsIgnoreCase(routeDefinition.getId()))
-                        .forEach(predicateDefinition -> resourceList
-                                .add(swaggerResource(routeDefinition.getId(), predicateDefinition.getArgs()
-                                        .get(NameUtils.GENERATED_NAME_PREFIX + "0").replace("/**", SWAGGER2URL)))));
-        return resourceList;
-    }
-
-    private SwaggerResource swaggerResource(String name, String location)
-    {
-        SwaggerResource swaggerResource = new SwaggerResource();
-        swaggerResource.setName(name);
-        swaggerResource.setLocation(location);
-        swaggerResource.setSwaggerVersion("2.0");
-        return swaggerResource;
-    }
-
-    @Override
-    public void addResourceHandlers(ResourceHandlerRegistry registry)
-    {
-        /** swagger-ui 地址 */
-        registry.addResourceHandler("/swagger-ui/**")
-                .addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/");
-    }
-}

+ 1 - 1
ruoyi-gateway/src/main/java/com/ruoyi/gateway/filter/AuthFilter.java

@@ -101,7 +101,7 @@ public class AuthFilter implements GlobalFilter, Ordered
 
     private Mono<Void> unauthorizedResponse(ServerWebExchange exchange, String msg)
     {
-        log.error("[鉴权异常处理]请求路径:{}", exchange.getRequest().getPath());
+        log.error("[鉴权异常处理]请求路径:{},错误信息:{}", exchange.getRequest().getPath(), msg);
         return ServletUtils.webFluxResponseWriter(exchange.getResponse(), msg, HttpStatus.UNAUTHORIZED);
     }
 

+ 0 - 56
ruoyi-gateway/src/main/java/com/ruoyi/gateway/handler/SwaggerHandler.java

@@ -1,56 +0,0 @@
-package com.ruoyi.gateway.handler;
-
-import java.util.Optional;
-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.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-import reactor.core.publisher.Mono;
-import springfox.documentation.swagger.web.SecurityConfiguration;
-import springfox.documentation.swagger.web.SecurityConfigurationBuilder;
-import springfox.documentation.swagger.web.SwaggerResourcesProvider;
-import springfox.documentation.swagger.web.UiConfiguration;
-import springfox.documentation.swagger.web.UiConfigurationBuilder;
-
-@RestController
-@RequestMapping("/swagger-resources")
-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("/configuration/security")
-    public Mono<ResponseEntity<SecurityConfiguration>> securityConfiguration()
-    {
-        return Mono.just(new ResponseEntity<>(
-                Optional.ofNullable(securityConfiguration).orElse(SecurityConfigurationBuilder.builder().build()),
-                HttpStatus.OK));
-    }
-
-    @GetMapping("/configuration/ui")
-    public Mono<ResponseEntity<UiConfiguration>> uiConfiguration()
-    {
-        return Mono.just(new ResponseEntity<>(
-                Optional.ofNullable(uiConfiguration).orElse(UiConfigurationBuilder.builder().build()), HttpStatus.OK));
-    }
-
-    @SuppressWarnings("rawtypes")
-    @GetMapping("")
-    public Mono<ResponseEntity> swaggerResources()
-    {
-        return Mono.just((new ResponseEntity<>(swaggerResources.get(), HttpStatus.OK)));
-    }
-}

+ 6 - 6
ruoyi-modules/ruoyi-file/pom.xml

@@ -40,6 +40,12 @@
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-actuator</artifactId>
         </dependency>
+        
+        <!-- SpringBoot Web -->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-web</artifactId>
+        </dependency>
 		
         <!-- FastDFS -->
         <dependency>
@@ -60,12 +66,6 @@
             <artifactId>ruoyi-api-system</artifactId>
         </dependency>
         
-        <!-- RuoYi Common Swagger -->
-        <dependency>
-            <groupId>com.ruoyi</groupId>
-            <artifactId>ruoyi-common-swagger</artifactId>
-        </dependency>
-        
     </dependencies>
 
     <build>

+ 0 - 2
ruoyi-modules/ruoyi-file/src/main/java/com/ruoyi/file/RuoYiFileApplication.java

@@ -3,14 +3,12 @@ package com.ruoyi.file;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
-import com.ruoyi.common.swagger.annotation.EnableCustomSwagger2;
 
 /**
  * 文件服务
  * 
  * @author ruoyi
  */
-@EnableCustomSwagger2
 @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class })
 public class RuoYiFileApplication
 {

+ 0 - 7
ruoyi-modules/ruoyi-gen/pom.xml

@@ -40,13 +40,6 @@
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-actuator</artifactId>
         </dependency>
-		
-        <!-- Swagger UI -->
-        <dependency>
-            <groupId>io.springfox</groupId>
-            <artifactId>springfox-swagger-ui</artifactId>
-            <version>${swagger.fox.version}</version>
-        </dependency>
         
         <!-- Apache Velocity -->
         <dependency>

+ 0 - 2
ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/RuoYiGenApplication.java

@@ -4,7 +4,6 @@ import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import com.ruoyi.common.security.annotation.EnableCustomConfig;
 import com.ruoyi.common.security.annotation.EnableRyFeignClients;
-import com.ruoyi.common.swagger.annotation.EnableCustomSwagger2;
 
 /**
  * 代码生成
@@ -12,7 +11,6 @@ import com.ruoyi.common.swagger.annotation.EnableCustomSwagger2;
  * @author ruoyi
  */
 @EnableCustomConfig
-@EnableCustomSwagger2
 @EnableRyFeignClients
 @SpringBootApplication
 public class RuoYiGenApplication

+ 0 - 1
ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/domain/GenTableColumn.java

@@ -1,7 +1,6 @@
 package com.ruoyi.gen.domain;
 
 import javax.validation.constraints.NotBlank;
-
 import com.ruoyi.common.core.utils.StringUtils;
 import com.ruoyi.common.core.web.domain.BaseEntity;
 

+ 1 - 8
ruoyi-modules/ruoyi-job/pom.xml

@@ -40,14 +40,7 @@
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-actuator</artifactId>
         </dependency>
-		
-        <!-- Swagger UI -->
-        <dependency>
-            <groupId>io.springfox</groupId>
-            <artifactId>springfox-swagger-ui</artifactId>
-            <version>${swagger.fox.version}</version>
-        </dependency>
-		
+        
         <!-- Quartz -->
         <dependency>
             <groupId>org.quartz-scheduler</groupId>

+ 0 - 2
ruoyi-modules/ruoyi-job/src/main/java/com/ruoyi/job/RuoYiJobApplication.java

@@ -4,7 +4,6 @@ import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import com.ruoyi.common.security.annotation.EnableCustomConfig;
 import com.ruoyi.common.security.annotation.EnableRyFeignClients;
-import com.ruoyi.common.swagger.annotation.EnableCustomSwagger2;
 
 /**
  * 定时任务
@@ -12,7 +11,6 @@ import com.ruoyi.common.swagger.annotation.EnableCustomSwagger2;
  * @author ruoyi
  */
 @EnableCustomConfig
-@EnableCustomSwagger2
 @EnableRyFeignClients   
 @SpringBootApplication
 public class RuoYiJobApplication

+ 1 - 8
ruoyi-modules/ruoyi-system/pom.xml

@@ -40,14 +40,7 @@
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-actuator</artifactId>
         </dependency>
-		
-        <!-- Swagger UI -->
-        <dependency>
-            <groupId>io.springfox</groupId>
-            <artifactId>springfox-swagger-ui</artifactId>
-            <version>${swagger.fox.version}</version>
-        </dependency>
-		
+        
         <!-- Mysql Connector -->
         <dependency>
             <groupId>com.mysql</groupId>

+ 0 - 2
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/RuoYiSystemApplication.java

@@ -4,7 +4,6 @@ import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import com.ruoyi.common.security.annotation.EnableCustomConfig;
 import com.ruoyi.common.security.annotation.EnableRyFeignClients;
-import com.ruoyi.common.swagger.annotation.EnableCustomSwagger2;
 
 /**
  * 系统模块
@@ -12,7 +11,6 @@ import com.ruoyi.common.swagger.annotation.EnableCustomSwagger2;
  * @author ruoyi
  */
 @EnableCustomConfig
-@EnableCustomSwagger2
 @EnableRyFeignClients
 @SpringBootApplication
 public class RuoYiSystemApplication

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 4 - 7
sql/ry_config_20240829.sql


Některé soubory nejsou zobrazeny, neboť je v těchto rozdílových datech změněno mnoho souborů