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

feat(internal/gengapic): move operations & iterators to aux.go #1428

Merged
merged 12 commits into from
Nov 1, 2023

Conversation

noahdietz
Copy link
Collaborator

@noahdietz noahdietz commented Oct 12, 2023

Generate all Iterator and Operation wrapper types into a single file - aux.go. The auxiliary types can be shared across the entire client package when certain criteria are met.

For Iterator wrappers, it is simply a matching repeated type, common when multiple RPCs paginate over the same message.

For Operation wrappers, the RPC name must be the same, as well as the response and metadata types declared inside of the operation returned. This is less common, but can happen if two proto services in the same package share an RPC name and types. This introduces a new generator error mode when the aforementioned conditions are not met. This is good because previously the generator would succeed, but the generated code would not compile (colliding type names) and not provide a clear reason to debug.

The operation "builder" methods that are generated onto a service client type surface remain in the same place - in the service client file. These are specific to each client, even if they are mostly the same in surface between clients, so we keep them generated in the client file.

An example of the changes can be found in #8703. Building all Go gapic targets under google/cloud worked.

Note: Thus undoes #1398, which will result in a breaking change in the beta client it address a collision in. This is OK because the client is marked as beta/unstable, and it is more true to the surface.

Fixes #156.
Updates #1399.

@noahdietz noahdietz marked this pull request as ready for review October 12, 2023 22:50
@noahdietz noahdietz requested review from a team as code owners October 12, 2023 22:50
Copy link
Member

@codyoss codyoss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just a couple nits

// auxTypes gathers details of types we need to generate along with the client
type auxTypes struct {
// Map of RPC descriptor to assigned operationWrapper.
methodToWrapper map[*descriptorpb.MethodDescriptorProto]operationWrapper
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Someday we should create a lightweight generic sorted map impl. We always be sorting in generator because of key randomness today.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oo that would be great, and fun :)

If you want to, we could start one in this repo's internal package, then potentially give it its own repo? Would be good practice with generics...

internal/gengapic/auxiliary.go Show resolved Hide resolved
internal/gengapic/auxiliary_test.go Outdated Show resolved Hide resolved
Copy link
Member

@quartzmo quartzmo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comments in this PR are great. They made it really easy to understand.

Also: Bravo on closing an issue from 2019! 🎉

I had one question about testing, super minor.

@noahdietz
Copy link
Collaborator Author

Ready to release this now. merging.

@noahdietz noahdietz merged commit e8ad272 into googleapis:main Nov 1, 2023
7 checks passed
@noahdietz noahdietz deleted the aux-file branch November 1, 2023 19:52
gcf-merge-on-green bot pushed a commit that referenced this pull request Nov 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

gapic: generate auxiliary types in a separate file
3 participants