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

fix: Permit top-level resources to have batch methods. #619

Merged
merged 2 commits into from
Sep 15, 2020

Conversation

lukesneeringer
Copy link
Contributor

@lukesneeringer lukesneeringer commented Sep 2, 2020

Also, I rewrote the tests for these rules from scratch, as they
were in a weird state.

Fixes #615.

Also, I rewrote the tests for these rules from scratch, as they
were in a weird state.

Fixes #599.
@lukesneeringer lukesneeringer requested a review from a team September 2, 2020 23:15
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Sep 2, 2020
Comment on lines +39 to +50
plural := strings.TrimPrefix(strings.TrimSuffix(m.GetName(), "Request"), "BatchGet")
if resp := m.GetFile().FindMessage(fmt.Sprintf("BatchGet%sResponse", plural)); resp != nil {
if paged := resp.FindFieldByName(strcase.SnakeCase(plural)); paged != nil {
if resource := utils.GetResource(paged.GetMessageType()); resource != nil {
for _, pattern := range resource.GetPattern() {
if strings.Count(pattern, "{") == 1 {
return false
}
}
}
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can this logic (which is used for BatchGet, BatchCreate, and BatchUpdate) be pulled out into a function that takes the "batching method type" as param i.e. "BatchGet", as well as the necessary proto input i.e. m *desc.MessageDescriptor? This code is non-trivial and used in three places, feels ripe for a func. WDYT? If there is a nuance in the code for each that prevents this that I missed, lmk.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It can be, although the code is slightly different each time, and I am not sure there is a good place to put it. I do not know that it is common enough to justify going in utils. This is right in the sour spot where the function can not be in the AIP modules themselves, but are not generic enough for me to be convinced that they belong in utils.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok, I understand. Bummer!

@lukesneeringer lukesneeringer merged commit 8227cc2 into master Sep 15, 2020
@lukesneeringer lukesneeringer deleted the issue-599 branch September 15, 2020 23:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update lints for parent-less batch methods
2 participants