Skip to content

Commit

Permalink
fix(AIP-121): ignore standard method lookalikes (googleapis#1250)
Browse files Browse the repository at this point in the history
  • Loading branch information
noahdietz committed Sep 12, 2023
1 parent 2c2abff commit 34aa3c8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
6 changes: 3 additions & 3 deletions rules/aip0121/resource_must_support_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ var resourceMustSupportGet = &lint.ServiceRule{
// Iterate all RPCs and try to find resources. Mark the
// resources which have a Get method, and which ones do not.
for _, m := range s.GetMethods() {
if utils.IsGetMethod(m) {
if utils.IsGetMethod(m) && utils.IsResource(utils.GetResponseType(m)) {
t := utils.GetResource(m.GetOutputType()).GetType()
resourcesWithGet.Add(t)
} else if utils.IsCreateMethod(m) || utils.IsUpdateMethod(m) {
if msg := utils.GetResponseType(m); msg != nil {
if msg := utils.GetResponseType(m); msg != nil && utils.IsResource(msg) {
t := utils.GetResource(msg).GetType()
resourcesWithOtherMethods.Add(t)
}
} else if utils.IsListMethod(m) {
if msg := utils.GetListResourceMessage(m); msg != nil {
if msg := utils.GetListResourceMessage(m); msg != nil && utils.IsResource(msg) {
t := utils.GetResource(msg).GetType()
resourcesWithOtherMethods.Add(t)
}
Expand Down
15 changes: 15 additions & 0 deletions rules/aip0121/resource_must_support_get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ func TestResourceMustSupportGet(t *testing.T) {
rpc GetBook(GetBookRequest) returns (Book) {};
rpc UpdateBook(UpdateBookRequest) returns (Book) {};
`, nil},
{"ValidIgnoreNonResourceUpdate", `
rpc UpdateBook(UpdateBookRequest) returns (Other) {};
`, nil},
{"ValidIgnoreNonResourceCreate", `
rpc CreateBook(CreateBookRequest) returns (Other) {};
`, nil},
{"ValidIgnoreNonResourceList", `
rpc ListBooks(ListBooksRequest) returns (RepeatedOther) {};
`, nil},
{"InvalidCreateOnly", `
rpc CreateBook(CreateBookRequest) returns (Book) {};
`, []lint.Problem{
Expand Down Expand Up @@ -124,6 +133,12 @@ func TestResourceMustSupportGet(t *testing.T) {
repeated Book books = 1;
string next_page_token = 2;
}
message Other {}
message RepeatedOther {
repeated Other others = 1;
}
`, test)
s := file.GetServices()[0]
got := resourceMustSupportGet.Lint(file)
Expand Down

0 comments on commit 34aa3c8

Please sign in to comment.