From 11b92f8e40f88622d82cabdc77ebbc3fc42c2547 Mon Sep 17 00:00:00 2001 From: Alex Stephen Date: Mon, 9 Dec 2024 19:39:11 -0800 Subject: [PATCH] remove 132 rule --- docs/rules/0132/http-uri-parent.md | 65 --------------------------- rules/aep0132/aep0132.go | 1 - rules/aep0132/http_uri_parent.go | 31 ------------- rules/aep0132/http_uri_parent_test.go | 60 ------------------------- rules/internal/utils/common_lints.go | 1 + 5 files changed, 1 insertion(+), 157 deletions(-) delete mode 100644 docs/rules/0132/http-uri-parent.md delete mode 100644 rules/aep0132/http_uri_parent.go delete mode 100644 rules/aep0132/http_uri_parent_test.go diff --git a/docs/rules/0132/http-uri-parent.md b/docs/rules/0132/http-uri-parent.md deleted file mode 100644 index 6f67981..0000000 --- a/docs/rules/0132/http-uri-parent.md +++ /dev/null @@ -1,65 +0,0 @@ ---- -rule: - aep: 132 - name: [core, '0132', http-uri-parent] - summary: List methods must map the parent field to the URI. -permalink: /132/http-uri-parent -redirect_from: - - /0132/http-uri-parent ---- - -# List methods: HTTP URI parent field - -This rule enforces that all `List` RPCs map the `parent` field to the HTTP -URI, as mandated in [AEP-132][]. - -## Details - -This rule looks at any message beginning with `List`, and complains -if the `parent` variable is not included in the URI. It _does_ check additional -bindings if they are present. - -## Examples - -**Incorrect** code for this rule: - -```proto -// Incorrect. -rpc ListBooks(ListBooksRequest) returns (ListBooksResponse) { - option (google.api.http) = { - get: "/v1/publishers/*/books" // The `parent` field should be extracted. - }; -} -``` - -**Correct** code for this rule: - -```proto -// Correct. -rpc ListBooks(ListBooksRequest) returns (ListBooksResponse) { - option (google.api.http) = { - get: "/v1/{parent=publishers/*}/books" - }; -} -``` - -## Disabling - -If you need to violate this rule, use a leading comment above the method. -Remember to also include an [aep.dev/not-precedent][] comment explaining why. - -```proto -// (-- api-linter: core::0132::http-uri-parent=disabled -// aep.dev/not-precedent: We need to do this because reasons. --) -rpc ListBooks(ListBooksRequest) returns (ListBooksResponse) { - option (google.api.http) = { - get: "/v1/publishers/*/books" - }; -} -``` - -If you need to violate this rule for an entire file, place the comment at the -top of the file. - -[aep-132]: https://aep.dev/132 -[aep.dev/not-precedent]: https://aep.dev/not-precedent diff --git a/rules/aep0132/aep0132.go b/rules/aep0132/aep0132.go index aae71e4..8292f20 100644 --- a/rules/aep0132/aep0132.go +++ b/rules/aep0132/aep0132.go @@ -25,7 +25,6 @@ func AddRules(r lint.RuleRegistry) error { 132, httpBody, httpMethod, - httpURIParent, methodSignature, requestFieldTypes, requestMessageName, diff --git a/rules/aep0132/http_uri_parent.go b/rules/aep0132/http_uri_parent.go deleted file mode 100644 index db68886..0000000 --- a/rules/aep0132/http_uri_parent.go +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2021 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package aep0132 - -import ( - "github.com/aep-dev/api-linter/lint" - "github.com/aep-dev/api-linter/rules/internal/utils" - "github.com/jhump/protoreflect/desc" -) - -// List methods should have a parent variable if the request has a parent field. -var httpURIParent = &lint.MethodRule{ - Name: lint.NewRuleName(132, "http-uri-parent"), - RuleType: lint.NewRuleType(lint.MustRule), - OnlyIf: func(m *desc.MethodDescriptor) bool { - return utils.IsListMethod(m) && m.GetInputType().FindFieldByName("parent") != nil - }, - LintMethod: utils.LintHTTPURIHasParentVariable, -} diff --git a/rules/aep0132/http_uri_parent_test.go b/rules/aep0132/http_uri_parent_test.go deleted file mode 100644 index f4789fe..0000000 --- a/rules/aep0132/http_uri_parent_test.go +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright 2021 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package aep0132 - -import ( - "testing" - - "github.com/aep-dev/api-linter/rules/internal/testutils" -) - -func TestHTTPURIParent(t *testing.T) { - tests := []struct { - testName string - URI string - MethodName string - RequestField string - problems testutils.Problems - }{ - {"Valid", "/v1/{parent=publishers/*/books/*}", "ListBooks", "string parent = 1;", nil}, - {"InvalidVarParent", "/v1/{book=publishers/*/books/*}", "ListBooks", "string parent = 1;", testutils.Problems{{Message: "`parent` variable"}}}, - {"InvalidNoVarParent", "/v1/publishers/*/books/*", "ListBooks", "string parent = 1;", testutils.Problems{{Message: "`parent` variable"}}}, - {"ValidNoParent", "/v1/books/*", "ListBooks", "", nil}, - {"Irrelevant", "/v1/{book=publishers/*/books/*}", "BuildBook", "string parent = 1;", nil}, - } - - for _, test := range tests { - t.Run(test.testName, func(t *testing.T) { - f := testutils.ParseProto3Tmpl(t, ` - import "google/api/annotations.proto"; - service Library { - rpc {{.MethodName}}({{.MethodName}}Request) returns ({{.MethodName}}Response) { - option (google.api.http) = { - get: "{{.URI}}" - }; - } - } - message {{.MethodName}}Request { - {{.RequestField}} - } - message {{.MethodName}}Response {} - `, test) - method := f.GetServices()[0].GetMethods()[0] - if diff := test.problems.SetDescriptor(method).Diff(httpURIParent.Lint(f)); diff != "" { - t.Error(diff) - } - }) - } -} diff --git a/rules/internal/utils/common_lints.go b/rules/internal/utils/common_lints.go index 72b9022..979081e 100644 --- a/rules/internal/utils/common_lints.go +++ b/rules/internal/utils/common_lints.go @@ -194,6 +194,7 @@ func LintMethodHasMatchingResponseName(m *desc.MethodDescriptor) []lint.Problem // LintHTTPURIHasParentVariable returns a problem if any of the given method's HTTP rules do not // have a parent variable in the URI. +// This is only required if the resource is not top-level. func LintHTTPURIHasParentVariable(m *desc.MethodDescriptor) []lint.Problem { return LintHTTPURIHasVariable(m, "parent") }