Skip to content

Commit

Permalink
fix(AIP-135): removing df check in response-message-name (#1205)
Browse files Browse the repository at this point in the history
AIP-135 and AIP-128 have changed to not suggest soft-deleted
resources. This updates the linter to that recommendation.
  • Loading branch information
toumorokoshi authored Jul 19, 2023
1 parent 79f0b19 commit 42c9ce9
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 13 deletions.
3 changes: 0 additions & 3 deletions docs/rules/0135/response-message-name.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ if the name of the corresponding output message is not one of:
- `google.protobuf.Empty`
- The name of the RPC with the prefix `Delete` removed.

**Important:** For declarative-friendly resources, only the resource is
permitted as a return type.

It also permits a response of `google.longrunning.Operation`; in this case, it
checks the `response_type` in the `google.longrunning.operation_info`
annotation and ensures that _it_ corresponds to either `google.protobuf.Empty`
Expand Down
10 changes: 1 addition & 9 deletions rules/aip0135/response_message_name.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ var responseMessageName = &lint.MethodRule{
Name: lint.NewRuleName(135, "response-message-name"),
OnlyIf: isDeleteMethod,
LintMethod: func(m *desc.MethodDescriptor) []lint.Problem {
declFriendly := utils.IsDeclarativeFriendlyMethod(m)
resource := strings.Replace(m.GetName(), "Delete", "", 1)

// Rule check: Establish that for methods such as `DeleteFoo`, the response
Expand All @@ -41,10 +40,7 @@ var responseMessageName = &lint.MethodRule{
if stringset.New("Empty", "Operation").Contains(got) {
got = m.GetOutputType().GetFullyQualifiedName()
}
want := stringset.New(resource)
if !declFriendly {
want.Add("google.protobuf.Empty")
}
want := stringset.New(resource, "google.protobuf.Empty")

// If the return type is an Operation, use the annotated response type.
lro := false
Expand All @@ -63,10 +59,6 @@ var responseMessageName = &lint.MethodRule{
// not marked declarative-friendly)
msg := "Delete RPCs should have response message type of Empty or the resource, not %q."
suggestion := "google.protobuf.Empty"
if declFriendly {
msg = strings.Replace(msg, "Empty or ", "", 1)
suggestion = resource
}

// Customize the location based on whether an LRO is in use.
location := locations.MethodResponseType(m)
Expand Down
3 changes: 2 additions & 1 deletion rules/aip0135/response_message_name_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,10 @@ func TestResponseMessageName(t *testing.T) {
problems map[string]testutils.Problems
}{
{"ValidEmpty", "DeleteBook", "google.protobuf.Empty", "", problems["none"]},
// the declarative friendly style is no longer deviated for delete.
{"ValidEmptyDF", "DeleteBook", "google.protobuf.Empty", "style: DECLARATIVE_FRIENDLY", problems["none"]},
{"ValidResource", "DeleteBook", "Book", "", problems["none"]},
{"Invalid", "DeleteBook", "DeleteBookResponse", "", problems["empty"]},
{"InvalidEmptyDF", "DeleteBook", "google.protobuf.Empty", "style: DECLARATIVE_FRIENDLY", problems["book"]},
{"Irrelevant", "DestroyBook", "DestroyBookResponse", "", problems["none"]},
}

Expand Down

0 comments on commit 42c9ce9

Please sign in to comment.