-
Notifications
You must be signed in to change notification settings - Fork 144
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
Conversation
Also, I rewrote the tests for these rules from scratch, as they were in a weird state. Fixes #599.
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 | ||
} | ||
} | ||
} | ||
} | ||
} |
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 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.
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 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.
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.
Ok, I understand. Bummer!
Also, I rewrote the tests for these rules from scratch, as they
were in a weird state.
Fixes #615.