Skip to content

Commit

Permalink
fix: cleanup and simplify.
Browse files Browse the repository at this point in the history
  • Loading branch information
zhumin8 committed Jul 16, 2024
1 parent 7c6239f commit c1b2aab
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -436,24 +436,16 @@ public static List<Service> parseService(

return fileDescriptor.getServices().stream()
.filter(
s -> {
String pakkage = TypeParser.getPackage(fileDescriptor);
List<Method> methods = parseMethods(
s,
pakkage,
messageTypes,
resourceNames,
serviceConfigOpt,
serviceYamlProtoOpt,
outputArgResourceNames,
transport);
if (methods.isEmpty()) {
LOGGER.warning(String.format("No rpc methods specified in %s, generation will be skipped.", s.getName()));
// Service.builder()
serviceDescriptor -> {
List<MethodDescriptor> methodsList = serviceDescriptor.getMethods();
if (methodsList.isEmpty()) {
LOGGER.warning(
String.format(
"No rpc methods specified in %s, generation will be skipped.",
serviceDescriptor.getName()));
}
return !methods.isEmpty();
}
)
return !methodsList.isEmpty();
})
.map(
s -> {
// Workaround for a missing default_host and oauth_scopes annotation from a service
Expand Down Expand Up @@ -514,19 +506,6 @@ public static List<Service> parseService(
overriddenServiceName =
languageSettings.getJavaServiceName(fileDescriptor.getPackage(), s.getName());
}
List<Method> methods = parseMethods(
s,
pakkage,
messageTypes,
resourceNames,
serviceConfigOpt,
serviceYamlProtoOpt,
outputArgResourceNames,
transport);
if (methods.isEmpty()) {
LOGGER.warning("No methods in this service.");
// Service.builder()
}
return serviceBuilder
.setName(serviceName)
.setOverriddenName(overriddenServiceName)
Expand All @@ -537,7 +516,15 @@ public static List<Service> parseService(
.setProtoPakkage(fileDescriptor.getPackage())
.setIsDeprecated(isDeprecated)
.setMethods(
methods)
parseMethods(
s,
pakkage,
messageTypes,
resourceNames,
serviceConfigOpt,
serviceYamlProtoOpt,
outputArgResourceNames,
transport))
.build();
})
.collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -704,19 +703,15 @@ void testServiceWithoutApiVersionParsed() {
assertNull(parsedBookshopService.apiVersion());
}


@Test
void parseServiceWithNoMethodsTest() {
FileDescriptor fileDescriptor = com.google.api.service.without.methods.test.ServiceWithNoMethodsOuterClass.getDescriptor();
FileDescriptor fileDescriptor =
com.google.api.service.without.methods.test.ServiceWithNoMethodsOuterClass.getDescriptor();
Map<String, Message> messageTypes = Parser.parseMessages(fileDescriptor);
Map<String, ResourceName> resourceNames = Parser.parseResourceNames(fileDescriptor);
List<com.google.api.generator.gapic.model.Service> services =
Parser.parseService(
fileDescriptor,
messageTypes,
resourceNames,
Optional.empty(),
new HashSet<>());
fileDescriptor, messageTypes, resourceNames, Optional.empty(), new HashSet<>());
assertEquals(1, services.size());
assertEquals("EchoWithMethods", services.get(0).overriddenName());
}
Expand Down

0 comments on commit c1b2aab

Please sign in to comment.