-
Notifications
You must be signed in to change notification settings - Fork 53
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
Draft: Selective api poc #3129
Conversation
gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/ComposerTest.java
Outdated
Show resolved
Hide resolved
gapic-generator-java/src/main/java/com/google/api/generator/gapic/protoparser/Parser.java
Outdated
Show resolved
Hide resolved
gapic-generator-java/src/main/java/com/google/api/generator/gapic/protoparser/Parser.java
Outdated
Show resolved
Hide resolved
…atches proto package in parser. other cleanups and minor fixes.
gapic-generator-java/src/main/java/com/google/api/generator/gapic/protoparser/Parser.java
Outdated
Show resolved
Hide resolved
return fileDescriptor.getServices().stream() | ||
.filter( | ||
serviceDescriptor -> { | ||
List<MethodDescriptor> methodsList = serviceDescriptor.getMethods(); | ||
if (methodsList.isEmpty()) { | ||
List<MethodDescriptor> methodListSelected = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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.
gapic-generator-java/src/main/java/com/google/api/generator/gapic/protoparser/Parser.java
Show resolved
Hide resolved
@@ -425,6 +434,47 @@ public static List<Service> parseService( | |||
Transport.GRPC); | |||
} | |||
|
|||
private static Optional<List<String>> getInclusionMethodListFromServiceYaml( | |||
Optional<com.google.api.Service> serviceYamlProtoOpt, String protoPackage) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is usually preferred to not passing around Optional
if we can check it before calling the method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to follow-up on this from our discussion earlier and get @blakeli0 your opinion on this. (FYI, I've combined this method into shouldIncludeMethodInGeneration()
)
For now, I am slightly inclined to keep this Optional<com.google.api.Service> serviceYamlProtoOpt
as input for 2 reasons:
- The pattern of passing in this
Optional
is repeated in thisParser
class, a larger scale refactor is needed to remove these. - Because this service yaml is an optional config file that only some libraries have, it sort of make sense to have this Optional representation. And I find the current way can better encapsulate this piece of logic:
shouldIncludeMethodInGeneration()
has all the information to decide if this method should or not be included. I could checkserviceYamlProtoOpt
before calling the method, but the 2 occurrences would repeat the logic in a reverse way, and it might be less readable for debugging in the future.
Does this makes sense to you? WDYT?
gapic-generator-java/src/main/java/com/google/api/generator/gapic/protoparser/Parser.java
Outdated
Show resolved
Hide resolved
@@ -705,6 +710,99 @@ void parseServiceWithNoMethodsTest() { | |||
assertEquals("EchoWithMethods", services.get(0).overriddenName()); | |||
} | |||
|
|||
@Test | |||
void selectiveGenerationTest_shouldExcludeUnusedResourceNames() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test verifies that unused resource names (associated with methods not in inclusion list) will not be populated to GapicContext.
gapic-generator-java/src/main/java/com/google/api/generator/gapic/protoparser/Parser.java
Outdated
Show resolved
Hide resolved
gapic-generator-java/src/main/java/com/google/api/generator/gapic/protoparser/Parser.java
Outdated
Show resolved
Hide resolved
gapic-generator-java/src/test/proto/selective_api_generation.proto
Outdated
Show resolved
Hide resolved
@@ -425,6 +434,39 @@ public static List<Service> parseService( | |||
Transport.GRPC); | |||
} | |||
|
|||
private static boolean shouldIncludeMethodInGeneration( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make this a default scope method so we can test it directly? This would enabled us testing more scenarios like the non matching packages, it would also simplify the golden tests.
gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/ComposerTest.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably don't need this yaml and selective_api_generation_no_publishing_v1beta1.yaml
as the scenarios should be tested in ParserTest
directly.
#3323) following changes in client.proto that propagated to `ClientProto.java` ([pr](https://github.com/googleapis/sdk-platform-java/pull/3309/files#diff-44c330ef5cfa380744be6c58a14aa543edceb6043d5b17da7b32bb728ef5d85f)), apply changes from poc pr (#3129). For context: [go/selective-api-gen-java-one-pager](http://goto.google.com/selective-api-gen-java-one-pager), b/356380016
implemented in #3323. closing |
DO NOT MERGE.
This is a draft pr as prototype to changes for selective api generation feature.
The changes in this pr include api-common-java changes copied over manually for testing purposes.