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

fix(AIP-135): allow required etag in Delete #1414

Merged
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: 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
Loading