Skip to content

Commit b41be6e

Browse files
authored
feat: allow request_id for standard Get and List (#1312)
1 parent bd89b13 commit b41be6e

File tree

6 files changed

+14
-1
lines changed

6 files changed

+14
-1
lines changed

docs/rules/0131/request-unknown-fields.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ This rule looks at any message matching `Get*Request` and complains if it comes
1919
across any fields other than:
2020

2121
- `string name` ([AIP-131][])
22+
- `string request_id` ([AIP-155][])
2223
- `google.protobuf.FieldMask read_mask` ([AIP-157][])
2324
- `View view` ([AIP-157][])
2425

@@ -62,5 +63,6 @@ If you need to violate this rule for an entire file, place the comment at the
6263
top of the file.
6364

6465
[aip-131]: https://aip.dev/131
66+
[aip-155]: https://aip.dev/155
6567
[aip-157]: https://aip.dev/157
6668
[aip.dev/not-precedent]: https://aip.dev/not-precedent

docs/rules/0132/request-unknown-fields.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ comes across any fields other than:
2525
- `string filter` ([AIP-132][])
2626
- `string order_by` ([AIP-132][])
2727
- `bool show_deleted` ([AIP-132][])
28+
- `string request_id` ([AIP-155][])
2829
- `google.protobuf.FieldMask read_mask` ([AIP-157][])
2930
- `View view` ([AIP-157][])
3031

@@ -79,6 +80,7 @@ top of the file.
7980

8081
[aip-132]: https://aip.dev/132
8182
[aip-135]: https://aip.dev/135
83+
[aip-155]: https://aip.dev/155
8284
[aip-157]: https://aip.dev/157
8385
[aip-158]: https://aip.dev/158
8486
[aip.dev/not-precedent]: https://aip.dev/not-precedent

rules/aip0131/request_unknown_fields.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,20 @@ import (
2424
"github.com/jhump/protoreflect/desc"
2525
)
2626

27+
var allowedFields = stringset.New(
28+
"name", // AIP-131
29+
"request_id", // AIP-155
30+
"read_mask", // AIP-157
31+
"view", // AIP-157
32+
)
33+
2734
// Get methods should not have unrecognized fields.
2835
var unknownFields = &lint.FieldRule{
2936
Name: lint.NewRuleName(131, "request-unknown-fields"),
3037
OnlyIf: func(f *desc.FieldDescriptor) bool {
3138
return utils.IsGetRequestMessage(f.GetOwner())
3239
},
3340
LintField: func(field *desc.FieldDescriptor) []lint.Problem {
34-
allowedFields := stringset.New("name", "read_mask", "view")
3541
if !allowedFields.Contains(field.GetName()) {
3642
return []lint.Problem{{
3743
Message: fmt.Sprintf(

rules/aip0131/request_unknown_fields_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func TestUnknownFields(t *testing.T) {
3838
fieldType *builder.FieldType
3939
problems testutils.Problems
4040
}{
41+
{"RequestId", "GetBookRequest", "request_id", builder.FieldTypeImportedMessage(fieldMask), testutils.Problems{}},
4142
{"ReadMask", "GetBookRequest", "read_mask", builder.FieldTypeImportedMessage(fieldMask), testutils.Problems{}},
4243
{"View", "GetBookRequest", "view", builder.FieldTypeEnum(builder.NewEnum("View").AddValue(builder.NewEnumValue("BASIC"))), testutils.Problems{}},
4344
{"Invalid", "GetBookRequest", "application_id", builder.FieldTypeString(), testutils.Problems{{

rules/aip0132/request_unknown_fields.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ var allowedFields = stringset.New(
2929
"filter", // AIP-132
3030
"order_by", // AIP-132
3131
"show_deleted", // AIP-135
32+
"request_id", // AIP-155
3233
"read_mask", // AIP-157
3334
"view", // AIP-157
3435
)

rules/aip0132/request_unknown_fields_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ func TestUnknownFields(t *testing.T) {
4444
{"Filter", "ListBooksRequest", "filter", builder.FieldTypeString(), testutils.Problems{}},
4545
{"OrderBy", "ListBooksRequest", "order_by", builder.FieldTypeString(), testutils.Problems{}},
4646
{"ShowDeleted", "ListBooksRequest", "show_deleted", builder.FieldTypeBool(), testutils.Problems{}},
47+
{"RequestId", "ListBooksRequest", "request_id", builder.FieldTypeImportedMessage(fieldMask), testutils.Problems{}},
4748
{"ReadMask", "ListBooksRequest", "read_mask", builder.FieldTypeImportedMessage(fieldMask), testutils.Problems{}},
4849
{"View", "ListBooksRequest", "view", builder.FieldTypeEnum(builder.NewEnum("View").AddValue(builder.NewEnumValue("BASIC"))), testutils.Problems{}},
4950
{"Invalid", "ListBooksRequest", "application_id", builder.FieldTypeString(), testutils.Problems{{Message: "explicitly described"}}},

0 commit comments

Comments
 (0)