Skip to content

Commit

Permalink
fix(AIP-123): skip resource-pattern-plural when there is no plural (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
noahdietz authored Jul 31, 2024
1 parent deb3983 commit 93a601d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion rules/aip0123/resource_pattern_plural.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
var resourcePatternPlural = &lint.MessageRule{
Name: lint.NewRuleName(123, "resource-pattern-plural"),
OnlyIf: func(m *desc.MessageDescriptor) bool {
return utils.IsResource(m) && len(utils.GetResource(m).GetPattern()) > 0 && !utils.IsSingletonResource(m)
return utils.IsResource(m) && len(utils.GetResource(m).GetPattern()) > 0 && utils.GetResourcePlural(utils.GetResource(m)) != "" && !utils.IsSingletonResource(m)
},
LintMessage: func(m *desc.MessageDescriptor) []lint.Problem {
var problems []lint.Problem
Expand Down
20 changes: 20 additions & 0 deletions rules/aip0123/resource_pattern_plural_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,23 @@ func TestResourcePatternPluralNested(t *testing.T) {
})
}
}

func TestResourcePatternPluralSkipNoPlural(t *testing.T) {
f := testutils.ParseProto3String(t, `
import "google/api/resource.proto";
message BookShelf {
option (google.api.resource) = {
type: "library.googleapis.com/BookShelf"
singular: "bookShelf"
plural: ""
pattern: "shelves/{shelf}/missingPlural/{book_shelf}"
};
string name = 1;
}
`)
findings := resourcePatternPlural.Lint(f)
if got, want := len(findings), 0; got != want {
t.Errorf("expected %d findings, got %d: %v", want, got, findings)
}
}

0 comments on commit 93a601d

Please sign in to comment.