Repository: googleapis/api-linter (go)

Issue:
AIP 136 http-uri-suffix incorrect flags batch custom methods
When following https://aip.dev/231, https://linter.aip.dev/136/http-uri-suffix will give a lint message that

For code:

```
  rpc BatchGetContactGroups(BatchGetContactGroupsRequest)
      returns (BatchGetContactGroupsResponse) {
    option (google.api.http).get = "/v1/contactGroups:batchGet";
    option deadline = 10.0;
    option fail_fast = true;
  }
```

Linter gives error:"

message: Custom method should have a URI suffix matching the method name, such
      as ":batchGetContactGroups".
    rule_id: core::0136::http-uri-suffix
    rule_doc_uri: https://linter.aip.dev/136/http-uri-suffix

Pull request description:
[fix] Stop false positive on batch methods.
Fixes #464.

Patch:
diff --git a/rules/aip0136/http_uri_suffix.go b/rules/aip0136/http_uri_suffix.go
index 33b9f2d..981fbcb 100644
--- a/rules/aip0136/http_uri_suffix.go
+++ b/rules/aip0136/http_uri_suffix.go
@@ -49,7 +49,12 @@ var uriSuffix = &lint.MethodRule{
 			//      from upper camel to lower camel correctly.
 			want := ":" + strcase.LowerCamelCase(strcase.SnakeCase(m.GetName()))
 			if strings.Contains(httpRule.URI, "{name=") || strings.Contains(httpRule.URI, "{parent=") {
-				want = ":" + strings.Split(strcase.SnakeCase(m.GetName()), "_")[0]
+				rpcSlice := strings.Split(strcase.SnakeCase(m.GetName()), "_")
+				if rpcSlice[0] == "batch" {
+					want = ":" + strcase.LowerCamelCase(rpcSlice[0]+"_"+rpcSlice[1])
+				} else {
+					want = ":" + rpcSlice[0]
+				}
 			}
 
 			// Do we have the suffix we expect?


Test patch:
diff --git a/rules/aip0136/http_uri_suffix_test.go b/rules/aip0136/http_uri_suffix_test.go
index 669d932..55c0ac5 100644
--- a/rules/aip0136/http_uri_suffix_test.go
+++ b/rules/aip0136/http_uri_suffix_test.go
@@ -29,6 +29,7 @@ func TestURISuffix(t *testing.T) {
 	}{
 		{"ValidVerb", "ArchiveBook", "/v1/{name=publishers/*/books}:archive", testutils.Problems{}},
 		{"ValidVerbParent", "ImportBooks", "/v1/{parent=publishers/*}/books:import", testutils.Problems{}},
+		{"ValidVerbParentBatchGet", "BatchGetBooks", "/v1/{parent=publishers/*}/books:batchGet", testutils.Problems{}},
 		{"InvalidVerb", "ArchiveBook", "/v1/{name=publishers/*/books}:archiveBook", testutils.Problems{{Message: ":archive"}}},
 		{"ValidVerbNounNoVars", "TranslateText", "/v3:translateText", testutils.Problems{}},
 		{"ValidVerbNounNoName", "TranslateText", "/v3/{location=projects/*/locations/*}:translateText", testutils.Problems{}},