diff --git a/runtime/config-deployer-service/ballerina/APIClient.bal b/runtime/config-deployer-service/ballerina/APIClient.bal index 9151f2119c..549ae64233 100644 --- a/runtime/config-deployer-service/ballerina/APIClient.bal +++ b/runtime/config-deployer-service/ballerina/APIClient.bal @@ -46,7 +46,7 @@ public class APIClient { encodedString = encodedString.substring(0, encodedString.length() - 1); } APKConf apkConf = { - name: api.getName(), + name: api.getType() == API_TYPE_GRPC ? self.getUniqueNameForGrpcApi(api.getName()) : api.getName(), basePath: api.getBasePath().length() > 0 ? api.getBasePath() : encodedString, version: api.getVersion(), 'type: api.getType() == "" ? API_TYPE_REST : api.getType().toUpperAscii() @@ -1679,6 +1679,11 @@ public class APIClient { return hashedValue.toBase16(); } + public isolated function getUniqueNameForGrpcApi(string concatanatedServices) returns string { + byte[] hashedValue = crypto:hashSha1(concatanatedServices.toBytes()); + return hashedValue.toBase16(); + } + public isolated function retrieveHttpRouteRefName(APKConf apkConf, string 'type, commons:Organization organization) returns string { return uuid:createType1AsString(); } diff --git a/runtime/config-deployer-service/java/src/main/java/org/wso2/apk/config/RuntimeAPICommonUtil.java b/runtime/config-deployer-service/java/src/main/java/org/wso2/apk/config/RuntimeAPICommonUtil.java index ebca7e8e4b..0cb0b8ee35 100644 --- a/runtime/config-deployer-service/java/src/main/java/org/wso2/apk/config/RuntimeAPICommonUtil.java +++ b/runtime/config-deployer-service/java/src/main/java/org/wso2/apk/config/RuntimeAPICommonUtil.java @@ -148,7 +148,10 @@ private static API getGRPCAPIFromProtoDefinition(String definition) { API api = new API(); api.setBasePath("/"+protoParser.protoFile.basePath); api.setVersion(protoParser.protoFile.version); + StringBuilder apiName = new StringBuilder(); + for (ProtoParser.Service service : protoParser.getServices()) { + apiName.append(service.name); for (String method : service.methods) { URITemplate uriTemplate = new URITemplate(); uriTemplate.setUriTemplate(protoParser.protoFile.packageName + "." + service.name); @@ -156,6 +159,7 @@ private static API getGRPCAPIFromProtoDefinition(String definition) { uriTemplates.add(uriTemplate); } } + api.setName(apiName.toString()); api.setUriTemplates(uriTemplates.toArray(new URITemplate[uriTemplates.size()])); return api;