-
Notifications
You must be signed in to change notification settings - Fork 75
Draft: Selective api poc #3129
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
Draft: Selective api poc #3129
Changes from 5 commits
c20c974
cbcd5bc
cf87622
e877473
a89bb9f
7dcdf56
f47c93a
2496716
c29a319
7d8480a
395fa47
950069e
fa63021
e013458
5a89def
a99af2c
e8f5388
2012a82
7978c15
c2967e9
819bdd5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ | |
|
|
||
| package com.google.api.generator.gapic.protoparser; | ||
|
|
||
| import com.google.api.ClientLibrarySettings; | ||
| import com.google.api.ClientProto; | ||
| import com.google.api.DocumentationRule; | ||
| import com.google.api.FieldBehavior; | ||
|
|
@@ -70,6 +71,7 @@ | |
| import com.google.protobuf.Descriptors.FileDescriptor; | ||
| import com.google.protobuf.Descriptors.MethodDescriptor; | ||
| import com.google.protobuf.Descriptors.ServiceDescriptor; | ||
| import com.google.protobuf.ProtocolStringList; | ||
| import com.google.protobuf.compiler.PluginProtos.CodeGeneratorRequest; | ||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
|
|
@@ -425,6 +427,66 @@ public static List<Service> parseService( | |
| Transport.GRPC); | ||
| } | ||
|
|
||
| private static String getPakkageName(FileDescriptor fileDescriptor, ServiceDescriptor s, | ||
| Optional<GapicServiceConfig> serviceConfigOpt) { | ||
| String pakkage = TypeParser.getPackage(fileDescriptor); | ||
| // Override Java package with that specified in gapic.yaml. | ||
| // this override is deprecated and legacy support only | ||
| // see go/client-user-guide#configure-long-running-operation-polling-timeouts-optional | ||
| if (serviceConfigOpt.isPresent() | ||
| && serviceConfigOpt.get().getLanguageSettingsOpt().isPresent()) { | ||
| GapicLanguageSettings languageSettings = | ||
| serviceConfigOpt.get().getLanguageSettingsOpt().get(); | ||
| pakkage = languageSettings.pakkage(); | ||
| } | ||
| return pakkage; | ||
| } | ||
|
|
||
| private static String getOverriddenServiceName(FileDescriptor fileDescriptor, ServiceDescriptor s, | ||
| Optional<GapicServiceConfig> serviceConfigOpt) { | ||
| String serviceName = s.getName(); | ||
| String overriddenServiceName = serviceName; | ||
| String pakkage = TypeParser.getPackage(fileDescriptor); | ||
| // Override Java package with that specified in gapic.yaml. | ||
| // this override is deprecated and legacy support only | ||
| // see go/client-user-guide#configure-long-running-operation-polling-timeouts-optional | ||
| if (serviceConfigOpt.isPresent() | ||
| && serviceConfigOpt.get().getLanguageSettingsOpt().isPresent()) { | ||
| GapicLanguageSettings languageSettings = | ||
| serviceConfigOpt.get().getLanguageSettingsOpt().get(); | ||
| overriddenServiceName = | ||
| languageSettings.getJavaServiceName(fileDescriptor.getPackage(), s.getName()); | ||
| } | ||
| return overriddenServiceName; | ||
| } | ||
| private static boolean shouldIncludeMethod( | ||
| MethodDescriptor method, Optional<com.google.api.Service> serviceYamlProtoOpt) { | ||
| method.getInputType().getFullName(); | ||
| // default to include all when no service yaml or no library setting section. | ||
| if (!serviceYamlProtoOpt.isPresent() | ||
| || serviceYamlProtoOpt.get().getPublishing().getLibrarySettingsCount() == 0) { | ||
| return true; | ||
| } | ||
| List<ClientLibrarySettings> librarySettingsList = | ||
| serviceYamlProtoOpt.get().getPublishing().getLibrarySettingsList(); | ||
| // TODO: verify if get(0) is reliable. may need to use package version. | ||
|
zhumin8 marked this conversation as resolved.
Outdated
|
||
| // should be okay since it's cut per version. no harm in verifying. | ||
| // library settings version (required): http://google3/google/api/client.proto;l=29-32;rcl=651426419 | ||
| ProtocolStringList includeMethodsList = | ||
| librarySettingsList | ||
| .get(0) | ||
| .getJavaSettings() | ||
| .getCommon() | ||
| .getSelectiveGapicGeneration() | ||
| .getMethodsList(); | ||
| // default to include all when nothing specified. | ||
| if (includeMethodsList.isEmpty()) { | ||
| return true; | ||
| } | ||
| // may need to preprocess method name with override package name | ||
| return includeMethodsList.contains(method.getFullName()); | ||
| } | ||
|
|
||
| public static List<Service> parseService( | ||
| FileDescriptor fileDescriptor, | ||
| Map<String, Message> messageTypes, | ||
|
|
@@ -438,13 +500,20 @@ public static List<Service> parseService( | |
| .filter( | ||
| serviceDescriptor -> { | ||
| List<MethodDescriptor> methodsList = serviceDescriptor.getMethods(); | ||
| if (methodsList.isEmpty()) { | ||
| List<MethodDescriptor> methodListSelected = | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This scenario is in case that all methods from a service are excluded?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. And this is likely now e.g. in vertexai's requirement it only exposes methods from 2 services. |
||
| methodsList.stream() | ||
| .filter( | ||
| method -> { | ||
| return shouldIncludeMethod(method, serviceYamlProtoOpt); | ||
| }) | ||
| .collect(Collectors.toList()); | ||
| if (methodListSelected.isEmpty()) { | ||
| LOGGER.warning( | ||
| String.format( | ||
| "Service %s has no RPC methods and will not be generated", | ||
| serviceDescriptor.getName())); | ||
| } | ||
| return !methodsList.isEmpty(); | ||
| return !methodListSelected.isEmpty(); | ||
| }) | ||
| .map( | ||
| s -> { | ||
|
|
@@ -498,6 +567,8 @@ public static List<Service> parseService( | |
| String pakkage = TypeParser.getPackage(fileDescriptor); | ||
| String originalJavaPackage = pakkage; | ||
| // Override Java package with that specified in gapic.yaml. | ||
| // this override is deprecated and legacy support only | ||
| // see go/client-user-guide#configure-long-running-operation-polling-timeouts-optional | ||
| if (serviceConfigOpt.isPresent() | ||
| && serviceConfigOpt.get().getLanguageSettingsOpt().isPresent()) { | ||
| GapicLanguageSettings languageSettings = | ||
|
|
@@ -723,6 +794,9 @@ static List<Method> parseMethods( | |
| parseAutoPopulatedMethodsAndFields(serviceYamlProtoOpt); | ||
|
|
||
| for (MethodDescriptor protoMethod : serviceDescriptor.getMethods()) { | ||
| if (!shouldIncludeMethod(protoMethod, serviceYamlProtoOpt)) { | ||
| continue; | ||
| } | ||
| // Parse the method. | ||
| TypeNode inputType = TypeParser.parseType(protoMethod.getInputType()); | ||
| Method.Builder methodBuilder = Method.builder(); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.