Skip to content
Permalink
Browse files
fix #19 of api docs bug , apache/dubbo-spi-extensions#19 (#707)
  • Loading branch information
KeRan213539 committed Mar 19, 2021
1 parent a7dc202 commit 404b4209a70f9900a266d5f23ae001552e6021b9
Showing 7 changed files with 47 additions and 16 deletions.
@@ -16,6 +16,7 @@
*/
package org.apache.dubbo.admin.controller;

import org.apache.dubbo.admin.annotation.Authority;
import org.apache.dubbo.admin.controller.editors.CustomLocalDateEditor;
import org.apache.dubbo.admin.controller.editors.CustomLocalDateTimeEditor;
import org.apache.dubbo.admin.model.dto.docs.ApiInfoRequest;
@@ -53,6 +54,7 @@
/**
* dubbo doc ui server api.
*/
@Authority(needLogin = true)
@Api(tags = {"dubbo-api-docs-api"})
@RestController
@RequestMapping("/api/{env}/docs")
@@ -131,7 +133,7 @@ public String callDubboService(CallDubboServiceRequest dubboCfg, @RequestBody Li
paramValues = new Object[0];
}
CompletableFuture<Object> future = ApiDocsDubboGenericUtil.invoke(dubboCfg.getRegistryCenterUrl(), dubboCfg.getInterfaceClassName(),
dubboCfg.getMethodName(), dubboCfg.isAsync(), dubboCfg.getVersion(), paramTypes, paramValues);
dubboCfg.getMethodName(), dubboCfg.isAsync(), dubboCfg.getVersion(), paramTypes, paramValues, dubboCfg.getGroup());
try {
Object objResult = future.get();
return JSON.toJSONString(objResult, CLASS_NAME_PRE_FILTER);
@@ -39,6 +39,9 @@ public class CallDubboServiceRequest {
@ApiParam(value = "The version of API")
private String version;

@ApiParam(value = "The group of API")
private String group;

public String getVersion() {
return version;
}
@@ -78,4 +81,12 @@ public boolean isAsync() {
public void setAsync(boolean async) {
this.async = async;
}

public String getGroup() {
return group;
}

public void setGroup(String group) {
this.group = group;
}
}
@@ -111,14 +111,16 @@ private static void removeRegistryConfig(String address) {
* @param: address address Address of Registration Center
* @param: interfaceName Interface full package path
*/
private static ReferenceConfig<GenericService> getReferenceConfig(String address, String interfaceName, String version) {
final String key = buildCacheKey(address, interfaceName, version);
private static ReferenceConfig<GenericService> getReferenceConfig(String address, String interfaceName,
String version, String group) {
final String key = buildCacheKey(address, interfaceName, version, group);
ReferenceConfig<GenericService> referenceConfig = referenceCache.get(key);
if (null == referenceConfig) {
referenceConfig = new ReferenceConfig<>();
referenceConfig.setRetries(retries);
referenceConfig.setTimeout(timeout);
referenceConfig.setVersion(version);
referenceConfig.setGroup(group);
referenceConfig.setApplication(application);
if (address.startsWith("dubbo")) {
referenceConfig.setUrl(address);
@@ -139,13 +141,13 @@ private static ReferenceConfig<GenericService> getReferenceConfig(String address
* @param interfaceName
* @return void
*/
private static void removeReferenceConfig(String address, String interfaceName, String version) {
private static void removeReferenceConfig(String address, String interfaceName, String version, String group) {
removeRegistryConfig(address);
referenceCache.remove(buildCacheKey(address, interfaceName, version));
referenceCache.remove(buildCacheKey(address, interfaceName, version, group));
}

private static String buildCacheKey(String address, String interfaceName, String version) {
return address + "/" + interfaceName + "/" + version;
private static String buildCacheKey(String address, String interfaceName, String version, String group) {
return address + "/" + interfaceName + "/" + version + "/" + group;
}

/**
@@ -162,9 +164,9 @@ private static String buildCacheKey(String address, String interfaceName, String
*/
public static CompletableFuture<Object> invoke(String address, String interfaceName,
String methodName, boolean async, String version, String[] paramTypes,
Object[] paramValues) {
Object[] paramValues, String group) {
CompletableFuture future = null;
ReferenceConfig<GenericService> reference = getReferenceConfig(address, interfaceName, version);
ReferenceConfig<GenericService> reference = getReferenceConfig(address, interfaceName, version, group);
if (null != reference) {
GenericService genericService = reference.get();
if (null != genericService) {
@@ -176,7 +178,7 @@ public static CompletableFuture<Object> invoke(String address, String interfaceN
}
future.exceptionally(ex -> {
if (StringUtils.contains(ex.toString(), "Failed to invoke remote method")) {
removeReferenceConfig(address, interfaceName, version);
removeReferenceConfig(address, interfaceName, version, group);
}
return ex;
});
@@ -197,8 +199,8 @@ public static CompletableFuture<Object> invoke(String address, String interfaceN
*/
public static Object invokeSync(String address, String interfaceName,
String methodName, String version, String[] paramTypes,
Object[] paramValues) {
ReferenceConfig<GenericService> reference = getReferenceConfig(address, interfaceName, version);
Object[] paramValues, String group) {
ReferenceConfig<GenericService> reference = getReferenceConfig(address, interfaceName, version, group);
if (null != reference) {
GenericService genericService = reference.get();
try {
@@ -207,7 +209,7 @@ public static Object invokeSync(String address, String interfaceName,
}
} catch (Exception ex) {
if (StringUtils.contains(ex.toString(), "Failed to invoke remote method")) {
removeReferenceConfig(address, interfaceName, version);
removeReferenceConfig(address, interfaceName, version, group);
} else {
throw ex;
}
@@ -157,7 +157,8 @@ export default {
apiRespDec: menuItem.apiRespDec,
apiDocName: menuItem.apiDocName,
description: menuItem.description,
apiVersion: menuItem.apiVersion
apiVersion: menuItem.apiVersion,
apiGroup: menuItem.apiGroup
}
}
menu2.apis.push(menuItem2)
@@ -82,6 +82,19 @@
</div>
</div>
</v-timeline-item>
<v-timeline-item
color="cyan"
small
>
<div>
<div class="font-weight-normal">
<strong>{{ $t('apiDocsRes.apiForm.apiGroupShowLabel') }}</strong>
</div>
<div>
{{ this.apiInfoData.apiGroup || $t('apiDocsRes.apiForm.none') }}
</div>
</div>
</v-timeline-item>
<v-timeline-item
color="cyan"
small
@@ -356,7 +369,6 @@ export default {
if (!this.$refs.form.validate()) {
return false
}
console.log(this.formValues)
var tempMap = new Map()
this.formValues.forEach((value, key) => {
var elementIdSplited = key.split('@@')
@@ -408,7 +420,8 @@ export default {
interfaceClassName: this.formItemInterfaceClassName,
methodName: this.formItemMethodName,
registryCenterUrl: this.formItemRegistryCenterUrl,
version: this.apiInfoData.apiVersion || ''
version: this.apiInfoData.apiVersion || '',
group: this.apiInfoData.apiGroup || ''
},
headers: {
'Content-Type': 'application/json; charset=UTF-8'
@@ -177,6 +177,7 @@ export default {
apiPathShowLabel: 'Api Path',
apiMethodParamInfoLabel: 'Api method parameters',
apiVersionShowLabel: 'Api Version',
apiGroupShowLabel: 'Api Group',
apiDescriptionShowLabel: 'Api Description',
isAsyncFormLabel: 'Whether to call asynchronously (this parameter cannot be modified, according to whether to display asynchronously defined by the interface)',
apiModuleFormLabel: 'Api module (this parameter cannot be modified)',
@@ -177,6 +177,7 @@ export default {
apiPathShowLabel: '接口位置',
apiMethodParamInfoLabel: '接口参数',
apiVersionShowLabel: '接口版本',
apiGroupShowLabel: '接口分组',
apiDescriptionShowLabel: '接口说明',
isAsyncFormLabel: '是否异步调用(此参数不可修改,根据接口定义的是否异步显示)',
apiModuleFormLabel: '接口模块(此参数不可修改)',

0 comments on commit 404b420

Please sign in to comment.