You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shenyu.apache.org by GitBox <gi...@apache.org> on 2022/12/15 03:22:24 UTC

[GitHub] [shenyu] 847850277 opened a new pull request, #4270: [ISSUE #4029] add shenyu-client-api-doc part1

847850277 opened a new pull request, #4270:
URL: https://github.com/apache/shenyu/pull/4270

   <!-- Describe your PR here; eg. Fixes #issueNo -->
   
   <!--
   Thank you for proposing a pull request. This template will guide you through the essential steps necessary for a pull request.
   -->
   Make sure that:
   
   - [ ] You have read the [contribution guidelines](https://shenyu.apache.org/community/contributor-guide).
   - [ ] You submit test cases (unit or integration tests) that back your changes.
   - [ ] Your local test passed `./mvnw clean install -Dmaven.javadoc.skip=true`.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shenyu] codecov-commenter commented on pull request #4270: [ISSUE #4029] add shenyu-client-api-doc part1 client module

Posted by GitBox <gi...@apache.org>.
codecov-commenter commented on PR #4270:
URL: https://github.com/apache/shenyu/pull/4270#issuecomment-1352530122

   # [Codecov](https://codecov.io/gh/apache/shenyu/pull/4270?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#4270](https://codecov.io/gh/apache/shenyu/pull/4270?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (14b2869) into [master](https://codecov.io/gh/apache/shenyu/commit/a098c3e422560d3c2937c932299c564cf1807a9a?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (a098c3e) will **decrease** coverage by `0.71%`.
   > The diff coverage is `0.00%`.
   
   ```diff
   @@             Coverage Diff              @@
   ##             master    #4270      +/-   ##
   ============================================
   - Coverage     69.44%   68.73%   -0.72%     
   - Complexity     7382     7384       +2     
   ============================================
     Files           995      996       +1     
     Lines         28014    28313     +299     
     Branches       2481     2518      +37     
   ============================================
   + Hits          19455    19460       +5     
   - Misses         7079     7374     +295     
   + Partials       1480     1479       -1     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/shenyu/pull/4270?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [...client/brpc/BrpcContextRefreshedEventListener.java](https://codecov.io/gh/apache/shenyu/pull/4270/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hlbnl1LWNsaWVudC9zaGVueXUtY2xpZW50LWJycGMvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoZW55dS9jbGllbnQvYnJwYy9CcnBjQ29udGV4dFJlZnJlc2hlZEV2ZW50TGlzdGVuZXIuamF2YQ==) | `80.64% <0.00%> (-1.33%)` | :arrow_down: |
   | [...alibaba/dubbo/AlibabaDubboServiceBeanListener.java](https://codecov.io/gh/apache/shenyu/pull/4270/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hlbnl1LWNsaWVudC9zaGVueXUtY2xpZW50LWR1YmJvL3NoZW55dS1jbGllbnQtYWxpYmFiYS1kdWJiby9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hlbnl1L2NsaWVudC9hbGliYWJhL2R1YmJvL0FsaWJhYmFEdWJib1NlcnZpY2VCZWFuTGlzdGVuZXIuamF2YQ==) | `0.00% <0.00%> (ø)` | |
   | [...t/apache/dubbo/ApacheDubboServiceBeanListener.java](https://codecov.io/gh/apache/shenyu/pull/4270/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hlbnl1LWNsaWVudC9zaGVueXUtY2xpZW50LWR1YmJvL3NoZW55dS1jbGllbnQtYXBhY2hlLWR1YmJvL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGVueXUvY2xpZW50L2FwYWNoZS9kdWJiby9BcGFjaGVEdWJib1NlcnZpY2VCZWFuTGlzdGVuZXIuamF2YQ==) | `0.00% <0.00%> (ø)` | |
   | [...ringcloud/init/SpringCloudClientEventListener.java](https://codecov.io/gh/apache/shenyu/pull/4270/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hlbnl1LWNsaWVudC9zaGVueXUtY2xpZW50LWh0dHAvc2hlbnl1LWNsaWVudC1zcHJpbmdjbG91ZC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hlbnl1L2NsaWVudC9zcHJpbmdjbG91ZC9pbml0L1NwcmluZ0Nsb3VkQ2xpZW50RXZlbnRMaXN0ZW5lci5qYXZh) | `40.33% <0.00%> (-38.17%)` | :arrow_down: |
   | [...t/springmvc/init/SpringMvcClientEventListener.java](https://codecov.io/gh/apache/shenyu/pull/4270/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hlbnl1LWNsaWVudC9zaGVueXUtY2xpZW50LWh0dHAvc2hlbnl1LWNsaWVudC1zcHJpbmdtdmMvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoZW55dS9jbGllbnQvc3ByaW5nbXZjL2luaXQvU3ByaW5nTXZjQ2xpZW50RXZlbnRMaXN0ZW5lci5qYXZh) | `42.85% <0.00%> (-43.35%)` | :arrow_down: |
   | [...enyu/client/tars/TarsServiceBeanEventListener.java](https://codecov.io/gh/apache/shenyu/pull/4270/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hlbnl1LWNsaWVudC9zaGVueXUtY2xpZW50LXRhcnMvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoZW55dS9jbGllbnQvdGFycy9UYXJzU2VydmljZUJlYW5FdmVudExpc3RlbmVyLmphdmE=) | `63.06% <0.00%> (-25.55%)` | :arrow_down: |
   | [...a/org/apache/shenyu/common/constant/Constants.java](https://codecov.io/gh/apache/shenyu/pull/4270/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hlbnl1LWNvbW1vbi9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hlbnl1L2NvbW1vbi9jb25zdGFudC9Db25zdGFudHMuamF2YQ==) | `66.66% <ø> (ø)` | |
   | [.../apache/shenyu/common/enums/ApiHttpMethodEnum.java](https://codecov.io/gh/apache/shenyu/pull/4270/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hlbnl1LWNvbW1vbi9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hlbnl1L2NvbW1vbi9lbnVtcy9BcGlIdHRwTWV0aG9kRW51bS5qYXZh) | `0.00% <0.00%> (ø)` | |
   | [...ster/client/http/HttpClientRegisterRepository.java](https://codecov.io/gh/apache/shenyu/pull/4270/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hlbnl1LXJlZ2lzdGVyLWNlbnRlci9zaGVueXUtcmVnaXN0ZXItY2xpZW50L3NoZW55dS1yZWdpc3Rlci1jbGllbnQtaHR0cC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hlbnl1L3JlZ2lzdGVyL2NsaWVudC9odHRwL0h0dHBDbGllbnRSZWdpc3RlclJlcG9zaXRvcnkuamF2YQ==) | `0.00% <0.00%> (ø)` | |
   | [...shenyu/sync/data/consul/ConsulSyncDataService.java](https://codecov.io/gh/apache/shenyu/pull/4270/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hlbnl1LXN5bmMtZGF0YS1jZW50ZXIvc2hlbnl1LXN5bmMtZGF0YS1jb25zdWwvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoZW55dS9zeW5jL2RhdGEvY29uc3VsL0NvbnN1bFN5bmNEYXRhU2VydmljZS5qYXZh) | `78.33% <0.00%> (-1.67%)` | :arrow_down: |
   | ... and [3 more](https://codecov.io/gh/apache/shenyu/pull/4270/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | |
   
   :mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shenyu] 847850277 commented on a diff in pull request #4270: [ISSUE #4029] add shenyu-client-api-doc part1 client module

Posted by GitBox <gi...@apache.org>.
847850277 commented on code in PR #4270:
URL: https://github.com/apache/shenyu/pull/4270#discussion_r1056906679


##########
shenyu-client/shenyu-client-dubbo/shenyu-client-alibaba-dubbo/src/main/java/org/apache/shenyu/client/alibaba/dubbo/AlibabaDubboServiceBeanListener.java:
##########
@@ -60,6 +69,44 @@ public AlibabaDubboServiceBeanListener(final PropertiesConfig clientConfig,
         super(clientConfig, shenyuClientRegisterRepository);
     }
 
+    @Override
+    protected List<ApiDocRegisterDTO> buildApiDocDTO(final Class<?> clazz, final Method method) {
+        final String contextPath = getContextPath();
+        String apiDesc = Stream.of(method.getDeclaredAnnotations()).filter(item -> item instanceof ApiDoc).findAny().map(item -> {
+            ApiDoc apiDoc = (ApiDoc) item;
+            return apiDoc.desc();
+        }).orElse("");
+        String superPath = buildApiSuperPath(clazz, AnnotatedElementUtils.findMergedAnnotation(clazz, getAnnotationType()));
+        if (superPath.indexOf("*") > 0) {
+            superPath = superPath.substring(0, superPath.lastIndexOf("/"));
+        }
+        ShenyuDubboClient shenyuDubboClient = AnnotatedElementUtils.findMergedAnnotation(method, ShenyuDubboClient.class);
+        if (Objects.isNull(shenyuDubboClient)) {
+            return Lists.newArrayList();
+        }
+        List<ApiDocRegisterDTO> list = Lists.newArrayList();
+        String value = shenyuDubboClient.value();
+        String apiPath = contextPath + superPath + value;
+        ApiDocRegisterDTO build = ApiDocRegisterDTO.builder()
+                .consume(ShenyuClientConstants.MEDIA_TYPE_ALL_VALUE)
+                .produce(ShenyuClientConstants.MEDIA_TYPE_ALL_VALUE)
+                .httpMethod(ApiHttpMethodEnum.NOT_HTTP.getValue())
+                .contextPath(contextPath)
+                .ext("{}")
+                .document("{}")
+                .version("v0.01")

Review Comment:
   i try this code,but it didn't work
   ```java
   
   if (apiModuleClass.isAnnotationPresent(Service.class)) {
       Service dubboService = apiModuleClass.getAnnotation(Service.class);
       apiVersion = dubboService.version();
   } else {
       DubboService dubboService = apiModuleClass.getAnnotation(DubboService.class);
       apiVersion = dubboService.version();
   }
   
   ```



##########
shenyu-client/shenyu-client-dubbo/shenyu-client-alibaba-dubbo/src/main/java/org/apache/shenyu/client/alibaba/dubbo/AlibabaDubboServiceBeanListener.java:
##########
@@ -60,6 +69,44 @@ public AlibabaDubboServiceBeanListener(final PropertiesConfig clientConfig,
         super(clientConfig, shenyuClientRegisterRepository);
     }
 
+    @Override
+    protected List<ApiDocRegisterDTO> buildApiDocDTO(final Class<?> clazz, final Method method) {
+        final String contextPath = getContextPath();
+        String apiDesc = Stream.of(method.getDeclaredAnnotations()).filter(item -> item instanceof ApiDoc).findAny().map(item -> {
+            ApiDoc apiDoc = (ApiDoc) item;
+            return apiDoc.desc();
+        }).orElse("");
+        String superPath = buildApiSuperPath(clazz, AnnotatedElementUtils.findMergedAnnotation(clazz, getAnnotationType()));
+        if (superPath.indexOf("*") > 0) {
+            superPath = superPath.substring(0, superPath.lastIndexOf("/"));
+        }
+        ShenyuDubboClient shenyuDubboClient = AnnotatedElementUtils.findMergedAnnotation(method, ShenyuDubboClient.class);
+        if (Objects.isNull(shenyuDubboClient)) {
+            return Lists.newArrayList();
+        }
+        List<ApiDocRegisterDTO> list = Lists.newArrayList();
+        String value = shenyuDubboClient.value();
+        String apiPath = contextPath + superPath + value;
+        ApiDocRegisterDTO build = ApiDocRegisterDTO.builder()
+                .consume(ShenyuClientConstants.MEDIA_TYPE_ALL_VALUE)
+                .produce(ShenyuClientConstants.MEDIA_TYPE_ALL_VALUE)
+                .httpMethod(ApiHttpMethodEnum.NOT_HTTP.getValue())
+                .contextPath(contextPath)
+                .ext("{}")
+                .document("{}")
+                .version("v0.01")
+                .rpcType(RpcTypeEnum.DUBBO.getName())
+                .apiDesc(apiDesc)
+                .apiPath(apiPath)
+                .apiSource(1)
+                .state(1)

Review Comment:
   fixed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shenyu] dragon-zhang commented on a diff in pull request #4270: [ISSUE #4029] add shenyu-client-api-doc part1 client module

Posted by GitBox <gi...@apache.org>.
dragon-zhang commented on code in PR #4270:
URL: https://github.com/apache/shenyu/pull/4270#discussion_r1051305353


##########
shenyu-client/shenyu-client-api-docs-annotations/src/main/java/org/apache/shenyu/client/apidocs/annotations/ApiModule.java:
##########
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shenyu.client.apidocs.annotations;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * ApiModule
+ * declaring {@code @ApiModule}.
+ */
+@Target({ElementType.TYPE, ElementType.METHOD})
+@Retention(RetentionPolicy.RUNTIME)
+@Documented
+public @interface ApiModule {
+
+    /**
+     * value.
+     * @return value
+     */
+    String value();

Review Comment:
   maybe add `required` and `example` ?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shenyu] 847850277 commented on a diff in pull request #4270: [ISSUE #4029] add shenyu-client-api-doc part1 client module

Posted by GitBox <gi...@apache.org>.
847850277 commented on code in PR #4270:
URL: https://github.com/apache/shenyu/pull/4270#discussion_r1056906630


##########
shenyu-client/shenyu-client-dubbo/shenyu-client-apache-dubbo/src/main/java/org/apache/shenyu/client/apache/dubbo/ApacheDubboServiceBeanListener.java:
##########
@@ -62,7 +71,45 @@ public ApacheDubboServiceBeanListener(final PropertiesConfig clientConfig,
                                           final ShenyuClientRegisterRepository shenyuClientRegisterRepository) {
         super(clientConfig, shenyuClientRegisterRepository);
     }
-    
+
+    @Override
+    protected List<ApiDocRegisterDTO> buildApiDocDTO(final Class<?> clazz, final Method method) {
+        final String contextPath = getContextPath();
+        String apiDesc = Stream.of(method.getDeclaredAnnotations()).filter(item -> item instanceof ApiDoc).findAny().map(item -> {
+            ApiDoc apiDoc = (ApiDoc) item;
+            return apiDoc.desc();
+        }).orElse("");
+        String superPath = buildApiSuperPath(clazz, AnnotatedElementUtils.findMergedAnnotation(clazz, getAnnotationType()));
+        if (superPath.indexOf("*") > 0) {
+            superPath = superPath.substring(0, superPath.lastIndexOf("/"));
+        }
+        ShenyuDubboClient shenyuDubboClient = AnnotatedElementUtils.findMergedAnnotation(method, ShenyuDubboClient.class);
+        if (Objects.isNull(shenyuDubboClient)) {
+            return Lists.newArrayList();
+        }
+        List<ApiDocRegisterDTO> list = Lists.newArrayList();
+        String value = shenyuDubboClient.value();
+        String apiPath = contextPath + superPath + value;
+        ApiDocRegisterDTO build = ApiDocRegisterDTO.builder()
+                .consume(ShenyuClientConstants.MEDIA_TYPE_ALL_VALUE)
+                .produce(ShenyuClientConstants.MEDIA_TYPE_ALL_VALUE)
+                .httpMethod(ApiHttpMethodEnum.NOT_HTTP.getValue())
+                .contextPath(contextPath)
+                .ext("{}")
+                .document("{}")
+                .version("v0.01")

Review Comment:
   i try this code,but it didn't work
   ```java
   
   if (apiModuleClass.isAnnotationPresent(Service.class)) {
       Service dubboService = apiModuleClass.getAnnotation(Service.class);
       apiVersion = dubboService.version();
   } else {
       DubboService dubboService = apiModuleClass.getAnnotation(DubboService.class);
       apiVersion = dubboService.version();
   }
   
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shenyu] dragon-zhang commented on a diff in pull request #4270: [ISSUE #4029] add shenyu-client-api-doc part1 client module

Posted by GitBox <gi...@apache.org>.
dragon-zhang commented on code in PR #4270:
URL: https://github.com/apache/shenyu/pull/4270#discussion_r1057080956


##########
shenyu-client/shenyu-client-sofa/src/main/java/org/apache/shenyu/client/sofa/SofaServiceEventListener.java:
##########
@@ -151,6 +159,44 @@ public void onApplicationEvent(final ContextRefreshedEvent contextRefreshedEvent
         }
     }
 
+    @Override
+    protected List<ApiDocRegisterDTO> buildApiDocDTO(final Class<?> clazz, final Method method) {
+        final String contextPath = getContextPath();
+        String apiDesc = Stream.of(method.getDeclaredAnnotations()).filter(item -> item instanceof ApiDoc).findAny().map(item -> {
+            ApiDoc apiDoc = (ApiDoc) item;
+            return apiDoc.desc();
+        }).orElse("");
+        String superPath = buildApiSuperPath(clazz, AnnotatedElementUtils.findMergedAnnotation(clazz, getAnnotationType()));
+        if (superPath.indexOf("*") > 0) {
+            superPath = superPath.substring(0, superPath.lastIndexOf("/"));
+        }
+        ShenyuSofaClient shenyuSofaClient = AnnotatedElementUtils.findMergedAnnotation(method, ShenyuSofaClient.class);
+        if (Objects.isNull(shenyuSofaClient)) {
+            return Lists.newArrayList();
+        }
+        List<ApiDocRegisterDTO> list = Lists.newArrayList();
+        String value = shenyuSofaClient.value();
+        String apiPath = contextPath + superPath + value;
+        ApiDocRegisterDTO build = ApiDocRegisterDTO.builder()
+                .consume(ShenyuClientConstants.MEDIA_TYPE_ALL_VALUE)
+                .produce(ShenyuClientConstants.MEDIA_TYPE_ALL_VALUE)
+                .httpMethod(ApiHttpMethodEnum.NOT_HTTP.getValue())

Review Comment:
   I think yes.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shenyu] 847850277 commented on a diff in pull request #4270: [ISSUE #4029] add shenyu-client-api-doc part1 client module

Posted by GitBox <gi...@apache.org>.
847850277 commented on code in PR #4270:
URL: https://github.com/apache/shenyu/pull/4270#discussion_r1056906785


##########
shenyu-client/shenyu-client-api-docs-annotations/src/main/java/org/apache/shenyu/client/apidocs/annotations/ApiModule.java:
##########
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shenyu.client.apidocs.annotations;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * ApiModule
+ * declaring {@code @ApiModule}.
+ */
+@Target({ElementType.TYPE, ElementType.METHOD})
+@Retention(RetentionPolicy.RUNTIME)
+@Documented
+public @interface ApiModule {
+
+    /**
+     * value.
+     * @return value
+     */
+    String value();

Review Comment:
    i think required and example It is a parameter of the request response body. It should not appear in the ApiModule



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shenyu] dragon-zhang commented on a diff in pull request #4270: [ISSUE #4029] add shenyu-client-api-doc part1 client module

Posted by GitBox <gi...@apache.org>.
dragon-zhang commented on code in PR #4270:
URL: https://github.com/apache/shenyu/pull/4270#discussion_r1051304249


##########
shenyu-client/shenyu-client-dubbo/shenyu-client-alibaba-dubbo/src/main/java/org/apache/shenyu/client/alibaba/dubbo/AlibabaDubboServiceBeanListener.java:
##########
@@ -60,6 +69,44 @@ public AlibabaDubboServiceBeanListener(final PropertiesConfig clientConfig,
         super(clientConfig, shenyuClientRegisterRepository);
     }
 
+    @Override
+    protected List<ApiDocRegisterDTO> buildApiDocDTO(final Class<?> clazz, final Method method) {
+        final String contextPath = getContextPath();
+        String apiDesc = Stream.of(method.getDeclaredAnnotations()).filter(item -> item instanceof ApiDoc).findAny().map(item -> {
+            ApiDoc apiDoc = (ApiDoc) item;
+            return apiDoc.desc();
+        }).orElse("");
+        String superPath = buildApiSuperPath(clazz, AnnotatedElementUtils.findMergedAnnotation(clazz, getAnnotationType()));
+        if (superPath.indexOf("*") > 0) {
+            superPath = superPath.substring(0, superPath.lastIndexOf("/"));
+        }
+        ShenyuDubboClient shenyuDubboClient = AnnotatedElementUtils.findMergedAnnotation(method, ShenyuDubboClient.class);
+        if (Objects.isNull(shenyuDubboClient)) {
+            return Lists.newArrayList();
+        }
+        List<ApiDocRegisterDTO> list = Lists.newArrayList();
+        String value = shenyuDubboClient.value();
+        String apiPath = contextPath + superPath + value;
+        ApiDocRegisterDTO build = ApiDocRegisterDTO.builder()
+                .consume(ShenyuClientConstants.MEDIA_TYPE_ALL_VALUE)
+                .produce(ShenyuClientConstants.MEDIA_TYPE_ALL_VALUE)
+                .httpMethod(ApiHttpMethodEnum.NOT_HTTP.getValue())
+                .contextPath(contextPath)
+                .ext("{}")
+                .document("{}")
+                .version("v0.01")

Review Comment:
   In `dubbo`, maybe we can build version from `ServiceBean`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shenyu] dragon-zhang commented on a diff in pull request #4270: [ISSUE #4029] add shenyu-client-api-doc part1 client module

Posted by GitBox <gi...@apache.org>.
dragon-zhang commented on code in PR #4270:
URL: https://github.com/apache/shenyu/pull/4270#discussion_r1051332454


##########
shenyu-client/shenyu-client-http/shenyu-client-springmvc/src/main/java/org/apache/shenyu/client/springmvc/init/SpringMvcClientEventListener.java:
##########
@@ -80,7 +94,124 @@ public SpringMvcClientEventListener(final PropertiesConfig clientConfig,
         mappingAnnotation.add(ShenyuSpringMvcClient.class);
         mappingAnnotation.add(RequestMapping.class);
     }
-    
+
+    /**
+     * buildApiDocDTO.
+     *
+     * @param clazz  clazz
+     * @param method method
+     * @return ApiDocRegisterDTO
+     */
+    @Override
+    protected List<ApiDocRegisterDTO> buildApiDocDTO(final Class<?> clazz, final Method method) {
+        final String contextPath = getContextPath();
+        String apiDesc = Stream.of(method.getDeclaredAnnotations()).filter(item -> item instanceof ApiDoc).findAny().map(item -> {
+            ApiDoc apiDoc = (ApiDoc) item;
+            return apiDoc.desc();
+        }).orElse("");
+        String superPath = buildApiSuperPath(clazz, AnnotatedElementUtils.findMergedAnnotation(clazz, getAnnotationType()));
+        if (superPath.indexOf("*") > 0) {
+            superPath = superPath.substring(0, superPath.lastIndexOf("/"));
+        }
+        RequestMapping requestMapping = AnnotatedElementUtils.findMergedAnnotation(method, RequestMapping.class);
+        if (Objects.nonNull(requestMapping)) {
+            List<ApiDocRegisterDTO> list = Lists.newArrayList();
+            String produce = requestMapping.produces().length == 0 ? ShenyuClientConstants.MEDIA_TYPE_ALL_VALUE : String.join(",", requestMapping.produces());
+            String consume = requestMapping.consumes().length == 0 ? ShenyuClientConstants.MEDIA_TYPE_ALL_VALUE : String.join(",", requestMapping.consumes());
+            String[] values = requestMapping.value();
+            for (String value : values) {
+                String apiPath = contextPath + superPath + value;
+                RequestMethod[] requestMethods = requestMapping.method();
+                if (requestMethods.length == 0) {
+                    requestMethods = RequestMethod.values();
+                }
+                for (RequestMethod requestMethod : requestMethods) {
+                    ApiDocRegisterDTO build = ApiDocRegisterDTO.builder()
+                            .consume(consume)
+                            .produce(produce)
+                            .httpMethod(ApiHttpMethodEnum.getValueByName(String.valueOf(requestMethod)))
+                            .contextPath(contextPath)
+                            .ext("{}")
+                            .document("{}")
+                            .version("v0.01")
+                            .rpcType(RpcTypeEnum.HTTP.getName())
+                            .apiDesc(apiDesc)
+                            .apiPath(apiPath)
+                            .apiSource(1)
+                            .state(1)
+                            .apiOwner("admin")
+                            .eventType(EventType.REGISTER)
+                            .build();
+                    list.add(build);
+                }
+            }
+            return list;
+        } else {
+            return apiDocRegisterDTOListByDeclaredAnnotations(contextPath, superPath, method, apiDesc);
+        }
+    }
+
+    private List<ApiDocRegisterDTO> apiDocRegisterDTOListByDeclaredAnnotations(final String contextPath, final String superPath, final Method method, final String apiDesc) {
+        List<ApiDocRegisterDTO> list = Lists.newArrayList();
+        Map<ApiHttpMethodEnum, Triple<String[], String[], String[]>> methodConsumeProduceValueMap = httpMethodConsumeProduceValueMap(method);
+        methodConsumeProduceValueMap.forEach((k, v) -> {
+            String[] values = v.getRight();
+            String consume = v.getLeft().length == 0 ? ShenyuClientConstants.MEDIA_TYPE_ALL_VALUE : String.join(",", v.getLeft());
+            String produce = v.getMiddle().length == 0 ? ShenyuClientConstants.MEDIA_TYPE_ALL_VALUE : String.join(",", v.getMiddle());
+            for (String value : values) {
+                String apiPath = contextPath + superPath + value;
+                ApiDocRegisterDTO build = ApiDocRegisterDTO.builder()
+                        .consume(consume)
+                        .produce(produce)
+                        .httpMethod(k.getValue())
+                        .contextPath(contextPath)
+                        .ext("{}")
+                        .document("{}")
+                        .version("v0.01")
+                        .rpcType(RpcTypeEnum.HTTP.getName())
+                        .apiDesc(apiDesc)
+                        .apiPath(apiPath)
+                        .apiSource(1)
+                        .state(1)
+                        .apiOwner("admin")
+                        .eventType(EventType.REGISTER)
+                        .build();
+                list.add(build);
+            }
+        });
+        return list;
+    }
+
+    private Map<ApiHttpMethodEnum, Triple<String[], String[], String[]>> httpMethodConsumeProduceValueMap(final Method method) {
+        Map<ApiHttpMethodEnum, Triple<String[], String[], String[]>> map = Maps.newHashMap();
+        GetMapping getMapping = AnnotatedElementUtils.findMergedAnnotation(method, GetMapping.class);
+        if (Objects.nonNull(getMapping)) {
+            map.put(ApiHttpMethodEnum.GET, Triple.of(getMapping.consumes(), getMapping.produces(), getMapping.value()));
+            return map;

Review Comment:
   maybe do the same changes in `springcloud client`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shenyu] dragon-zhang commented on a diff in pull request #4270: [ISSUE #4029] add shenyu-client-api-doc part1 client module

Posted by GitBox <gi...@apache.org>.
dragon-zhang commented on code in PR #4270:
URL: https://github.com/apache/shenyu/pull/4270#discussion_r1051304191


##########
shenyu-client/shenyu-client-dubbo/shenyu-client-apache-dubbo/src/main/java/org/apache/shenyu/client/apache/dubbo/ApacheDubboServiceBeanListener.java:
##########
@@ -62,7 +71,45 @@ public ApacheDubboServiceBeanListener(final PropertiesConfig clientConfig,
                                           final ShenyuClientRegisterRepository shenyuClientRegisterRepository) {
         super(clientConfig, shenyuClientRegisterRepository);
     }
-    
+
+    @Override
+    protected List<ApiDocRegisterDTO> buildApiDocDTO(final Class<?> clazz, final Method method) {
+        final String contextPath = getContextPath();
+        String apiDesc = Stream.of(method.getDeclaredAnnotations()).filter(item -> item instanceof ApiDoc).findAny().map(item -> {
+            ApiDoc apiDoc = (ApiDoc) item;
+            return apiDoc.desc();
+        }).orElse("");
+        String superPath = buildApiSuperPath(clazz, AnnotatedElementUtils.findMergedAnnotation(clazz, getAnnotationType()));
+        if (superPath.indexOf("*") > 0) {
+            superPath = superPath.substring(0, superPath.lastIndexOf("/"));
+        }
+        ShenyuDubboClient shenyuDubboClient = AnnotatedElementUtils.findMergedAnnotation(method, ShenyuDubboClient.class);
+        if (Objects.isNull(shenyuDubboClient)) {
+            return Lists.newArrayList();
+        }
+        List<ApiDocRegisterDTO> list = Lists.newArrayList();
+        String value = shenyuDubboClient.value();
+        String apiPath = contextPath + superPath + value;
+        ApiDocRegisterDTO build = ApiDocRegisterDTO.builder()
+                .consume(ShenyuClientConstants.MEDIA_TYPE_ALL_VALUE)
+                .produce(ShenyuClientConstants.MEDIA_TYPE_ALL_VALUE)
+                .httpMethod(ApiHttpMethodEnum.NOT_HTTP.getValue())
+                .contextPath(contextPath)
+                .ext("{}")
+                .document("{}")
+                .version("v0.01")

Review Comment:
   In `dubbo`, maybe we can build version from `ServiceBean`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shenyu] 847850277 commented on a diff in pull request #4270: [ISSUE #4029] add shenyu-client-api-doc part1 client module

Posted by GitBox <gi...@apache.org>.
847850277 commented on code in PR #4270:
URL: https://github.com/apache/shenyu/pull/4270#discussion_r1056906390


##########
shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/client/AbstractContextRefreshedEventListener.java:
##########
@@ -108,7 +112,24 @@ public void onApplicationEvent(@NonNull final ContextRefreshedEvent event) {
         }
         publisher.publishEvent(buildURIRegisterDTO(context, beans));
         beans.forEach(this::handle);
+        Map<String, Object> apiModules = context.getBeansWithAnnotation(ApiModule.class);
+        apiModules.forEach(this::handleApiDoc);
     }
+
+    private void handleApiDoc(final String name, final Object classes) {

Review Comment:
   fixed



##########
shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/client/AbstractContextRefreshedEventListener.java:
##########
@@ -108,7 +112,24 @@ public void onApplicationEvent(@NonNull final ContextRefreshedEvent event) {
         }
         publisher.publishEvent(buildURIRegisterDTO(context, beans));
         beans.forEach(this::handle);
+        Map<String, Object> apiModules = context.getBeansWithAnnotation(ApiModule.class);
+        apiModules.forEach(this::handleApiDoc);
     }
+
+    private void handleApiDoc(final String name, final Object classes) {
+        Class<?> apiModuleClass = AopUtils.isAopProxy(classes) ? AopUtils.getTargetClass(classes) : classes.getClass();
+        final Method[] methods = ReflectionUtils.getUniqueDeclaredMethods(apiModuleClass);
+        for (Method method : methods) {
+            if (method.isAnnotationPresent(ApiDoc.class)) {
+                List<ApiDocRegisterDTO> apis = buildApiDocDTO(apiModuleClass, method);
+                for (ApiDocRegisterDTO apiDocRegisterDTO : apis) {
+                    publisher.publishEvent(apiDocRegisterDTO);
+                }
+            }
+        }
+    }
+
+    protected abstract List<ApiDocRegisterDTO> buildApiDocDTO(Class<?> clazz, Method method);

Review Comment:
   fixed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shenyu] 847850277 commented on a diff in pull request #4270: [ISSUE #4029] add shenyu-client-api-doc part1 client module

Posted by GitBox <gi...@apache.org>.
847850277 commented on code in PR #4270:
URL: https://github.com/apache/shenyu/pull/4270#discussion_r1056907530


##########
shenyu-client/shenyu-client-sofa/src/main/java/org/apache/shenyu/client/sofa/SofaServiceEventListener.java:
##########
@@ -151,6 +159,44 @@ public void onApplicationEvent(final ContextRefreshedEvent contextRefreshedEvent
         }
     }
 
+    @Override
+    protected List<ApiDocRegisterDTO> buildApiDocDTO(final Class<?> clazz, final Method method) {
+        final String contextPath = getContextPath();
+        String apiDesc = Stream.of(method.getDeclaredAnnotations()).filter(item -> item instanceof ApiDoc).findAny().map(item -> {
+            ApiDoc apiDoc = (ApiDoc) item;
+            return apiDoc.desc();
+        }).orElse("");
+        String superPath = buildApiSuperPath(clazz, AnnotatedElementUtils.findMergedAnnotation(clazz, getAnnotationType()));
+        if (superPath.indexOf("*") > 0) {
+            superPath = superPath.substring(0, superPath.lastIndexOf("/"));
+        }
+        ShenyuSofaClient shenyuSofaClient = AnnotatedElementUtils.findMergedAnnotation(method, ShenyuSofaClient.class);
+        if (Objects.isNull(shenyuSofaClient)) {
+            return Lists.newArrayList();
+        }
+        List<ApiDocRegisterDTO> list = Lists.newArrayList();
+        String value = shenyuSofaClient.value();
+        String apiPath = contextPath + superPath + value;
+        ApiDocRegisterDTO build = ApiDocRegisterDTO.builder()
+                .consume(ShenyuClientConstants.MEDIA_TYPE_ALL_VALUE)
+                .produce(ShenyuClientConstants.MEDIA_TYPE_ALL_VALUE)
+                .httpMethod(ApiHttpMethodEnum.NOT_HTTP.getValue())

Review Comment:
   i read and learn `template method`. and this code looks like `template method`.
   ```java
   private void handleApiDoc(final String name, final Object bean) {
           Class<?> apiModuleClass = AopUtils.isAopProxy(bean) ? AopUtils.getTargetClass(bean) : bean.getClass();
           final Method[] methods = ReflectionUtils.getUniqueDeclaredMethods(apiModuleClass);
           for (Method method : methods) {
               if (method.isAnnotationPresent(ApiDoc.class)) {
                   List<ApiDocRegisterDTO> apis = buildApiDocDTO(bean, method);
                   for (ApiDocRegisterDTO apiDocRegisterDTO : apis) {
                       publisher.publishEvent(apiDocRegisterDTO);
                   }
               }
           }
       }
   ```
   Is it necessary to add another abstract class?
   
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shenyu] dragon-zhang commented on a diff in pull request #4270: [ISSUE #4029] add shenyu-client-api-doc part1 client module

Posted by GitBox <gi...@apache.org>.
dragon-zhang commented on code in PR #4270:
URL: https://github.com/apache/shenyu/pull/4270#discussion_r1057082953


##########
shenyu-client/shenyu-client-http/shenyu-client-springcloud/src/main/java/org/apache/shenyu/client/springcloud/init/SpringCloudClientEventListener.java:
##########
@@ -92,6 +106,123 @@ public SpringCloudClientEventListener(final PropertiesConfig clientConfig,
         mappingAnnotation.add(RequestMapping.class);
     }
 
+    /**
+     * buildApiDocDTO.
+     *
+     * @param clazz  clazz
+     * @param method method
+     * @return ApiDocRegisterDTO
+     */
+    @Override
+    protected List<ApiDocRegisterDTO> buildApiDocDTO(final Class<?> clazz, final Method method) {
+        final String contextPath = getContextPath();
+        String apiDesc = Stream.of(method.getDeclaredAnnotations()).filter(item -> item instanceof ApiDoc).findAny().map(item -> {
+            ApiDoc apiDoc = (ApiDoc) item;
+            return apiDoc.desc();
+        }).orElse("");
+        String superPath = buildApiSuperPath(clazz, AnnotatedElementUtils.findMergedAnnotation(clazz, getAnnotationType()));
+        if (superPath.indexOf("*") > 0) {
+            superPath = superPath.substring(0, superPath.lastIndexOf("/"));
+        }
+        RequestMapping requestMapping = AnnotatedElementUtils.findMergedAnnotation(method, RequestMapping.class);
+        if (Objects.nonNull(requestMapping)) {
+            List<ApiDocRegisterDTO> list = Lists.newArrayList();
+            String produce = requestMapping.produces().length == 0 ? ShenyuClientConstants.MEDIA_TYPE_ALL_VALUE : String.join(",", requestMapping.produces());
+            String consume = requestMapping.consumes().length == 0 ? ShenyuClientConstants.MEDIA_TYPE_ALL_VALUE : String.join(",", requestMapping.consumes());
+            String[] values = requestMapping.value();
+            for (String value : values) {
+                String apiPath = contextPath + superPath + value;
+                RequestMethod[] requestMethods = requestMapping.method();
+                if (requestMethods.length == 0) {
+                    requestMethods = RequestMethod.values();
+                }
+                for (RequestMethod requestMethod : requestMethods) {
+                    ApiDocRegisterDTO build = ApiDocRegisterDTO.builder()
+                            .consume(consume)
+                            .produce(produce)
+                            .httpMethod(ApiHttpMethodEnum.getValueByName(String.valueOf(requestMethod)))
+                            .contextPath(contextPath)
+                            .ext("{}")
+                            .document("{}")
+                            .version("v0.01")
+                            .rpcType(RpcTypeEnum.SPRING_CLOUD.getName())
+                            .apiDesc(apiDesc)
+                            .apiPath(apiPath)
+                            .apiSource(1)
+                            .state(1)
+                            .apiOwner("admin")
+                            .eventType(EventType.REGISTER)
+                            .build();
+                    list.add(build);
+                }
+            }
+            return list;
+        } else {
+            return apiDocRegisterDTOListByDeclaredAnnotations(contextPath, superPath, method, apiDesc);
+        }
+    }
+
+    private List<ApiDocRegisterDTO> apiDocRegisterDTOListByDeclaredAnnotations(final String contextPath, final String superPath, final Method method, final String apiDesc) {
+        List<ApiDocRegisterDTO> list = Lists.newArrayList();
+        Map<ApiHttpMethodEnum, Triple<String[], String[], String[]>> methodConsumeProduceValueMap = httpMethodConsumeProduceValueMap(method);
+        methodConsumeProduceValueMap.forEach((k, v) -> {
+            String[] values = v.getRight();
+            String consume = v.getLeft().length == 0 ? ShenyuClientConstants.MEDIA_TYPE_ALL_VALUE : String.join(",", v.getLeft());
+            String produce = v.getMiddle().length == 0 ? ShenyuClientConstants.MEDIA_TYPE_ALL_VALUE : String.join(",", v.getMiddle());
+            for (String value : values) {
+                String apiPath = contextPath + superPath + value;
+                ApiDocRegisterDTO build = ApiDocRegisterDTO.builder()
+                        .consume(consume)
+                        .produce(produce)
+                        .httpMethod(k.getValue())
+                        .contextPath(contextPath)
+                        .ext("{}")
+                        .document("{}")
+                        .version("v0.01")
+                        .rpcType(RpcTypeEnum.SPRING_CLOUD.getName())
+                        .apiDesc(apiDesc)
+                        .apiPath(apiPath)
+                        .apiSource(1)
+                        .state(1)
+                        .apiOwner("admin")
+                        .eventType(EventType.REGISTER)
+                        .build();
+                list.add(build);
+            }
+        });
+        return list;
+    }
+
+    private Map<ApiHttpMethodEnum, Triple<String[], String[], String[]>> httpMethodConsumeProduceValueMap(final Method method) {
+        Map<ApiHttpMethodEnum, Triple<String[], String[], String[]>> map = Maps.newHashMap();
+        GetMapping getMapping = AnnotatedElementUtils.findMergedAnnotation(method, GetMapping.class);
+        if (Objects.nonNull(getMapping)) {
+            map.put(ApiHttpMethodEnum.GET, Triple.of(getMapping.consumes(), getMapping.produces(), getMapping.value()));
+            return map;
+        }

Review Comment:
   Yes, but `GetMapping` is a derived annotation of `RequestMapping`, and all the attributes come from `RequestMapping`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shenyu] dragon-zhang commented on a diff in pull request #4270: [ISSUE #4029] add shenyu-client-api-doc part1 client module

Posted by GitBox <gi...@apache.org>.
dragon-zhang commented on code in PR #4270:
URL: https://github.com/apache/shenyu/pull/4270#discussion_r1051332378


##########
shenyu-client/shenyu-client-http/shenyu-client-springcloud/src/main/java/org/apache/shenyu/client/springcloud/init/SpringCloudClientEventListener.java:
##########
@@ -92,6 +106,123 @@ public SpringCloudClientEventListener(final PropertiesConfig clientConfig,
         mappingAnnotation.add(RequestMapping.class);
     }
 
+    /**
+     * buildApiDocDTO.
+     *
+     * @param clazz  clazz
+     * @param method method
+     * @return ApiDocRegisterDTO
+     */
+    @Override
+    protected List<ApiDocRegisterDTO> buildApiDocDTO(final Class<?> clazz, final Method method) {
+        final String contextPath = getContextPath();
+        String apiDesc = Stream.of(method.getDeclaredAnnotations()).filter(item -> item instanceof ApiDoc).findAny().map(item -> {
+            ApiDoc apiDoc = (ApiDoc) item;
+            return apiDoc.desc();
+        }).orElse("");
+        String superPath = buildApiSuperPath(clazz, AnnotatedElementUtils.findMergedAnnotation(clazz, getAnnotationType()));
+        if (superPath.indexOf("*") > 0) {
+            superPath = superPath.substring(0, superPath.lastIndexOf("/"));
+        }
+        RequestMapping requestMapping = AnnotatedElementUtils.findMergedAnnotation(method, RequestMapping.class);
+        if (Objects.nonNull(requestMapping)) {
+            List<ApiDocRegisterDTO> list = Lists.newArrayList();
+            String produce = requestMapping.produces().length == 0 ? ShenyuClientConstants.MEDIA_TYPE_ALL_VALUE : String.join(",", requestMapping.produces());
+            String consume = requestMapping.consumes().length == 0 ? ShenyuClientConstants.MEDIA_TYPE_ALL_VALUE : String.join(",", requestMapping.consumes());
+            String[] values = requestMapping.value();
+            for (String value : values) {
+                String apiPath = contextPath + superPath + value;
+                RequestMethod[] requestMethods = requestMapping.method();
+                if (requestMethods.length == 0) {
+                    requestMethods = RequestMethod.values();
+                }
+                for (RequestMethod requestMethod : requestMethods) {
+                    ApiDocRegisterDTO build = ApiDocRegisterDTO.builder()
+                            .consume(consume)
+                            .produce(produce)
+                            .httpMethod(ApiHttpMethodEnum.getValueByName(String.valueOf(requestMethod)))
+                            .contextPath(contextPath)
+                            .ext("{}")
+                            .document("{}")
+                            .version("v0.01")
+                            .rpcType(RpcTypeEnum.SPRING_CLOUD.getName())
+                            .apiDesc(apiDesc)
+                            .apiPath(apiPath)
+                            .apiSource(1)
+                            .state(1)
+                            .apiOwner("admin")
+                            .eventType(EventType.REGISTER)
+                            .build();
+                    list.add(build);
+                }
+            }
+            return list;
+        } else {
+            return apiDocRegisterDTOListByDeclaredAnnotations(contextPath, superPath, method, apiDesc);
+        }
+    }
+
+    private List<ApiDocRegisterDTO> apiDocRegisterDTOListByDeclaredAnnotations(final String contextPath, final String superPath, final Method method, final String apiDesc) {
+        List<ApiDocRegisterDTO> list = Lists.newArrayList();
+        Map<ApiHttpMethodEnum, Triple<String[], String[], String[]>> methodConsumeProduceValueMap = httpMethodConsumeProduceValueMap(method);
+        methodConsumeProduceValueMap.forEach((k, v) -> {
+            String[] values = v.getRight();
+            String consume = v.getLeft().length == 0 ? ShenyuClientConstants.MEDIA_TYPE_ALL_VALUE : String.join(",", v.getLeft());
+            String produce = v.getMiddle().length == 0 ? ShenyuClientConstants.MEDIA_TYPE_ALL_VALUE : String.join(",", v.getMiddle());
+            for (String value : values) {
+                String apiPath = contextPath + superPath + value;
+                ApiDocRegisterDTO build = ApiDocRegisterDTO.builder()
+                        .consume(consume)
+                        .produce(produce)
+                        .httpMethod(k.getValue())
+                        .contextPath(contextPath)
+                        .ext("{}")
+                        .document("{}")
+                        .version("v0.01")
+                        .rpcType(RpcTypeEnum.SPRING_CLOUD.getName())
+                        .apiDesc(apiDesc)
+                        .apiPath(apiPath)
+                        .apiSource(1)
+                        .state(1)
+                        .apiOwner("admin")
+                        .eventType(EventType.REGISTER)
+                        .build();
+                list.add(build);
+            }
+        });
+        return list;
+    }
+
+    private Map<ApiHttpMethodEnum, Triple<String[], String[], String[]>> httpMethodConsumeProduceValueMap(final Method method) {
+        Map<ApiHttpMethodEnum, Triple<String[], String[], String[]>> map = Maps.newHashMap();
+        GetMapping getMapping = AnnotatedElementUtils.findMergedAnnotation(method, GetMapping.class);
+        if (Objects.nonNull(getMapping)) {
+            map.put(ApiHttpMethodEnum.GET, Triple.of(getMapping.consumes(), getMapping.produces(), getMapping.value()));
+            return map;
+        }

Review Comment:
   How about this ?
   ```java
   RequestMapping mapping = AnnotatedElementUtils.findMergedAnnotation(method, RequestMapping.class);
   for(RequestMethod m : mapping.method()) {
       map.put(ApiHttpMethodEnum.valueOf(m.name()), Triple.of(mapping.consumes(), mapping.produces(), mapping.value()));
   }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shenyu] dragon-zhang commented on a diff in pull request #4270: [ISSUE #4029] add shenyu-client-api-doc part1 client module

Posted by GitBox <gi...@apache.org>.
dragon-zhang commented on code in PR #4270:
URL: https://github.com/apache/shenyu/pull/4270#discussion_r1057159457


##########
shenyu-client/shenyu-client-dubbo/shenyu-client-apache-dubbo/src/main/java/org/apache/shenyu/client/apache/dubbo/ApacheDubboServiceBeanListener.java:
##########
@@ -62,7 +71,45 @@ public ApacheDubboServiceBeanListener(final PropertiesConfig clientConfig,
                                           final ShenyuClientRegisterRepository shenyuClientRegisterRepository) {
         super(clientConfig, shenyuClientRegisterRepository);
     }
-    
+
+    @Override
+    protected List<ApiDocRegisterDTO> buildApiDocDTO(final Class<?> clazz, final Method method) {
+        final String contextPath = getContextPath();
+        String apiDesc = Stream.of(method.getDeclaredAnnotations()).filter(item -> item instanceof ApiDoc).findAny().map(item -> {
+            ApiDoc apiDoc = (ApiDoc) item;
+            return apiDoc.desc();
+        }).orElse("");
+        String superPath = buildApiSuperPath(clazz, AnnotatedElementUtils.findMergedAnnotation(clazz, getAnnotationType()));
+        if (superPath.indexOf("*") > 0) {
+            superPath = superPath.substring(0, superPath.lastIndexOf("/"));
+        }
+        ShenyuDubboClient shenyuDubboClient = AnnotatedElementUtils.findMergedAnnotation(method, ShenyuDubboClient.class);
+        if (Objects.isNull(shenyuDubboClient)) {
+            return Lists.newArrayList();
+        }
+        List<ApiDocRegisterDTO> list = Lists.newArrayList();
+        String value = shenyuDubboClient.value();
+        String apiPath = contextPath + superPath + value;
+        ApiDocRegisterDTO build = ApiDocRegisterDTO.builder()
+                .consume(ShenyuClientConstants.MEDIA_TYPE_ALL_VALUE)
+                .produce(ShenyuClientConstants.MEDIA_TYPE_ALL_VALUE)
+                .httpMethod(ApiHttpMethodEnum.NOT_HTTP.getValue())
+                .contextPath(contextPath)
+                .ext("{}")
+                .document("{}")
+                .version("v0.01")

Review Comment:
   try config it in `<dubbo:service version="1.0.0">` in xml, or `@DubboService(version="1.0.0")` in code.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shenyu] dragon-zhang merged pull request #4270: [ISSUE #4029] add shenyu-client-api-doc part1 client module

Posted by GitBox <gi...@apache.org>.
dragon-zhang merged PR #4270:
URL: https://github.com/apache/shenyu/pull/4270


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shenyu] 847850277 commented on a diff in pull request #4270: [ISSUE #4029] add shenyu-client-api-doc part1 client module

Posted by GitBox <gi...@apache.org>.
847850277 commented on code in PR #4270:
URL: https://github.com/apache/shenyu/pull/4270#discussion_r1059940691


##########
shenyu-client/shenyu-client-sofa/src/main/java/org/apache/shenyu/client/sofa/SofaServiceEventListener.java:
##########
@@ -151,6 +159,44 @@ public void onApplicationEvent(final ContextRefreshedEvent contextRefreshedEvent
         }
     }
 
+    @Override
+    protected List<ApiDocRegisterDTO> buildApiDocDTO(final Class<?> clazz, final Method method) {
+        final String contextPath = getContextPath();
+        String apiDesc = Stream.of(method.getDeclaredAnnotations()).filter(item -> item instanceof ApiDoc).findAny().map(item -> {
+            ApiDoc apiDoc = (ApiDoc) item;
+            return apiDoc.desc();
+        }).orElse("");
+        String superPath = buildApiSuperPath(clazz, AnnotatedElementUtils.findMergedAnnotation(clazz, getAnnotationType()));
+        if (superPath.indexOf("*") > 0) {
+            superPath = superPath.substring(0, superPath.lastIndexOf("/"));
+        }
+        ShenyuSofaClient shenyuSofaClient = AnnotatedElementUtils.findMergedAnnotation(method, ShenyuSofaClient.class);
+        if (Objects.isNull(shenyuSofaClient)) {
+            return Lists.newArrayList();
+        }
+        List<ApiDocRegisterDTO> list = Lists.newArrayList();
+        String value = shenyuSofaClient.value();
+        String apiPath = contextPath + superPath + value;
+        ApiDocRegisterDTO build = ApiDocRegisterDTO.builder()
+                .consume(ShenyuClientConstants.MEDIA_TYPE_ALL_VALUE)
+                .produce(ShenyuClientConstants.MEDIA_TYPE_ALL_VALUE)
+                .httpMethod(ApiHttpMethodEnum.NOT_HTTP.getValue())

Review Comment:
   > I think yes.
   
   fix it,The template method is used to design the pattern, but I don't think it is necessary to add new subclasses. Do you think the current implementation method is OK?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shenyu] dragon-zhang commented on a diff in pull request #4270: [ISSUE #4029] add shenyu-client-api-doc part1 client module

Posted by GitBox <gi...@apache.org>.
dragon-zhang commented on code in PR #4270:
URL: https://github.com/apache/shenyu/pull/4270#discussion_r1051305122


##########
shenyu-client/shenyu-client-dubbo/shenyu-client-alibaba-dubbo/src/main/java/org/apache/shenyu/client/alibaba/dubbo/AlibabaDubboServiceBeanListener.java:
##########
@@ -60,6 +69,44 @@ public AlibabaDubboServiceBeanListener(final PropertiesConfig clientConfig,
         super(clientConfig, shenyuClientRegisterRepository);
     }
 
+    @Override
+    protected List<ApiDocRegisterDTO> buildApiDocDTO(final Class<?> clazz, final Method method) {
+        final String contextPath = getContextPath();
+        String apiDesc = Stream.of(method.getDeclaredAnnotations()).filter(item -> item instanceof ApiDoc).findAny().map(item -> {
+            ApiDoc apiDoc = (ApiDoc) item;
+            return apiDoc.desc();
+        }).orElse("");
+        String superPath = buildApiSuperPath(clazz, AnnotatedElementUtils.findMergedAnnotation(clazz, getAnnotationType()));
+        if (superPath.indexOf("*") > 0) {
+            superPath = superPath.substring(0, superPath.lastIndexOf("/"));
+        }
+        ShenyuDubboClient shenyuDubboClient = AnnotatedElementUtils.findMergedAnnotation(method, ShenyuDubboClient.class);
+        if (Objects.isNull(shenyuDubboClient)) {
+            return Lists.newArrayList();
+        }
+        List<ApiDocRegisterDTO> list = Lists.newArrayList();
+        String value = shenyuDubboClient.value();
+        String apiPath = contextPath + superPath + value;
+        ApiDocRegisterDTO build = ApiDocRegisterDTO.builder()
+                .consume(ShenyuClientConstants.MEDIA_TYPE_ALL_VALUE)
+                .produce(ShenyuClientConstants.MEDIA_TYPE_ALL_VALUE)
+                .httpMethod(ApiHttpMethodEnum.NOT_HTTP.getValue())
+                .contextPath(contextPath)
+                .ext("{}")
+                .document("{}")
+                .version("v0.01")
+                .rpcType(RpcTypeEnum.DUBBO.getName())
+                .apiDesc(apiDesc)
+                .apiPath(apiPath)
+                .apiSource(1)
+                .state(1)

Review Comment:
   `apiSource` and `state`, please use an enum.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shenyu] dragon-zhang commented on a diff in pull request #4270: [ISSUE #4029] add shenyu-client-api-doc part1 client module

Posted by GitBox <gi...@apache.org>.
dragon-zhang commented on code in PR #4270:
URL: https://github.com/apache/shenyu/pull/4270#discussion_r1051303962


##########
shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/client/AbstractContextRefreshedEventListener.java:
##########
@@ -108,7 +112,24 @@ public void onApplicationEvent(@NonNull final ContextRefreshedEvent event) {
         }
         publisher.publishEvent(buildURIRegisterDTO(context, beans));
         beans.forEach(this::handle);
+        Map<String, Object> apiModules = context.getBeansWithAnnotation(ApiModule.class);
+        apiModules.forEach(this::handleApiDoc);
     }
+
+    private void handleApiDoc(final String name, final Object classes) {
+        Class<?> apiModuleClass = AopUtils.isAopProxy(classes) ? AopUtils.getTargetClass(classes) : classes.getClass();
+        final Method[] methods = ReflectionUtils.getUniqueDeclaredMethods(apiModuleClass);
+        for (Method method : methods) {
+            if (method.isAnnotationPresent(ApiDoc.class)) {
+                List<ApiDocRegisterDTO> apis = buildApiDocDTO(apiModuleClass, method);
+                for (ApiDocRegisterDTO apiDocRegisterDTO : apis) {
+                    publisher.publishEvent(apiDocRegisterDTO);
+                }
+            }
+        }
+    }
+
+    protected abstract List<ApiDocRegisterDTO> buildApiDocDTO(Class<?> clazz, Method method);

Review Comment:
   better to add `Object bean` param.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shenyu] 847850277 commented on a diff in pull request #4270: [ISSUE #4029] add shenyu-client-api-doc part1 client module

Posted by GitBox <gi...@apache.org>.
847850277 commented on code in PR #4270:
URL: https://github.com/apache/shenyu/pull/4270#discussion_r1057123063


##########
shenyu-client/shenyu-client-sofa/src/main/java/org/apache/shenyu/client/sofa/SofaServiceEventListener.java:
##########
@@ -151,6 +159,44 @@ public void onApplicationEvent(final ContextRefreshedEvent contextRefreshedEvent
         }
     }
 
+    @Override
+    protected List<ApiDocRegisterDTO> buildApiDocDTO(final Class<?> clazz, final Method method) {
+        final String contextPath = getContextPath();
+        String apiDesc = Stream.of(method.getDeclaredAnnotations()).filter(item -> item instanceof ApiDoc).findAny().map(item -> {
+            ApiDoc apiDoc = (ApiDoc) item;
+            return apiDoc.desc();
+        }).orElse("");
+        String superPath = buildApiSuperPath(clazz, AnnotatedElementUtils.findMergedAnnotation(clazz, getAnnotationType()));
+        if (superPath.indexOf("*") > 0) {
+            superPath = superPath.substring(0, superPath.lastIndexOf("/"));
+        }
+        ShenyuSofaClient shenyuSofaClient = AnnotatedElementUtils.findMergedAnnotation(method, ShenyuSofaClient.class);
+        if (Objects.isNull(shenyuSofaClient)) {
+            return Lists.newArrayList();
+        }
+        List<ApiDocRegisterDTO> list = Lists.newArrayList();
+        String value = shenyuSofaClient.value();
+        String apiPath = contextPath + superPath + value;
+        ApiDocRegisterDTO build = ApiDocRegisterDTO.builder()
+                .consume(ShenyuClientConstants.MEDIA_TYPE_ALL_VALUE)
+                .produce(ShenyuClientConstants.MEDIA_TYPE_ALL_VALUE)
+                .httpMethod(ApiHttpMethodEnum.NOT_HTTP.getValue())

Review Comment:
   > I think yes.
   
   i will try



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shenyu] dragon-zhang commented on a diff in pull request #4270: [ISSUE #4029] add shenyu-client-api-doc part1 client module

Posted by GitBox <gi...@apache.org>.
dragon-zhang commented on code in PR #4270:
URL: https://github.com/apache/shenyu/pull/4270#discussion_r1051332803


##########
shenyu-client/shenyu-client-sofa/src/main/java/org/apache/shenyu/client/sofa/SofaServiceEventListener.java:
##########
@@ -151,6 +159,44 @@ public void onApplicationEvent(final ContextRefreshedEvent contextRefreshedEvent
         }
     }
 
+    @Override
+    protected List<ApiDocRegisterDTO> buildApiDocDTO(final Class<?> clazz, final Method method) {
+        final String contextPath = getContextPath();
+        String apiDesc = Stream.of(method.getDeclaredAnnotations()).filter(item -> item instanceof ApiDoc).findAny().map(item -> {
+            ApiDoc apiDoc = (ApiDoc) item;
+            return apiDoc.desc();
+        }).orElse("");
+        String superPath = buildApiSuperPath(clazz, AnnotatedElementUtils.findMergedAnnotation(clazz, getAnnotationType()));
+        if (superPath.indexOf("*") > 0) {
+            superPath = superPath.substring(0, superPath.lastIndexOf("/"));
+        }
+        ShenyuSofaClient shenyuSofaClient = AnnotatedElementUtils.findMergedAnnotation(method, ShenyuSofaClient.class);
+        if (Objects.isNull(shenyuSofaClient)) {
+            return Lists.newArrayList();
+        }
+        List<ApiDocRegisterDTO> list = Lists.newArrayList();
+        String value = shenyuSofaClient.value();
+        String apiPath = contextPath + superPath + value;
+        ApiDocRegisterDTO build = ApiDocRegisterDTO.builder()
+                .consume(ShenyuClientConstants.MEDIA_TYPE_ALL_VALUE)
+                .produce(ShenyuClientConstants.MEDIA_TYPE_ALL_VALUE)
+                .httpMethod(ApiHttpMethodEnum.NOT_HTTP.getValue())

Review Comment:
   I have seen a lot of similar code. Can you use template method pattern to abstract another parent class? The new abstract class extends from `AbstractContextRefreshedEventListener`, and `SofaServiceEventListener` extends from the new abstract class.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shenyu] dragon-zhang commented on a diff in pull request #4270: [ISSUE #4029] add shenyu-client-api-doc part1 client module

Posted by GitBox <gi...@apache.org>.
dragon-zhang commented on code in PR #4270:
URL: https://github.com/apache/shenyu/pull/4270#discussion_r1057159457


##########
shenyu-client/shenyu-client-dubbo/shenyu-client-apache-dubbo/src/main/java/org/apache/shenyu/client/apache/dubbo/ApacheDubboServiceBeanListener.java:
##########
@@ -62,7 +71,45 @@ public ApacheDubboServiceBeanListener(final PropertiesConfig clientConfig,
                                           final ShenyuClientRegisterRepository shenyuClientRegisterRepository) {
         super(clientConfig, shenyuClientRegisterRepository);
     }
-    
+
+    @Override
+    protected List<ApiDocRegisterDTO> buildApiDocDTO(final Class<?> clazz, final Method method) {
+        final String contextPath = getContextPath();
+        String apiDesc = Stream.of(method.getDeclaredAnnotations()).filter(item -> item instanceof ApiDoc).findAny().map(item -> {
+            ApiDoc apiDoc = (ApiDoc) item;
+            return apiDoc.desc();
+        }).orElse("");
+        String superPath = buildApiSuperPath(clazz, AnnotatedElementUtils.findMergedAnnotation(clazz, getAnnotationType()));
+        if (superPath.indexOf("*") > 0) {
+            superPath = superPath.substring(0, superPath.lastIndexOf("/"));
+        }
+        ShenyuDubboClient shenyuDubboClient = AnnotatedElementUtils.findMergedAnnotation(method, ShenyuDubboClient.class);
+        if (Objects.isNull(shenyuDubboClient)) {
+            return Lists.newArrayList();
+        }
+        List<ApiDocRegisterDTO> list = Lists.newArrayList();
+        String value = shenyuDubboClient.value();
+        String apiPath = contextPath + superPath + value;
+        ApiDocRegisterDTO build = ApiDocRegisterDTO.builder()
+                .consume(ShenyuClientConstants.MEDIA_TYPE_ALL_VALUE)
+                .produce(ShenyuClientConstants.MEDIA_TYPE_ALL_VALUE)
+                .httpMethod(ApiHttpMethodEnum.NOT_HTTP.getValue())
+                .contextPath(contextPath)
+                .ext("{}")
+                .document("{}")
+                .version("v0.01")

Review Comment:
   try config it in `<dubbo:service version="1.0.0">` in xml, or `@DubboService(version="1.0.0")` in code, just because we doesn't config it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shenyu] 847850277 commented on a diff in pull request #4270: [ISSUE #4029] add shenyu-client-api-doc part1 client module

Posted by GitBox <gi...@apache.org>.
847850277 commented on code in PR #4270:
URL: https://github.com/apache/shenyu/pull/4270#discussion_r1059939445


##########
shenyu-client/shenyu-client-dubbo/shenyu-client-apache-dubbo/src/main/java/org/apache/shenyu/client/apache/dubbo/ApacheDubboServiceBeanListener.java:
##########
@@ -62,7 +71,45 @@ public ApacheDubboServiceBeanListener(final PropertiesConfig clientConfig,
                                           final ShenyuClientRegisterRepository shenyuClientRegisterRepository) {
         super(clientConfig, shenyuClientRegisterRepository);
     }
-    
+
+    @Override
+    protected List<ApiDocRegisterDTO> buildApiDocDTO(final Class<?> clazz, final Method method) {
+        final String contextPath = getContextPath();
+        String apiDesc = Stream.of(method.getDeclaredAnnotations()).filter(item -> item instanceof ApiDoc).findAny().map(item -> {
+            ApiDoc apiDoc = (ApiDoc) item;
+            return apiDoc.desc();
+        }).orElse("");
+        String superPath = buildApiSuperPath(clazz, AnnotatedElementUtils.findMergedAnnotation(clazz, getAnnotationType()));
+        if (superPath.indexOf("*") > 0) {
+            superPath = superPath.substring(0, superPath.lastIndexOf("/"));
+        }
+        ShenyuDubboClient shenyuDubboClient = AnnotatedElementUtils.findMergedAnnotation(method, ShenyuDubboClient.class);
+        if (Objects.isNull(shenyuDubboClient)) {
+            return Lists.newArrayList();
+        }
+        List<ApiDocRegisterDTO> list = Lists.newArrayList();
+        String value = shenyuDubboClient.value();
+        String apiPath = contextPath + superPath + value;
+        ApiDocRegisterDTO build = ApiDocRegisterDTO.builder()
+                .consume(ShenyuClientConstants.MEDIA_TYPE_ALL_VALUE)
+                .produce(ShenyuClientConstants.MEDIA_TYPE_ALL_VALUE)
+                .httpMethod(ApiHttpMethodEnum.NOT_HTTP.getValue())
+                .contextPath(contextPath)
+                .ext("{}")
+                .document("{}")
+                .version("v0.01")

Review Comment:
    i will try



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shenyu] dragon-zhang commented on a diff in pull request #4270: [ISSUE #4029] add shenyu-client-api-doc part1 client module

Posted by GitBox <gi...@apache.org>.
dragon-zhang commented on code in PR #4270:
URL: https://github.com/apache/shenyu/pull/4270#discussion_r1051303797


##########
shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/client/AbstractContextRefreshedEventListener.java:
##########
@@ -108,7 +112,24 @@ public void onApplicationEvent(@NonNull final ContextRefreshedEvent event) {
         }
         publisher.publishEvent(buildURIRegisterDTO(context, beans));
         beans.forEach(this::handle);
+        Map<String, Object> apiModules = context.getBeansWithAnnotation(ApiModule.class);
+        apiModules.forEach(this::handleApiDoc);
     }
+
+    private void handleApiDoc(final String name, final Object classes) {

Review Comment:
   `Object classes` rename to `Object bean`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shenyu] 847850277 commented on a diff in pull request #4270: [ISSUE #4029] add shenyu-client-api-doc part1 client module

Posted by GitBox <gi...@apache.org>.
847850277 commented on code in PR #4270:
URL: https://github.com/apache/shenyu/pull/4270#discussion_r1056907317


##########
shenyu-client/shenyu-client-http/shenyu-client-springcloud/src/main/java/org/apache/shenyu/client/springcloud/init/SpringCloudClientEventListener.java:
##########
@@ -92,6 +106,123 @@ public SpringCloudClientEventListener(final PropertiesConfig clientConfig,
         mappingAnnotation.add(RequestMapping.class);
     }
 
+    /**
+     * buildApiDocDTO.
+     *
+     * @param clazz  clazz
+     * @param method method
+     * @return ApiDocRegisterDTO
+     */
+    @Override
+    protected List<ApiDocRegisterDTO> buildApiDocDTO(final Class<?> clazz, final Method method) {
+        final String contextPath = getContextPath();
+        String apiDesc = Stream.of(method.getDeclaredAnnotations()).filter(item -> item instanceof ApiDoc).findAny().map(item -> {
+            ApiDoc apiDoc = (ApiDoc) item;
+            return apiDoc.desc();
+        }).orElse("");
+        String superPath = buildApiSuperPath(clazz, AnnotatedElementUtils.findMergedAnnotation(clazz, getAnnotationType()));
+        if (superPath.indexOf("*") > 0) {
+            superPath = superPath.substring(0, superPath.lastIndexOf("/"));
+        }
+        RequestMapping requestMapping = AnnotatedElementUtils.findMergedAnnotation(method, RequestMapping.class);
+        if (Objects.nonNull(requestMapping)) {
+            List<ApiDocRegisterDTO> list = Lists.newArrayList();
+            String produce = requestMapping.produces().length == 0 ? ShenyuClientConstants.MEDIA_TYPE_ALL_VALUE : String.join(",", requestMapping.produces());
+            String consume = requestMapping.consumes().length == 0 ? ShenyuClientConstants.MEDIA_TYPE_ALL_VALUE : String.join(",", requestMapping.consumes());
+            String[] values = requestMapping.value();
+            for (String value : values) {
+                String apiPath = contextPath + superPath + value;
+                RequestMethod[] requestMethods = requestMapping.method();
+                if (requestMethods.length == 0) {
+                    requestMethods = RequestMethod.values();
+                }
+                for (RequestMethod requestMethod : requestMethods) {
+                    ApiDocRegisterDTO build = ApiDocRegisterDTO.builder()
+                            .consume(consume)
+                            .produce(produce)
+                            .httpMethod(ApiHttpMethodEnum.getValueByName(String.valueOf(requestMethod)))
+                            .contextPath(contextPath)
+                            .ext("{}")
+                            .document("{}")
+                            .version("v0.01")
+                            .rpcType(RpcTypeEnum.SPRING_CLOUD.getName())
+                            .apiDesc(apiDesc)
+                            .apiPath(apiPath)
+                            .apiSource(1)
+                            .state(1)
+                            .apiOwner("admin")
+                            .eventType(EventType.REGISTER)
+                            .build();
+                    list.add(build);
+                }
+            }
+            return list;
+        } else {
+            return apiDocRegisterDTOListByDeclaredAnnotations(contextPath, superPath, method, apiDesc);
+        }
+    }
+
+    private List<ApiDocRegisterDTO> apiDocRegisterDTOListByDeclaredAnnotations(final String contextPath, final String superPath, final Method method, final String apiDesc) {
+        List<ApiDocRegisterDTO> list = Lists.newArrayList();
+        Map<ApiHttpMethodEnum, Triple<String[], String[], String[]>> methodConsumeProduceValueMap = httpMethodConsumeProduceValueMap(method);
+        methodConsumeProduceValueMap.forEach((k, v) -> {
+            String[] values = v.getRight();
+            String consume = v.getLeft().length == 0 ? ShenyuClientConstants.MEDIA_TYPE_ALL_VALUE : String.join(",", v.getLeft());
+            String produce = v.getMiddle().length == 0 ? ShenyuClientConstants.MEDIA_TYPE_ALL_VALUE : String.join(",", v.getMiddle());
+            for (String value : values) {
+                String apiPath = contextPath + superPath + value;
+                ApiDocRegisterDTO build = ApiDocRegisterDTO.builder()
+                        .consume(consume)
+                        .produce(produce)
+                        .httpMethod(k.getValue())
+                        .contextPath(contextPath)
+                        .ext("{}")
+                        .document("{}")
+                        .version("v0.01")
+                        .rpcType(RpcTypeEnum.SPRING_CLOUD.getName())
+                        .apiDesc(apiDesc)
+                        .apiPath(apiPath)
+                        .apiSource(1)
+                        .state(1)
+                        .apiOwner("admin")
+                        .eventType(EventType.REGISTER)
+                        .build();
+                list.add(build);
+            }
+        });
+        return list;
+    }
+
+    private Map<ApiHttpMethodEnum, Triple<String[], String[], String[]>> httpMethodConsumeProduceValueMap(final Method method) {
+        Map<ApiHttpMethodEnum, Triple<String[], String[], String[]>> map = Maps.newHashMap();
+        GetMapping getMapping = AnnotatedElementUtils.findMergedAnnotation(method, GetMapping.class);
+        if (Objects.nonNull(getMapping)) {
+            map.put(ApiHttpMethodEnum.GET, Triple.of(getMapping.consumes(), getMapping.produces(), getMapping.value()));
+            return map;
+        }

Review Comment:
   in SpringMvcClientEventListener or SpringCloudClientEventListener. this code in line 122. 
   `RequestMapping` or `GetMapping` They are different annotation
   
   
   ```java
   RequestMapping requestMapping = AnnotatedElementUtils.findMergedAnnotation(method, RequestMapping.class);
           if (Objects.nonNull(requestMapping)) {
               List<ApiDocRegisterDTO> list = Lists.newArrayList();
               String produce = requestMapping.produces().length == 0 ? ShenyuClientConstants.MEDIA_TYPE_ALL_VALUE : String.join(",", requestMapping.produces());
               String consume = requestMapping.consumes().length == 0 ? ShenyuClientConstants.MEDIA_TYPE_ALL_VALUE : String.join(",", requestMapping.consumes());
               String[] values = requestMapping.value();
               for (String value : values) {
                   String apiPath = contextPath + superPath + value;
                   RequestMethod[] requestMethods = requestMapping.method();
                   if (requestMethods.length == 0) {
                       requestMethods = RequestMethod.values();
                   }
                   for (RequestMethod requestMethod : requestMethods) {
                       ApiDocRegisterDTO build = ApiDocRegisterDTO.builder()
                               .consume(consume)
                               .produce(produce)
                               .httpMethod(ApiHttpMethodEnum.getValueByName(String.valueOf(requestMethod)))
                               .contextPath(contextPath)
                               .ext("{}")
                               .document("{}")
                               .version("v0.01")
                               .rpcType(RpcTypeEnum.HTTP.getName())
                               .apiDesc(apiDesc)
                               .apiPath(apiPath)
                               .apiSource(ApiSourceEnum.ANNOTATION_GENERATION.getValue())
                               .state(ApiStateEnum.PUBLISHED.getState())
                               .apiOwner("admin")
                               .eventType(EventType.REGISTER)
                               .build();
                       list.add(build);
                   }
               }
               return list;
           }
   
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shenyu] dragon-zhang commented on a diff in pull request #4270: [ISSUE #4029] add shenyu-client-api-doc part1 client module

Posted by GitBox <gi...@apache.org>.
dragon-zhang commented on code in PR #4270:
URL: https://github.com/apache/shenyu/pull/4270#discussion_r1057080212


##########
shenyu-client/shenyu-client-dubbo/shenyu-client-apache-dubbo/src/main/java/org/apache/shenyu/client/apache/dubbo/ApacheDubboServiceBeanListener.java:
##########
@@ -62,7 +71,45 @@ public ApacheDubboServiceBeanListener(final PropertiesConfig clientConfig,
                                           final ShenyuClientRegisterRepository shenyuClientRegisterRepository) {
         super(clientConfig, shenyuClientRegisterRepository);
     }
-    
+
+    @Override
+    protected List<ApiDocRegisterDTO> buildApiDocDTO(final Class<?> clazz, final Method method) {
+        final String contextPath = getContextPath();
+        String apiDesc = Stream.of(method.getDeclaredAnnotations()).filter(item -> item instanceof ApiDoc).findAny().map(item -> {
+            ApiDoc apiDoc = (ApiDoc) item;
+            return apiDoc.desc();
+        }).orElse("");
+        String superPath = buildApiSuperPath(clazz, AnnotatedElementUtils.findMergedAnnotation(clazz, getAnnotationType()));
+        if (superPath.indexOf("*") > 0) {
+            superPath = superPath.substring(0, superPath.lastIndexOf("/"));
+        }
+        ShenyuDubboClient shenyuDubboClient = AnnotatedElementUtils.findMergedAnnotation(method, ShenyuDubboClient.class);
+        if (Objects.isNull(shenyuDubboClient)) {
+            return Lists.newArrayList();
+        }
+        List<ApiDocRegisterDTO> list = Lists.newArrayList();
+        String value = shenyuDubboClient.value();
+        String apiPath = contextPath + superPath + value;
+        ApiDocRegisterDTO build = ApiDocRegisterDTO.builder()
+                .consume(ShenyuClientConstants.MEDIA_TYPE_ALL_VALUE)
+                .produce(ShenyuClientConstants.MEDIA_TYPE_ALL_VALUE)
+                .httpMethod(ApiHttpMethodEnum.NOT_HTTP.getValue())
+                .contextPath(contextPath)
+                .ext("{}")
+                .document("{}")
+                .version("v0.01")

Review Comment:
   I mean `org.apache.dubbo.config.spring.ServiceBean#getVersion`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shenyu] 847850277 commented on a diff in pull request #4270: [ISSUE #4029] add shenyu-client-api-doc part1 client module

Posted by GitBox <gi...@apache.org>.
847850277 commented on code in PR #4270:
URL: https://github.com/apache/shenyu/pull/4270#discussion_r1057122798


##########
shenyu-client/shenyu-client-dubbo/shenyu-client-apache-dubbo/src/main/java/org/apache/shenyu/client/apache/dubbo/ApacheDubboServiceBeanListener.java:
##########
@@ -62,7 +71,45 @@ public ApacheDubboServiceBeanListener(final PropertiesConfig clientConfig,
                                           final ShenyuClientRegisterRepository shenyuClientRegisterRepository) {
         super(clientConfig, shenyuClientRegisterRepository);
     }
-    
+
+    @Override
+    protected List<ApiDocRegisterDTO> buildApiDocDTO(final Class<?> clazz, final Method method) {
+        final String contextPath = getContextPath();
+        String apiDesc = Stream.of(method.getDeclaredAnnotations()).filter(item -> item instanceof ApiDoc).findAny().map(item -> {
+            ApiDoc apiDoc = (ApiDoc) item;
+            return apiDoc.desc();
+        }).orElse("");
+        String superPath = buildApiSuperPath(clazz, AnnotatedElementUtils.findMergedAnnotation(clazz, getAnnotationType()));
+        if (superPath.indexOf("*") > 0) {
+            superPath = superPath.substring(0, superPath.lastIndexOf("/"));
+        }
+        ShenyuDubboClient shenyuDubboClient = AnnotatedElementUtils.findMergedAnnotation(method, ShenyuDubboClient.class);
+        if (Objects.isNull(shenyuDubboClient)) {
+            return Lists.newArrayList();
+        }
+        List<ApiDocRegisterDTO> list = Lists.newArrayList();
+        String value = shenyuDubboClient.value();
+        String apiPath = contextPath + superPath + value;
+        ApiDocRegisterDTO build = ApiDocRegisterDTO.builder()
+                .consume(ShenyuClientConstants.MEDIA_TYPE_ALL_VALUE)
+                .produce(ShenyuClientConstants.MEDIA_TYPE_ALL_VALUE)
+                .httpMethod(ApiHttpMethodEnum.NOT_HTTP.getValue())
+                .contextPath(contextPath)
+                .ext("{}")
+                .document("{}")
+                .version("v0.01")

Review Comment:
   in `alibaba dubbo` or `apache dubbo`. it's seem look like empty.
   
   ![image](https://user-images.githubusercontent.com/12622645/209522023-4e98f563-2b31-410e-bba7-1b766186f486.png)
   
   ![image](https://user-images.githubusercontent.com/12622645/209522035-04b67540-6ec7-4e0c-a07b-458520d0e7aa.png)
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org