Paginated methods: Page token field
This rule enforces that all List
and Search
methods have a plural name
repeatable field as a first field in the response message, as mandated in
AIP-158.
Details
This rule looks at any message matching List*Response
or Search*Response
that has next_page_token
field and complains if the first field’s name is not
plural.
Examples
Incorrect code for this rule:
// Incorrect
message ListBooksResponse {
// Field name should be `books`.
repeated Book book = 1;
string next_page_token = 2;
}
Correct code for this rule:
// Correct.
message ListBooksResponse {
repeated Book books = 1;
string next_page_token = 2;
}
NOTE: If the field is a resource, the plural form of the resource type is expected.
Incorrect code for this rule (field is a resource)
import "google/api/resource.proto";
message LibraryBook {
option (google.api.resource) = {
type: "example.com/LibraryBook"
pattern: "libraryBooks/{libraryBook}"
singular: "libraryBook"
plural: "libraryBooks"
};
string name = 1;
}
// Incorrect.
message ListLibraryBooksResponse {
repeated LibraryBook books = 1;
string next_page_token = 2;
}
Correct code for this rule (resource type):
import "google/api/resource.proto";
message LibraryBook {
option (google.api.resource) = {
type: "example.com/LibraryBook"
pattern: "libraryBooks/{libraryBook}"
singular: "libraryBook"
plural: "libraryBooks"
};
string name = 1;
}
// Correct.
message ListLibraryBooksResponse {
repeated LibraryBook library_books = 1;
string next_page_token = 2;
}
Disabling
If you need to violate this rule, use a leading comment above the message or above the field. Remember to also include an aip.dev/not-precedent comment explaining why.
// (-- api-linter: core::0158::response-plural-first-field=disabled
// aip.dev/not-precedent: We need to do this because reasons. --)
message ListBooksResponse {
repeated Book book = 1;
string next_page_token = 2;
}
If you need to violate this rule for an entire file, place the comment at the top of the file.