Repository: googleapis/api-linter
Pull request #646 (2020-10-06 20:27:21)

Add rules for unknown fields in batch requests
Part of #612.


Patch:
diff --git a/docs/rules/0231/request-unknown-fields.md b/docs/rules/0231/request-unknown-fields.md
new file mode 100644
index 0000000..5363197
--- /dev/null
+++ b/docs/rules/0231/request-unknown-fields.md
@@ -0,0 +1,90 @@
+---
+rule:
+  aip: 231
+  name: [core, '0231', request-unknown-fields]
+  summary: Batch Get RPCs should not have unexpected fields in the request.
+permalink: /231/request-unknown-fields
+redirect_from:
+  - /0231/request-unknown-fields
+---
+
+# Batch Get methods: Unknown request fields
+
+This rule enforces that all `BatchGet` standard methods do not have unexpected
+fields, as mandated in [AIP-231][].
+
+## Details
+
+This rule looks at any message matching `BatchGet*Request` and complains if it comes
+across any fields other than:
+
+- `repeated string names` ([AIP-231][])
+- `string parent` ([AIP-231][])
+- `google.protobuf.FieldMask read_mask` ([AIP-157][])
+- `repeated Get*Request requests` ([AIP-231][])
+- `View view` ([AIP-157][])
+
+## Examples
+
+**Incorrect** code for this rule:
+
+```proto
+// Incorrect.
+message BatchGetBooksRequest {
+  string parent = 1 [
+    (google.api.resource_reference).child_type = "library.googleapis.com/Book"
+  ];
+
+  repeated string names = 2 [
+    (google.api.field_behavior) = REQUIRED,
+    (google.api.resource_reference).type = "library.googleapis.com/Book"
+  ];
+
+  string library_id = 3;  // Non-standard field.
+}
+```
+
+**Correct** code for this rule:
+
+```proto
+// Correct.
+message BatchGetBooksRequest {
+  string parent = 1 [
+    (google.api.resource_reference).child_type = "library.googleapis.com/Book"
+  ];
+
+  repeated string names = 2 [
+    (google.api.field_behavior) = REQUIRED,
+    (google.api.resource_reference).type = "library.googleapis.com/Book"
+  ];
+}
+```
+
+## Disabling
+
+If you need to violate this rule, use a leading comment above the field.
+Remember to also include an [aip.dev/not-precedent][] comment explaining why.
+
+```proto
+message BatchGetBooksRequest {
+  string parent = 1 [
+    (google.api.resource_reference).child_type = "library.googleapis.com/Book"
+  ];
+
+  repeated string names = 2 [
+    (google.api.field_behavior) = REQUIRED,
+    (google.api.resource_reference).type = "library.googleapis.com/Book"
+  ];
+
+  // (-- api-linter: core::0231::request-unknown-fields=disabled
+  //     aip.dev/not-precedent: We really need this field because reasons. --)
+  string library_id = 3;
+}
+```
+
+If you need to violate this rule for an entire file, place the comment at the
+top of the file.
+
+[aip-157]: https://aip.dev/157
+[aip-231]: https://aip.dev/231
+[aip.dev/not-precedent]: https://aip.dev/not-precedent
diff --git a/docs/rules/0233/request-unknown-fields.md b/docs/rules/0233/request-unknown-fields.md
new file mode 100644
index 0000000..69fc2d0
--- /dev/null
+++ b/docs/rules/0233/request-unknown-fields.md
@@ -0,0 +1,87 @@
+---
+rule:
+  aip: 233
+  name: [core, '0233', request-unknown-fields]
+  summary: Batch Create RPCs should not have unexpected fields in the request.
+permalink: /233/request-unknown-fields
+redirect_from:
+  - /0233/request-unknown-fields
+---
+
+# Batch Create methods: Unknown request fields
+
+This rule enforces that all `BatchCreate` standard methods do not have unexpected
+fields, as mandated in [AIP-233][].
+
+## Details
+
+This rule looks at any message matching `BatchCreate*Request` and complains if it comes
+across any fields other than:
+
+- `string parent` ([AIP-233][])
+- `string request_id` ([AIP-155][])
+- `repeated Create*Request requests` ([AIP-233][])
+- `bool validate_only` ([AIP-163][])
+
+## Examples
+
+**Incorrect** code for this rule:
+
+```proto
+// Incorrect.
+message BatchCreateBooksRequest {
+  string parent = 1 [
+    (google.api.resource_reference).child_type = "library.googleapis.com/Book"
+  ];
+
+  repeated CreateBookRequest requests = 2 [
+    (google.api.field_behavior) = REQUIRED
+  ];
+
+  string library_id = 3;  // Non-standard field.
+}
+```
+
+**Correct** code for this rule:
+
+```proto
+// Correct.
+message BatchCreateBooksRequest {
+  string parent = 1 [
+    (google.api.resource_reference).child_type = "library.googleapis.com/Book"
+  ];
+
+  repeated CreateBookRequest requests = 2 [
+    (google.api.field_behavior) = REQUIRED
+  ];
+}
+```
+
+## Disabling
+
+If you need to violate this rule, use a leading comment above the field.
+Remember to also include an [aip.dev/not-precedent][] comment explaining why.
+
+```proto
+message BatchCreateBooksRequest {
+  string parent = 1 [
+    (google.api.resource_reference).child_type = "library.googleapis.com/Book"
+  ];
+
+  repeated CreateBookRequest requests = 2 [
+    (google.api.field_behavior) = REQUIRED
+  ];
+
+  // (-- api-linter: core::0233::request-unknown-fields=disabled
+  //     aip.dev/not-precedent: We really need this field because reasons. --)
+  string library_id = 3;
+}
+```
+
+If you need to violate this rule for an entire file, place the comment at the
+top of the file.
+
+[aip-155]: https://aip.dev/155
+[aip-163]: https://aip.dev/163
+[aip-233]: https://aip.dev/233
+[aip.dev/not-precedent]: https://aip.dev/not-precedent
diff --git a/docs/rules/0234/request-unknown-fields.md b/docs/rules/0234/request-unknown-fields.md
new file mode 100644
index 0000000..7daa55d
--- /dev/null
+++ b/docs/rules/0234/request-unknown-fields.md
@@ -0,0 +1,89 @@
+---
+rule:
+  aip: 234
+  name: [core, '0234', request-unknown-fields]
+  summary: Batch Update RPCs should not have unexpected fields in the request.
+permalink: /234/request-unknown-fields
+redirect_from:
+  - /0234/request-unknown-fields
+---
+
+# Batch Update methods: Unknown request fields
+
+This rule enforces that all `BatchUpdate` standard methods do not have unexpected
+fields, as mandated in [AIP-234][].
+
+## Details
+
+This rule looks at any message matching `BatchUpdate*Request` and complains if it comes
+across any fields other than:
+
+- `string parent` ([AIP-234][])
+- `string request_id` ([AIP-155][])
+- `repeated Update*Request requests` ([AIP-234][])
+- `google.protobuf.FieldMask update_mask` ([AIP-134][])
+- `bool validate_only` ([AIP-163][])
+
+## Examples
+
+**Incorrect** code for this rule:
+
+```proto
+// Incorrect.
+message BatchUpdateBooksRequest {
+  string parent = 1 [
+    (google.api.resource_reference).child_type = "library.googleapis.com/Book"
+  ];
+
+  repeated UpdateBookRequest requests = 2 [
+    (google.api.field_behavior) = REQUIRED
+  ];
+
+  string library_id = 3;  // Non-standard field.
+}
+```
+
+**Correct** code for this rule:
+
+```proto
+// Correct.
+message BatchUpdateBooksRequest {
+  string parent = 1 [
+    (google.api.resource_reference).child_type = "library.googleapis.com/Book"
+  ];
+
+  repeated UpdateBookRequest requests = 2 [
+    (google.api.field_behavior) = REQUIRED
+  ];
+}
+```
+
+## Disabling
+
+If you need to violate this rule, use a leading comment above the field.
+Remember to also include an [aip.dev/not-precedent][] comment explaining why.
+
+```proto
+message BatchUpdateBooksRequest {
+  string parent = 1 [
+    (google.api.resource_reference).child_type = "library.googleapis.com/Book"
+  ];
+
+  repeated UpdateBookRequest requests = 2 [
+    (google.api.field_behavior) = REQUIRED
+  ];
+
+  // (-- api-linter: core::0234::request-unknown-fields=disabled
+  //     aip.dev/not-precedent: We really need this field because reasons. --)
+  string library_id = 3;
+}
+```
+
+If you need to violate this rule for an entire file, place the comment at the
+top of the file.
+
+[aip-134]: https://aip.dev/134
+[aip-155]: https://aip.dev/155
+[aip-163]: https://aip.dev/163
+[aip-234]: https://aip.dev/234
+[aip.dev/not-precedent]: https://aip.dev/not-precedent
diff --git a/docs/rules/0235/request-unknown-fields.md b/docs/rules/0235/request-unknown-fields.md
new file mode 100644
index 0000000..c8adea3
--- /dev/null
+++ b/docs/rules/0235/request-unknown-fields.md
@@ -0,0 +1,93 @@
+---
+rule:
+  aip: 235
+  name: [core, '0235', request-unknown-fields]
+  summary: Batch Delete RPCs should not have unexpected fields in the request.
+permalink: /235/request-unknown-fields
+redirect_from:
+  - /0235/request-unknown-fields
+---
+
+# Batch Delete methods: Unknown request fields
+
+This rule enforces that all `BatchDelete` standard methods do not have unexpected
+fields, as mandated in [AIP-235][].
+
+## Details
+
+This rule looks at any message matching `BatchDelete*Request` and complains if it comes
+across any fields other than:
+
+- `bool force` ([AIP-135][])
+- `repeated string names` ([AIP-235][])
+- `string parent` ([AIP-235][])
+- `string request_id` ([AIP-155][])
+- `repeated Delete*Request requests` ([AIP-235][])
+- `bool validate_only` ([AIP-163][])
+
+## Examples
+
+**Incorrect** code for this rule:
+
+```proto
+// Incorrect.
+message BatchDeleteBooksRequest {
+  string parent = 1 [
+    (google.api.resource_reference).child_type = "library.googleapis.com/Book"
+  ];
+
+  repeated string names = 2 [
+    (google.api.field_behavior) = REQUIRED,
+    (google.api.resource_reference).type = "library.googleapis.com/Book"
+  ];
+
+  string library_id = 3;  // Non-standard field.
+}
+```
+
+**Correct** code for this rule:
+
+```proto
+// Correct.
+message BatchDeleteBooksRequest {
+  string parent = 1 [
+    (google.api.resource_reference).child_type = "library.googleapis.com/Book"
+  ];
+
+  repeated string names = 2 [
+    (google.api.field_behavior) = REQUIRED,
+    (google.api.resource_reference).type = "library.googleapis.com/Book"
+  ];
+}
+```
+
+## Disabling
+
+If you need to violate this rule, use a leading comment above the field.
+Remember to also include an [aip.dev/not-precedent][] comment explaining why.
+
+```proto
+message BatchDeleteBooksRequest {
+  string parent = 1 [
+    (google.api.resource_reference).child_type = "library.googleapis.com/Book"
+  ];
+
+  repeated string names = 2 [
+    (google.api.field_behavior) = REQUIRED,
+    (google.api.resource_reference).type = "library.googleapis.com/Book"
+  ];
+
+  // (-- api-linter: core::0235::request-unknown-fields=disabled
+  //     aip.dev/not-precedent: We really need this field because reasons. --)
+  string library_id = 3;
+}
+```
+
+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-155]: https://aip.dev/155
+[aip-163]: https://aip.dev/163
+[aip-235]: https://aip.dev/235
+[aip.dev/not-precedent]: https://aip.dev/not-precedent
diff --git a/rules/aip0231/aip0231.go b/rules/aip0231/aip0231.go
index 81c7ec5..45f10f3 100644
--- a/rules/aip0231/aip0231.go
+++ b/rules/aip0231/aip0231.go
@@ -37,6 +37,7 @@ func AddRules(r lint.RuleRegistry) error {
 		requestNamesReference,
 		requestParentField,
 		requestParentReference,
+		requestUnknownFields,
 		resourceField,
 		uriSuffix,
 	)
diff --git a/rules/aip0231/request_unknown_fields.go b/rules/aip0231/request_unknown_fields.go
new file mode 100644
index 0000000..68231ec
--- /dev/null
+++ b/rules/aip0231/request_unknown_fields.go
@@ -0,0 +1,52 @@
+// Copyright 2020 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 aip0231
+
+import (
+	"fmt"
+
+	"bitbucket.org/creachadair/stringset"
+
+	"github.com/googleapis/api-linter/lint"
+	"github.com/jhump/protoreflect/desc"
+)
+
+// Batch Get methods should not have unrecognized fields.
+var requestUnknownFields = &lint.FieldRule{
+	Name: lint.NewRuleName(231, "request-unknown-fields"),
+	OnlyIf: func(f *desc.FieldDescriptor) bool {
+		return isBatchGetRequestMessage(f.GetOwner())
+	},
+	LintField: func(field *desc.FieldDescriptor) []lint.Problem {
+		allowedFields := stringset.New(
+			"names",     // AIP-231
+			"parent",    // AIP-231
+			"read_mask", // AIP-157
+			"requests",  // AIP-231
+			"view",      // AIP-157
+		)
+		if !allowedFields.Contains(field.GetName()) {
+			return []lint.Problem{{
+				Message: fmt.Sprintf(
+					"Unexpected field: Batch Get RPCs must only contain fields explicitly described in https://aip.dev/231, not %q.",
+					string(field.GetName()),
+				),
+				Descriptor: field,
+			}}
+		}
+
+		return nil
+	},
+}
diff --git a/rules/aip0233/aip0233.go b/rules/aip0233/aip0233.go
index 7fef05f..b497b06 100644
--- a/rules/aip0233/aip0233.go
+++ b/rules/aip0233/aip0233.go
@@ -37,6 +37,7 @@ func AddRules(r lint.RuleRegistry) error {
 		requestParentReference,
 		requestRequestsBehavior,
 		requestRequestsField,
+		requestUnknownFields,
 		responseResourceField,
 	)
 }
diff --git a/rules/aip0233/request_unknown_fields.go b/rules/aip0233/request_unknown_fields.go
new file mode 100644
index 0000000..04a40e3
--- /dev/null
+++ b/rules/aip0233/request_unknown_fields.go
@@ -0,0 +1,51 @@
+// Copyright 2020 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 aip0233
+
+import (
+	"fmt"
+
+	"bitbucket.org/creachadair/stringset"
+
+	"github.com/googleapis/api-linter/lint"
+	"github.com/jhump/protoreflect/desc"
+)
+
+// Batch Create methods should not have unrecognized fields.
+var requestUnknownFields = &lint.FieldRule{
+	Name: lint.NewRuleName(233, "request-unknown-fields"),
+	OnlyIf: func(f *desc.FieldDescriptor) bool {
+		return isBatchCreateRequestMessage(f.GetOwner())
+	},
+	LintField: func(field *desc.FieldDescriptor) []lint.Problem {
+		allowedFields := stringset.New(
+			"parent",        // AIP-233
+			"request_id",    // AIP-155
+			"requests",      // AIP-233
+			"validate_only", // AIP-163
+		)
+		if !allowedFields.Contains(field.GetName()) {
+			return []lint.Problem{{
+				Message: fmt.Sprintf(
+					"Unexpected field: Batch Create RPCs must only contain fields explicitly described in https://aip.dev/233, not %q.",
+					string(field.GetName()),
+				),
+				Descriptor: field,
+			}}
+		}
+
+		return nil
+	},
+}
diff --git a/rules/aip0234/aip0234.go b/rules/aip0234/aip0234.go
index ec93ff6..cbb28b0 100644
--- a/rules/aip0234/aip0234.go
+++ b/rules/aip0234/aip0234.go
@@ -36,6 +36,7 @@ func AddRules(r lint.RuleRegistry) error {
 		requestParentReference,
 		requestRequestsBehavior,
 		requestRequestsField,
+		requestUnknownFields,
 		responseMessageName,
 		responseResourceField,
 	)
diff --git a/rules/aip0234/request_unknown_fields.go b/rules/aip0234/request_unknown_fields.go
new file mode 100644
index 0000000..1f3c093
--- /dev/null
+++ b/rules/aip0234/request_unknown_fields.go
@@ -0,0 +1,52 @@
+// Copyright 2020 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 aip0234
+
+import (
+	"fmt"
+
+	"bitbucket.org/creachadair/stringset"
+
+	"github.com/googleapis/api-linter/lint"
+	"github.com/jhump/protoreflect/desc"
+)
+
+// Batch Update methods should not have unrecognized fields.
+var requestUnknownFields = &lint.FieldRule{
+	Name: lint.NewRuleName(234, "request-unknown-fields"),
+	OnlyIf: func(f *desc.FieldDescriptor) bool {
+		return isBatchUpdateRequestMessage(f.GetOwner())
+	},
+	LintField: func(field *desc.FieldDescriptor) []lint.Problem {
+		allowedFields := stringset.New(
+			"parent",        // AIP-234
+			"request_id",    // AIP-155
+			"requests",      // AIP-234
+			"update_mask",   // AIP-134
+			"validate_only", // AIP-163
+		)
+		if !allowedFields.Contains(field.GetName()) {
+			return []lint.Problem{{
+				Message: fmt.Sprintf(
+					"Unexpected field: Batch Update RPCs must only contain fields explicitly described in https://aip.dev/234, not %q.",
+					string(field.GetName()),
+				),
+				Descriptor: field,
+			}}
+		}
+
+		return nil
+	},
+}
diff --git a/rules/aip0235/aip0235.go b/rules/aip0235/aip0235.go
index d80f2a0..de0b64b 100644
--- a/rules/aip0235/aip0235.go
+++ b/rules/aip0235/aip0235.go
@@ -38,6 +38,7 @@ func AddRules(r lint.RuleRegistry) error {
 		requestParentField,
 		requestParentReference,
 		requestRequestsBehavior,
+		requestUnknownFields,
 	)
 }
 
diff --git a/rules/aip0235/request_unknown_fields.go b/rules/aip0235/request_unknown_fields.go
new file mode 100644
index 0000000..0314f10
--- /dev/null
+++ b/rules/aip0235/request_unknown_fields.go
@@ -0,0 +1,53 @@
+// Copyright 2020 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 aip0235
+
+import (
+	"fmt"
+
+	"bitbucket.org/creachadair/stringset"
+
+	"github.com/googleapis/api-linter/lint"
+	"github.com/jhump/protoreflect/desc"
+)
+
+// Batch Delete methods should not have unrecognized fields.
+var requestUnknownFields = &lint.FieldRule{
+	Name: lint.NewRuleName(235, "request-unknown-fields"),
+	OnlyIf: func(f *desc.FieldDescriptor) bool {
+		return isBatchDeleteRequestMessage(f.GetOwner())
+	},
+	LintField: func(field *desc.FieldDescriptor) []lint.Problem {
+		allowedFields := stringset.New(
+			"force",         // AIP-135
+			"names",         // AIP-235
+			"parent",        // AIP-235
+			"request_id",    // AIP-155
+			"requests",      // AIP-235
+			"validate_only", // AIP-163
+		)
+		if !allowedFields.Contains(field.GetName()) {
+			return []lint.Problem{{
+				Message: fmt.Sprintf(
+					"Unexpected field: Batch Delete RPCs must only contain fields explicitly described in https://aip.dev/235, not %q.",
+					string(field.GetName()),
+				),
+				Descriptor: field,
+			}}
+		}
+
+		return nil
+	},
+}


Test patch:
diff --git a/rules/aip0231/request_unknown_fields_test.go b/rules/aip0231/request_unknown_fields_test.go
new file mode 100644
index 0000000..86bfc9c
--- /dev/null
+++ b/rules/aip0231/request_unknown_fields_test.go
@@ -0,0 +1,50 @@
+// Copyright 2020 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 aip0231
+
+import (
+	"testing"
+
+	"github.com/googleapis/api-linter/rules/internal/testutils"
+)
+
+func TestRequestUnknownFields(t *testing.T) {
+	for _, test := range []struct {
+		name        string
+		MessageName string
+		FieldName   string
+		problems    testutils.Problems
+	}{
+		{"Valid-Names", "BatchGetBooks", "names", testutils.Problems{}},
+		{"Valid-Parent", "BatchGetBooks", "parent", testutils.Problems{}},
+		{"Valid-ReadMask", "BatchGetBooks", "read_mask", testutils.Problems{}},
+		{"Valid-Requests", "BatchGetBooks", "requests", testutils.Problems{}},
+		{"Valid-View", "BatchGetBooks", "view", testutils.Problems{}},
+		{"Invalid", "BatchGetBooks", "foo", testutils.Problems{{Message: "Unexpected field"}}},
+		{"IrrelevantMessage", "GetBooks", "foo", testutils.Problems{}},
+	} {
+		t.Run(test.name, func(t *testing.T) {
+			f := testutils.ParseProto3Tmpl(t, `
+				message {{.MessageName}}Request {
+					repeated string {{.FieldName}} = 1;
+				}
+			`, test)
+			field := f.GetMessageTypes()[0].GetFields()[0]
+			if diff := test.problems.SetDescriptor(field).Diff(requestUnknownFields.Lint(f)); diff != "" {
+				t.Errorf(diff)
+			}
+		})
+	}
+}
diff --git a/rules/aip0233/request_unknown_fields_test.go b/rules/aip0233/request_unknown_fields_test.go
new file mode 100644
index 0000000..f0e611d
--- /dev/null
+++ b/rules/aip0233/request_unknown_fields_test.go
@@ -0,0 +1,49 @@
+// Copyright 2020 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 aip0233
+
+import (
+	"testing"
+
+	"github.com/googleapis/api-linter/rules/internal/testutils"
+)
+
+func TestRequestUnknownFields(t *testing.T) {
+	for _, test := range []struct {
+		name        string
+		MessageName string
+		FieldName   string
+		problems    testutils.Problems
+	}{
+		{"Valid-Parent", "BatchCreateBooks", "parent", testutils.Problems{}},
+		{"Valid-RequestID", "BatchCreateBooks", "request_id", testutils.Problems{}},
+		{"Valid-Requests", "BatchCreateBooks", "requests", testutils.Problems{}},
+		{"Valid-ValidateOnly", "BatchCreateBooks", "validate_only", testutils.Problems{}},
+		{"Invalid", "BatchCreateBooks", "foo", testutils.Problems{{Message: "Unexpected field"}}},
+		{"IrrelevantMessage", "CreateBooks", "foo", testutils.Problems{}},
+	} {
+		t.Run(test.name, func(t *testing.T) {
+			f := testutils.ParseProto3Tmpl(t, `
+				message {{.MessageName}}Request {
+					repeated string {{.FieldName}} = 1;
+				}
+			`, test)
+			field := f.GetMessageTypes()[0].GetFields()[0]
+			if diff := test.problems.SetDescriptor(field).Diff(requestUnknownFields.Lint(f)); diff != "" {
+				t.Errorf(diff)
+			}
+		})
+	}
+}
diff --git a/rules/aip0234/request_unknown_fields_test.go b/rules/aip0234/request_unknown_fields_test.go
new file mode 100644
index 0000000..cac4456
--- /dev/null
+++ b/rules/aip0234/request_unknown_fields_test.go
@@ -0,0 +1,50 @@
+// Copyright 2020 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 aip0234
+
+import (
+	"testing"
+
+	"github.com/googleapis/api-linter/rules/internal/testutils"
+)
+
+func TestRequestUnknownFields(t *testing.T) {
+	for _, test := range []struct {
+		name        string
+		MessageName string
+		FieldName   string
+		problems    testutils.Problems
+	}{
+		{"Valid-Parent", "BatchUpdateBooks", "parent", testutils.Problems{}},
+		{"Valid-RequestID", "BatchCreateBooks", "request_id", testutils.Problems{}},
+		{"Valid-Requests", "BatchUpdateBooks", "requests", testutils.Problems{}},
+		{"Valid-UpdateMask", "BatchUpdateBooks", "update_mask", testutils.Problems{}},
+		{"Valid-ValidateOnly", "BatchUpdateBooks", "validate_only", testutils.Problems{}},
+		{"Invalid", "BatchUpdateBooks", "foo", testutils.Problems{{Message: "Unexpected field"}}},
+		{"IrrelevantMessage", "UpdateBooks", "foo", testutils.Problems{}},
+	} {
+		t.Run(test.name, func(t *testing.T) {
+			f := testutils.ParseProto3Tmpl(t, `
+				message {{.MessageName}}Request {
+					repeated string {{.FieldName}} = 1;
+				}
+			`, test)
+			field := f.GetMessageTypes()[0].GetFields()[0]
+			if diff := test.problems.SetDescriptor(field).Diff(requestUnknownFields.Lint(f)); diff != "" {
+				t.Errorf(diff)
+			}
+		})
+	}
+}
diff --git a/rules/aip0235/request_unknown_fields_test.go b/rules/aip0235/request_unknown_fields_test.go
new file mode 100644
index 0000000..11d830b
--- /dev/null
+++ b/rules/aip0235/request_unknown_fields_test.go
@@ -0,0 +1,51 @@
+// Copyright 2020 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 aip0235
+
+import (
+	"testing"
+
+	"github.com/googleapis/api-linter/rules/internal/testutils"
+)
+
+func TestRequestUnknownFields(t *testing.T) {
+	for _, test := range []struct {
+		name        string
+		MessageName string
+		FieldName   string
+		problems    testutils.Problems
+	}{
+		{"Valid-Force", "BatchDeleteBooks", "force", testutils.Problems{}},
+		{"Valid-Names", "BatchDeleteBooks", "names", testutils.Problems{}},
+		{"Valid-Parent", "BatchDeleteBooks", "parent", testutils.Problems{}},
+		{"Valid-RequestID", "BatchCreateBooks", "request_id", testutils.Problems{}},
+		{"Valid-Requests", "BatchDeleteBooks", "requests", testutils.Problems{}},
+		{"Valid-ValidateOnly", "BatchDeleteBooks", "validate_only", testutils.Problems{}},
+		{"Invalid", "BatchDeleteBooks", "foo", testutils.Problems{{Message: "Unexpected field"}}},
+		{"IrrelevantMessage", "DeleteBooks", "foo", testutils.Problems{}},
+	} {
+		t.Run(test.name, func(t *testing.T) {
+			f := testutils.ParseProto3Tmpl(t, `
+				message {{.MessageName}}Request {
+					repeated string {{.FieldName}} = 1;
+				}
+			`, test)
+			field := f.GetMessageTypes()[0].GetFields()[0]
+			if diff := test.problems.SetDescriptor(field).Diff(requestUnknownFields.Lint(f)); diff != "" {
+				t.Errorf(diff)
+			}
+		})
+	}
+}