You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by li...@apache.org on 2021/01/14 06:20:09 UTC

[dubbo-admin] branch develop updated: fix dubbo api docs (#676)

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

liujun pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/dubbo-admin.git


The following commit(s) were added to refs/heads/develop by this push:
     new 272b598  fix dubbo api docs (#676)
272b598 is described below

commit 272b598b6b39bc9bf751336f0adb8286d4a73c6c
Author: 邪影oO <21...@qq.com>
AuthorDate: Thu Jan 14 14:19:54 2021 +0800

    fix dubbo api docs (#676)
    
    fix #675
---
 .../dubbo/admin/controller/ApiDocsController.java  |  6 ++---
 .../model/dto/docs/CallDubboServiceRequest.java    | 11 +++++++++
 .../dubbo/admin/utils/ApiDocsDubboGenericUtil.java | 28 +++++++++++++---------
 dubbo-admin-ui/src/components/apiDocs/ApiForm.vue  |  3 ++-
 .../src/components/apiDocs/ApiFormItem.vue         |  7 +++---
 dubbo-admin-ui/src/lang/en.js                      |  2 +-
 dubbo-admin-ui/src/lang/zh.js                      |  4 ++--
 7 files changed, 40 insertions(+), 21 deletions(-)

diff --git a/dubbo-admin-server/src/main/java/org/apache/dubbo/admin/controller/ApiDocsController.java b/dubbo-admin-server/src/main/java/org/apache/dubbo/admin/controller/ApiDocsController.java
index 35e2dbc..569e1ea 100644
--- a/dubbo-admin-server/src/main/java/org/apache/dubbo/admin/controller/ApiDocsController.java
+++ b/dubbo-admin-server/src/main/java/org/apache/dubbo/admin/controller/ApiDocsController.java
@@ -112,8 +112,8 @@ public class ApiDocsController {
                     if(paramValue instanceof Map){
                         Map<?, ?> tempMap = (Map<?, ?>) paramValue;
                         if(!tempMap.isEmpty()) {
-                            this.emptyString2Null(tempMap);
-                            paramValues[i] = tempMap.values().stream().findFirst().orElse(null);
+                            Object tempParamValue = tempMap.values().stream().findFirst().orElse(null);
+                            paramValues[i] = this.emptyString2Null(tempParamValue);
                         }
                     } else {
                         paramValues[i] = emptyString2Null(paramValue);
@@ -131,7 +131,7 @@ public class ApiDocsController {
             paramValues = new Object[0];
         }
         CompletableFuture<Object> future = ApiDocsDubboGenericUtil.invoke(dubboCfg.getRegistryCenterUrl(), dubboCfg.getInterfaceClassName(),
-                dubboCfg.getMethodName(), dubboCfg.isAsync(), paramTypes, paramValues);
+                dubboCfg.getMethodName(), dubboCfg.isAsync(), dubboCfg.getVersion(), paramTypes, paramValues);
         try {
             Object objResult = future.get();
             return JSON.toJSONString(objResult, CLASS_NAME_PRE_FILTER);
diff --git a/dubbo-admin-server/src/main/java/org/apache/dubbo/admin/model/dto/docs/CallDubboServiceRequest.java b/dubbo-admin-server/src/main/java/org/apache/dubbo/admin/model/dto/docs/CallDubboServiceRequest.java
index 60c250b..6496849 100644
--- a/dubbo-admin-server/src/main/java/org/apache/dubbo/admin/model/dto/docs/CallDubboServiceRequest.java
+++ b/dubbo-admin-server/src/main/java/org/apache/dubbo/admin/model/dto/docs/CallDubboServiceRequest.java
@@ -36,6 +36,17 @@ public class CallDubboServiceRequest {
     @ApiParam(value = "Whether to call asynchronously, false by default")
     private boolean async = false;
 
+    @ApiParam(value = "The version of API")
+    private String version;
+
+    public String getVersion() {
+        return version;
+    }
+
+    public void setVersion(String version) {
+        this.version = version;
+    }
+
     public String getRegistryCenterUrl() {
         return registryCenterUrl;
     }
diff --git a/dubbo-admin-server/src/main/java/org/apache/dubbo/admin/utils/ApiDocsDubboGenericUtil.java b/dubbo-admin-server/src/main/java/org/apache/dubbo/admin/utils/ApiDocsDubboGenericUtil.java
index 3ce81f3..6200d5c 100644
--- a/dubbo-admin-server/src/main/java/org/apache/dubbo/admin/utils/ApiDocsDubboGenericUtil.java
+++ b/dubbo-admin-server/src/main/java/org/apache/dubbo/admin/utils/ApiDocsDubboGenericUtil.java
@@ -111,12 +111,14 @@ public class ApiDocsDubboGenericUtil {
      * @param: address  address Address of Registration Center
      * @param: interfaceName  Interface full package path
      */
-    private static ReferenceConfig<GenericService> getReferenceConfig(String address, String interfaceName) {
-        ReferenceConfig<GenericService> referenceConfig = referenceCache.get(address + "/" + interfaceName);
+    private static ReferenceConfig<GenericService> getReferenceConfig(String address, String interfaceName, String version) {
+        final String key = buildCacheKey(address, interfaceName, version);
+        ReferenceConfig<GenericService> referenceConfig = referenceCache.get(key);
         if (null == referenceConfig) {
             referenceConfig = new ReferenceConfig<>();
             referenceConfig.setRetries(retries);
             referenceConfig.setTimeout(timeout);
+            referenceConfig.setVersion(version);
             referenceConfig.setApplication(application);
             if (address.startsWith("dubbo")) {
                 referenceConfig.setUrl(address);
@@ -126,7 +128,7 @@ public class ApiDocsDubboGenericUtil {
             referenceConfig.setInterface(interfaceName);
             // Declared as a generic interface
             referenceConfig.setGeneric(true);
-            referenceCache.put(address + "/" + interfaceName, referenceConfig);
+            referenceCache.put(key, referenceConfig);
         }
         return referenceConfig;
     }
@@ -137,9 +139,13 @@ public class ApiDocsDubboGenericUtil {
      * @param interfaceName
      * @return void
      */
-    private static void removeReferenceConfig(String address, String interfaceName) {
+    private static void removeReferenceConfig(String address, String interfaceName, String version) {
         removeRegistryConfig(address);
-        referenceCache.remove(address + "/" + interfaceName);
+        referenceCache.remove(buildCacheKey(address, interfaceName, version));
+    }
+
+    private static String buildCacheKey(String address, String interfaceName, String version) {
+        return address + "/" + interfaceName + "/" + version;
     }
 
     /**
@@ -155,10 +161,10 @@ public class ApiDocsDubboGenericUtil {
      * @param: paramValues
      */
     public static CompletableFuture<Object> invoke(String address, String interfaceName,
-                                                   String methodName, boolean async, String[] paramTypes,
+                                                   String methodName, boolean async, String version, String[] paramTypes,
                                                    Object[] paramValues) {
         CompletableFuture future = null;
-        ReferenceConfig<GenericService> reference = getReferenceConfig(address, interfaceName);
+        ReferenceConfig<GenericService> reference = getReferenceConfig(address, interfaceName, version);
         if (null != reference) {
             GenericService genericService = reference.get();
             if (null != genericService) {
@@ -170,7 +176,7 @@ public class ApiDocsDubboGenericUtil {
             }
             future.exceptionally(ex -> {
                 if (StringUtils.contains(ex.toString(), "Failed to invoke remote method")) {
-                    removeReferenceConfig(address, interfaceName);
+                    removeReferenceConfig(address, interfaceName, version);
                 }
                 return ex;
             });
@@ -190,9 +196,9 @@ public class ApiDocsDubboGenericUtil {
      * @param: paramValues
      */
     public static Object invokeSync(String address, String interfaceName,
-                                    String methodName, String[] paramTypes,
+                                    String methodName, String version, String[] paramTypes,
                                     Object[] paramValues) {
-        ReferenceConfig<GenericService> reference = getReferenceConfig(address, interfaceName);
+        ReferenceConfig<GenericService> reference = getReferenceConfig(address, interfaceName, version);
         if (null != reference) {
             GenericService genericService = reference.get();
             try {
@@ -201,7 +207,7 @@ public class ApiDocsDubboGenericUtil {
                 }
             } catch (Exception ex) {
                 if (StringUtils.contains(ex.toString(), "Failed to invoke remote method")) {
-                    removeReferenceConfig(address, interfaceName);
+                    removeReferenceConfig(address, interfaceName, version);
                 } else {
                     throw ex;
                 }
diff --git a/dubbo-admin-ui/src/components/apiDocs/ApiForm.vue b/dubbo-admin-ui/src/components/apiDocs/ApiForm.vue
index 94fca80..9923b25 100644
--- a/dubbo-admin-ui/src/components/apiDocs/ApiForm.vue
+++ b/dubbo-admin-ui/src/components/apiDocs/ApiForm.vue
@@ -401,7 +401,8 @@ export default {
           async: this.formItemAsync,
           interfaceClassName: this.formItemInterfaceClassName,
           methodName: this.formItemMethodName,
-          registryCenterUrl: this.formItemRegistryCenterUrl
+          registryCenterUrl: this.formItemRegistryCenterUrl,
+          version: this.apiInfoData.apiVersion || ''
         },
         headers: {
           'Content-Type': 'application/json; charset=UTF-8'
diff --git a/dubbo-admin-ui/src/components/apiDocs/ApiFormItem.vue b/dubbo-admin-ui/src/components/apiDocs/ApiFormItem.vue
index 79bf293..d8ede6b 100644
--- a/dubbo-admin-ui/src/components/apiDocs/ApiFormItem.vue
+++ b/dubbo-admin-ui/src/components/apiDocs/ApiFormItem.vue
@@ -178,11 +178,10 @@ export default {
     },
     buildDefaultValue () {
       var defaultValue = this.formItemInfo.get('defaultValue')
-      if (defaultValue) {
-        this.formValues.set(this.buildItemId(), defaultValue)
-      } else {
+      if (!defaultValue) {
         defaultValue = ''
       }
+      this.formValues.set(this.buildItemId(), defaultValue)
       return defaultValue
     },
     buildSelectDefaultValue () {
@@ -192,6 +191,8 @@ export default {
         if (defaultValue) {
           this.selectDefaultValue = defaultValue
           this.formValues.set(this.buildItemId(), defaultValue[0])
+        } else {
+          this.formValues.set(this.buildItemId(), '')
         }
       }
       return this.selectDefaultValue
diff --git a/dubbo-admin-ui/src/lang/en.js b/dubbo-admin-ui/src/lang/en.js
index 893cf06..9fecb4e 100644
--- a/dubbo-admin-ui/src/lang/en.js
+++ b/dubbo-admin-ui/src/lang/en.js
@@ -170,7 +170,7 @@ export default {
       missingInterfaceInfo: 'Missing interface information',
       getApiInfoErr: 'Exception in obtaining interface information',
       api404Err: 'Interface name is incorrect, interface parameters and response information are not found',
-      apiRespDecShowLabel: 'Api Info',
+      apiRespDecShowLabel: 'Response Description',
       apiNameShowLabel: 'Api Name',
       apiPathShowLabel: 'Api Path',
       apiMethodParamInfoLabel: 'Api method parameters',
diff --git a/dubbo-admin-ui/src/lang/zh.js b/dubbo-admin-ui/src/lang/zh.js
index bcde366..36c72e6 100644
--- a/dubbo-admin-ui/src/lang/zh.js
+++ b/dubbo-admin-ui/src/lang/zh.js
@@ -170,12 +170,12 @@ export default {
       missingInterfaceInfo: '缺少接口信息',
       getApiInfoErr: '获取接口信息异常',
       api404Err: '接口名称不正确,没有查找到接口参数和响应信息',
-      apiRespDecShowLabel: '接口说明',
+      apiRespDecShowLabel: '响应说明',
       apiNameShowLabel: '接口名称',
       apiPathShowLabel: '接口位置',
       apiMethodParamInfoLabel: '接口参数',
       apiVersionShowLabel: '接口版本',
-      apiDescriptionShowLabel: '接口描述',
+      apiDescriptionShowLabel: '接口说明',
       isAsyncFormLabel: '是否异步调用(此参数不可修改,根据接口定义的是否异步显示)',
       apiModuleFormLabel: '接口模块(此参数不可修改)',
       apiFunctionNameFormLabel: '接口方法名(此参数不可修改)',