Skip to content

Commit

Permalink
fix(AIP-203): resource etag should not have behavior (#1376)
Browse files Browse the repository at this point in the history
  • Loading branch information
noahdietz authored Apr 16, 2024
1 parent 5bde03e commit 1c0f838
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 6 additions & 1 deletion rules/aip0203/field_behavior_required.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ var minimumRequiredFieldBehavior = stringset.New(
"OPTIONAL", "REQUIRED", "OUTPUT_ONLY", "IMMUTABLE",
)

var excusedResourceFields = stringset.New(
"name", // Uses https://google.aip.dev/203#identifier
"etag", // Prohibited by https://google.aip.dev/154
)

var fieldBehaviorRequired = &lint.MethodRule{
Name: lint.NewRuleName(203, "field-behavior-required"),
LintMethod: func(m *desc.MethodDescriptor) []lint.Problem {
Expand All @@ -51,7 +56,7 @@ func problems(m *desc.MessageDescriptor, pkg string, visited map[desc.Descriptor
}
visited[f] = true

if utils.IsResource(m) && f.GetName() == "name" {
if utils.IsResource(m) && excusedResourceFields.Contains(f.GetName()) {
continue
}

Expand Down
2 changes: 2 additions & 0 deletions rules/aip0203/field_behavior_required_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ func TestFieldBehaviorRequired_SingleFile_SingleMessage(t *testing.T) {
};
string name = 1;
string etag = 2;
}
`, tc)
field := f.GetMessageTypes()[0].GetFields()[0]
Expand Down

0 comments on commit 1c0f838

Please sign in to comment.