Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not get dubbo ProviderConfig config when ServiceConfig not set group #24

Merged
merged 2 commits into from
Apr 22, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.apache.dubbo.config.ProtocolConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.ServiceConfig;
import org.apache.dubbo.config.ProviderConfig;
import org.apache.dubbo.config.annotation.DubboService;
import org.apache.dubbo.config.annotation.Service;
import org.apache.dubbo.apidocs.annotations.ApiModule;
Expand Down Expand Up @@ -95,6 +96,9 @@ public class DubboApiDocsAnnotationScanner implements ApplicationListener<Applic
@Autowired
private ProtocolConfig protocol;

@Autowired(required = false)
private ProviderConfig providerConfig;

@Override
public void onApplicationEvent(ApplicationReadyEvent applicationReadyEvent) {
// Register dubbo doc provider
Expand Down Expand Up @@ -132,8 +136,15 @@ public void onApplicationEvent(ApplicationReadyEvent applicationReadyEvent) {
apiVersion = dubboService.version();
apiGroup = dubboService.group();
}


// API version&group safe guard!
apiVersion = getApiVersionIfAbsent(apiVersion);
apiGroup = getApiGroupIfAbsent(apiGroup);

apiVersion = applicationContext.getEnvironment().resolvePlaceholders(apiVersion);
apiGroup = applicationContext.getEnvironment().resolvePlaceholders(apiGroup);

ModuleCacheItem moduleCacheItem = new ModuleCacheItem();
DubboApiDocsCache.addApiModule(moduleAnn.apiInterface().getCanonicalName(), moduleCacheItem);
//module name
Expand All @@ -158,6 +169,42 @@ public void onApplicationEvent(ApplicationReadyEvent applicationReadyEvent) {
LOG.info("================= Dubbo API Docs-- doc annotations scanning and processing completed ================");
}

/**
* get provider config(default) api version if param apiVersion is blank
* @param apiVersion api version
* @return api version is apiVersion when it isn`t blank, or return provider config(default) version
*/
private String getApiVersionIfAbsent(String apiVersion) {
if (StringUtils.isBlank(apiVersion)) {
if (providerConfig != null) {
apiVersion = providerConfig.getVersion();
}

if (StringUtils.isBlank(apiVersion)) {
apiVersion = "";
}
}
return apiVersion;
}

/**
* get provider config(default) api group if param apiGroup is blank
* @param apiGroup api version
* @return api group is apiGroup when it isn`t blank, or return provider config(default) group
*/
private String getApiGroupIfAbsent(String apiGroup) {
if (StringUtils.isBlank(apiGroup)) {
if (providerConfig != null) {
apiGroup = providerConfig.getGroup();
}

if (StringUtils.isBlank(apiGroup)) {
apiGroup = "";
}
}
return apiGroup;
}

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

Expand Down Expand Up @@ -272,7 +319,7 @@ private List<ParamBean> processField(Class<?> argClass, Type parameterType, Para
genericTypeAndNamesMap = Collections.EMPTY_MAP;
}

List<ParamBean> apiParamsList = new ArrayList(16);
List<ParamBean> apiParamsList = new ArrayList<>(16);
// get all fields
List<Field> allFields = ClassTypeUtil.getAllFields(null, argClass);
if (allFields.size() > 0) {
Expand Down