Skip to content

Commit

Permalink
fix(AIP-135): allow required etag in Delete (#1414)
Browse files Browse the repository at this point in the history
Allow Standard Field `etag` to be `REQUIRED` in Standard Delete.

Updates #1395
  • Loading branch information
noahdietz authored Aug 9, 2024
1 parent f9cf2eb commit aa9587b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions docs/rules/0135/request-required-fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ This rule looks at any message matching `Delete*Request` and complains if it
comes across any required fields other than:

- `string name` ([AIP-135][])
- `string etag` ([AIP-135][], [AIP-154][])

## Examples

Expand Down Expand Up @@ -62,4 +63,5 @@ If you need to violate this rule for an entire file, place the comment at the
top of the file.

[aip-135]: https://aip.dev/135
[aip-154]: https://aip.dev/154
[aip.dev/not-precedent]: https://aip.dev/not-precedent
4 changes: 3 additions & 1 deletion rules/aip0135/request_required_fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ var requestRequiredFields = &lint.MessageRule{
OnlyIf: utils.IsDeleteRequestMessage,
LintMessage: func(m *desc.MessageDescriptor) (problems []lint.Problem) {
// Rule check: Establish that there are no unexpected fields.
allowedRequiredFields := stringset.New("name")
// * name: required by AIP-135
// * etag: optional or required by both AIP-135 and AIP-154
allowedRequiredFields := stringset.New("name", "etag")

for _, f := range m.GetFields() {
if !utils.GetFieldBehavior(f).Contains("REQUIRED") {
Expand Down
6 changes: 6 additions & 0 deletions rules/aip0135/request_required_fields_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ func TestRequiredFieldTests(t *testing.T) {
"",
nil,
},
{
"ValidRequiredEtag",
"string etag = 2 [(google.api.field_behavior) = OPTIONAL];",
"etag",
nil,
},
{
"ValidOptionalAllowMissing",
"bool allow_missing = 2 [(google.api.field_behavior) = OPTIONAL];",
Expand Down

0 comments on commit aa9587b

Please sign in to comment.