Skip to content

Commit

Permalink
Merge pull request #20 from KeRan213539/fix-apidocs-#19
Browse files Browse the repository at this point in the history
Fix #19
  • Loading branch information
KeRan213539 authored Mar 19, 2021
2 parents e8b4c4a + 71555a7 commit b582326
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,20 @@ public void onApplicationEvent(ApplicationReadyEvent applicationReadyEvent) {
}
boolean async;
String apiVersion;
String apiGroup;
if (apiModuleClass.isAnnotationPresent(Service.class)) {
Service dubboService = apiModuleClass.getAnnotation(Service.class);
async = dubboService.async();
apiVersion = dubboService.version();
apiGroup = dubboService.group();
} else {
DubboService dubboService = apiModuleClass.getAnnotation(DubboService.class);
async = dubboService.async();
apiVersion = dubboService.version();
apiGroup = dubboService.group();
}
apiVersion = applicationContext.getEnvironment().resolvePlaceholders(apiVersion);
apiGroup = applicationContext.getEnvironment().resolvePlaceholders(apiGroup);
ModuleCacheItem moduleCacheItem = new ModuleCacheItem();
DubboApiDocsCache.addApiModule(moduleAnn.apiInterface().getCanonicalName(), moduleCacheItem);
//module name
Expand All @@ -138,22 +142,24 @@ public void onApplicationEvent(ApplicationReadyEvent applicationReadyEvent) {
moduleCacheItem.setModuleClassName(moduleAnn.apiInterface().getCanonicalName());
//module version
moduleCacheItem.setModuleVersion(apiVersion);
//module group
moduleCacheItem.setModuleGroup(apiGroup);

Method[] apiModuleMethods = apiModuleClass.getMethods();
// API basic information list in module cache
List<ApiCacheItem> moduleApiList = new ArrayList<>(apiModuleMethods.length);
moduleCacheItem.setModuleApiList(moduleApiList);
for (Method method : apiModuleMethods) {
if (method.isAnnotationPresent(ApiDoc.class)) {
processApiDocAnnotation(method, moduleApiList, moduleAnn, async, moduleCacheItem, apiVersion);
processApiDocAnnotation(method, moduleApiList, moduleAnn, async, moduleCacheItem, apiVersion, apiGroup);
}
}
});
LOG.info("================= Dubbo API Docs-- doc annotations scanning and processing completed ================");
}

private void processApiDocAnnotation(Method method, List<ApiCacheItem> moduleApiList, ApiModule moduleAnn,
boolean async, ModuleCacheItem moduleCacheItem, String apiVersion) {
boolean async, ModuleCacheItem moduleCacheItem, String apiVersion, String apiGroup) {

ApiDoc dubboApi = method.getAnnotation(ApiDoc.class);

Expand All @@ -168,6 +174,8 @@ private void processApiDocAnnotation(Method method, List<ApiCacheItem> moduleApi
apiListItem.setDescription(dubboApi.description());
//API version
apiListItem.setApiVersion(apiVersion);
//API group
apiListItem.setApiGroup(apiGroup);
//Description of API return data
apiListItem.setApiRespDec(dubboApi.responseClassDescription());

Expand All @@ -185,6 +193,7 @@ private void processApiDocAnnotation(Method method, List<ApiCacheItem> moduleApi
apiParamsAndResp.setApiName(method.getName());
apiParamsAndResp.setApiDocName(dubboApi.value());
apiParamsAndResp.setApiVersion(apiVersion);
apiParamsAndResp.setApiGroup(apiGroup);
apiParamsAndResp.setApiRespDec(dubboApi.responseClassDescription());
apiParamsAndResp.setDescription(dubboApi.description());
apiParamsAndResp.setApiModelClass(moduleCacheItem.getModuleClassName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public class ApiCacheItem {

private String apiVersion;

private String apiGroup;

private String description;

private String apiRespDec;
Expand Down Expand Up @@ -122,4 +124,12 @@ public String getMethodParamInfo() {
public void setMethodParamInfo(String methodParamInfo) {
this.methodParamInfo = methodParamInfo;
}

public String getApiGroup() {
return apiGroup;
}

public void setApiGroup(String apiGroup) {
this.apiGroup = apiGroup;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public class ModuleCacheItem {

private String moduleVersion;

private String moduleGroup;

private List<ApiCacheItem> moduleApiList;

public String getModuleDocName() {
Expand Down Expand Up @@ -62,4 +64,12 @@ public List<ApiCacheItem> getModuleApiList() {
public void setModuleApiList(List<ApiCacheItem> moduleApiList) {
this.moduleApiList = moduleApiList;
}

public String getModuleGroup() {
return moduleGroup;
}

public void setModuleGroup(String moduleGroup) {
this.moduleGroup = moduleGroup;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
*
* @date 2020/12/23 17:21
*/
@DubboService(version = "${demo.apiversion.quickstart}")
@DubboService(version = "${demo.apiversion.quickstart}", group = "demoGroup")
@ApiModule(value = "quick start demo", apiInterface = IQuickStartDemo.class)
public class QuickStartDemoImpl implements IQuickStartDemo {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ spring:
dubbo:
registry:
address: zookeeper://127.0.0.1:2181
# group: DEFAULT_GROUP
provider:
timeout: 2000
filter: metrics
Expand All @@ -33,8 +34,10 @@ dubbo:
name: dubbo-api-docs-example-provider
metadata-report:
address: zookeeper://127.0.0.1:2181
# group: DEFAULT_GROUP
config-center:
address: zookeeper://127.0.0.1:2181
# group: DEFAULT_GROUP
metrics:
port: ${dubbo.protocol.port}
protocol: dubbo
Expand Down

0 comments on commit b582326

Please sign in to comment.