From 3cf71fed094ad9dc56d0e8212c4a904f5ad3e00f Mon Sep 17 00:00:00 2001 From: michaelbausor Date: Fri, 19 Jun 2020 12:23:03 -0700 Subject: [PATCH] Fix snake_case for plural resource name (#569) --- rules/aip0136/http_parent_variable.go | 4 ++-- rules/aip0136/http_parent_variable_test.go | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/rules/aip0136/http_parent_variable.go b/rules/aip0136/http_parent_variable.go index 993a7c931..b15e0c7ed 100644 --- a/rules/aip0136/http_parent_variable.go +++ b/rules/aip0136/http_parent_variable.go @@ -37,8 +37,8 @@ var httpParentVariable = &lint.MethodRule{ if _, ok := vars["parent"]; ok { // Determine the resource. segs := strings.Split(strings.Split(http.GetPlainURI(), ":")[0], "/") - plural := segs[len(segs)-1] - singular := strcase.SnakeCase(p.Singular(plural)) + plural := strcase.SnakeCase(segs[len(segs)-1]) + singular := p.Singular(plural) // Does the RPC name end in the singular or plural name of the resource? // If not, complain. diff --git a/rules/aip0136/http_parent_variable_test.go b/rules/aip0136/http_parent_variable_test.go index 691904ac7..59c69552b 100644 --- a/rules/aip0136/http_parent_variable_test.go +++ b/rules/aip0136/http_parent_variable_test.go @@ -34,6 +34,7 @@ func TestHTTPParentVariable(t *testing.T) { {"ValidBookVar", "WritePage", "/v1/{book=publishers/*/books/*}:writePage", testutils.Problems{}}, {"ValidBatchGet", "BatchGetBooks", "/v1/{parent=publishers/*}/books:batchGet", testutils.Problems{}}, {"ValidBatchCreate", "BatchCreateBooks", "/v1/{parent=publishers/*}/books:batchCreate", testutils.Problems{}}, + {"ValidTwoWordNounBatch", "BatchUpdateAudioBooks", "/v1/{parent=publishers/*}/audioBooks:batchUpdate", testutils.Problems{}}, } { t.Run(test.name, func(t *testing.T) { f := testutils.ParseProto3Tmpl(t, `