Skip to content

Commit

Permalink
fixing 92 by using path field (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
rambleraptor authored Nov 3, 2024
1 parent d95b836 commit c2ec184
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion rules/aep0004/aep0004.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func isResourceMessage(m *desc.MessageDescriptor) bool {
// If the parent of this message is a message, it is nested and shoudn't
// be considered a resource, even if it has a name field.
_, nested := m.GetParent().(*desc.MessageDescriptor)
return m.FindFieldByName("name") != nil && !strings.HasSuffix(m.GetName(), "Request") &&
return m.FindFieldByName("path") != nil && !strings.HasSuffix(m.GetName(), "Request") &&
!strings.HasSuffix(m.GetName(), "Response") && !nested
}

Expand Down
10 changes: 5 additions & 5 deletions rules/aep0004/resource_annotation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestResourceAnnotation(t *testing.T) {
type: "library.googleapis.com/Book"
pattern: "publishers/{publisher}/books/{book}"
};
string name = 1;
string path = 1;
}
`)
if diff := (testutils.Problems{}).Diff(resourceAnnotation.Lint(f)); diff != "" {
Expand All @@ -42,7 +42,7 @@ func TestResourceAnnotation(t *testing.T) {
f := testutils.ParseProto3String(t, `
message Foo {
message Bar {
string name = 1;
string path = 1;
}
Bar bar = 1;
}
Expand All @@ -61,9 +61,9 @@ func TestResourceAnnotation(t *testing.T) {
problems testutils.Problems
}{
{"ValidNoNameField", "Book", "title", testutils.Problems{}},
{"ValidRequestMessage", "GetBookRequest", "name", testutils.Problems{}},
{"ValidResponseMessage", "GetBookResponse", "name", testutils.Problems{}},
{"Invalid", "Book", "name", testutils.Problems{{Message: "google.api.resource"}}},
{"ValidRequestMessage", "GetBookRequest", "path", testutils.Problems{}},
{"ValidResponseMessage", "GetBookResponse", "path", testutils.Problems{}},
{"Invalid", "Book", "path", testutils.Problems{{Message: "google.api.resource"}}},
} {
t.Run(test.name, func(t *testing.T) {
f := testutils.ParseProto3Tmpl(t, `
Expand Down

0 comments on commit c2ec184

Please sign in to comment.