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

Resource messages should be identified by the 'path' field #98

Merged
merged 1 commit into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading