This is an automated email from the ASF dual-hosted git repository.

xiaoyu pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/shenyu-client-java.git


The following commit(s) were added to refs/heads/main by this push:
     new cb1a3a4  [feat] modify swagger (#4)
cb1a3a4 is described below

commit cb1a3a4fffdce63745868424f568f7a0cd61298a
Author: aias00 <liuhon...@apache.org>
AuthorDate: Tue Mar 4 16:09:03 2025 +0800

    [feat] modify swagger (#4)
---
 shenyu-java-examples/pom.xml                       |  2 +-
 .../examples/http/config/SwaggerConfiguration.java | 93 ++++++++++------------
 2 files changed, 44 insertions(+), 51 deletions(-)

diff --git a/shenyu-java-examples/pom.xml b/shenyu-java-examples/pom.xml
index 83036c5..1f63d64 100644
--- a/shenyu-java-examples/pom.xml
+++ b/shenyu-java-examples/pom.xml
@@ -38,7 +38,7 @@
         <versions-maven-plugin.version>2.5</versions-maven-plugin.version>
         <docker-maven-plugin.version>0.40.1</docker-maven-plugin.version>
         
<maven-checkstyle-plugin.version>3.4.0</maven-checkstyle-plugin.version>
-        <swagger.version>2.9.2</swagger.version>
+        <swagger.version>2.10.0</swagger.version>
     </properties>
 
     <modules>
diff --git 
a/shenyu-java-examples/shenyu-java-examples-http-swagger2/src/main/java/org/apache/shenyu/examples/http/config/SwaggerConfiguration.java
 
b/shenyu-java-examples/shenyu-java-examples-http-swagger2/src/main/java/org/apache/shenyu/examples/http/config/SwaggerConfiguration.java
index 8da8e9c..4ff4791 100644
--- 
a/shenyu-java-examples/shenyu-java-examples-http-swagger2/src/main/java/org/apache/shenyu/examples/http/config/SwaggerConfiguration.java
+++ 
b/shenyu-java-examples/shenyu-java-examples-http-swagger2/src/main/java/org/apache/shenyu/examples/http/config/SwaggerConfiguration.java
@@ -18,19 +18,10 @@
 package org.apache.shenyu.examples.http.config;
 
 import io.swagger.annotations.ApiOperation;
-import java.lang.reflect.Field;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Objects;
-import java.util.stream.Collectors;
 import org.apache.shenyu.common.constant.Constants;
 import org.apache.shenyu.common.utils.VersionUtils;
-import org.springframework.beans.BeansException;
-import org.springframework.beans.factory.config.BeanPostProcessor;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
-import org.springframework.util.ReflectionUtils;
-import 
org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping;
 import springfox.documentation.builders.ApiInfoBuilder;
 import springfox.documentation.builders.ParameterBuilder;
 import springfox.documentation.builders.PathSelectors;
@@ -41,14 +32,16 @@ import springfox.documentation.service.Contact;
 import springfox.documentation.service.Parameter;
 import springfox.documentation.spi.DocumentationType;
 import springfox.documentation.spring.web.plugins.Docket;
-import springfox.documentation.spring.web.plugins.WebMvcRequestHandlerProvider;
-import springfox.documentation.swagger2.annotations.EnableSwagger2;
+import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;
+
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  * Configuration class for Swagger API document.
  */
 @Configuration
-@EnableSwagger2
+@EnableSwagger2WebMvc
 public class SwaggerConfiguration {
 
     private static final String DEFAULT_SWAGGER_API_VERSION = "2.3.0";
@@ -103,44 +96,44 @@ public class SwaggerConfiguration {
             .build();
     }
 
-    /**
-     * use bean to be compatible with springboot 2.6.8.
-     *
-     * @return BeanPostProcessor
-     */
-    @Bean
-    public BeanPostProcessor springfoxBeanHandler() {
-        return new BeanPostProcessor() {
-            @Override
-            public Object postProcessAfterInitialization(final Object bean,
-                final String beanName) throws BeansException {
-                if (bean instanceof WebMvcRequestHandlerProvider) {
-                    
customizeSpringfoxHandlerMappings(getHandlerMappings(bean));
-                }
-                return bean;
-            }
-
-            private <T extends RequestMappingInfoHandlerMapping> void 
customizeSpringfoxHandlerMappings(
-                final List<T> mappings) {
-                List<T> copy = mappings.stream()
-                    .filter(mapping -> 
Objects.isNull(mapping.getPatternParser()))
-                    .collect(Collectors.toList());
-                mappings.clear();
-                mappings.addAll(copy);
-            }
-
-            @SuppressWarnings("unchecked")
-            private List<RequestMappingInfoHandlerMapping> 
getHandlerMappings(final 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);
-                }
-            }
-        };
-    }
+//    /**
+//     * use bean to be compatible with springboot 2.6.8.
+//     *
+//     * @return BeanPostProcessor
+//     */
+//    @Bean
+//    public BeanPostProcessor springfoxBeanHandler() {
+//        return new BeanPostProcessor() {
+//            @Override
+//            public Object postProcessAfterInitialization(final Object bean,
+//                final String beanName) throws BeansException {
+//                if (bean instanceof WebMvcRequestHandlerProvider) {
+//                    
customizeSpringfoxHandlerMappings(getHandlerMappings(bean));
+//                }
+//                return bean;
+//            }
+//
+//            private <T extends RequestMappingInfoHandlerMapping> void 
customizeSpringfoxHandlerMappings(
+//                final List<T> mappings) {
+//                List<T> copy = mappings.stream()
+//                    .filter(mapping -> 
Objects.isNull(mapping.getPatternParser()))
+//                    .collect(Collectors.toList());
+//                mappings.clear();
+//                mappings.addAll(copy);
+//            }
+//
+//            @SuppressWarnings("unchecked")
+//            private List<RequestMappingInfoHandlerMapping> 
getHandlerMappings(final 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);
+//                }
+//            }
+//        };
+//    }
 
     /**
      * Fetch version information from pom.xml and set title, version, 
description,

Reply via email to