AEP-0158 Linter Rules
Paginated methods- Page size field
Paginated methods: Page size field
This rule enforces that all List
and Search
methods have a
int32 page_size
field in the request message, as mandated in AEP-158.
Details
This rule looks at any message matching List*Request
or Search*Request
and
complains if either the page_size
field is missing, or if it has any type
other than int32
.
Examples
Incorrect code for this rule:
// Incorrect.message ListBooksRequest { string path = 1; int32 limit = 2; // Field name should be `page_size`. string page_token = 3;}
// Incorrect.message ListBooksRequest { string parent = 1; uint32 max_page_size = 2; // Field type should be `int32`. string page_token = 3;}
Correct code for this rule:
// Correct.message ListBooksRequest { string parent = 1; int32 max_page_size = 2; string page_token = 3;}
Disabling
If you need to violate this rule, use a leading comment above the message (if
the page_size
field is missing) or above the field (if it is the wrong type).
Remember to also include an aep.dev/not-precedent comment explaining why.
// (-- api-linter: core::0158::request-page-size-field=disabled// aep.dev/not-precedent: We need to do this because reasons. --)message ListBooksRequest { string path = 1; int32 limit = 2; string page_token = 3;}
If you need to violate this rule for an entire file, place the comment at the top of the file.
Paginated methods- Page token field
Paginated methods: Page token field
This rule enforces that all List
and Search
methods have a
string page_token
field in the request message, as mandated in AEP-158.
Details
This rule looks at any message matching List*Request
or Search*Request
and
complains if either the page_token
field is missing, or if it has any type
other than string
.
Examples
Incorrect code for this rule:
// Incorrect.message ListBooksRequest { string path = 1; int32 max_page_size = 2; string offset = 3; // Field name should be `page_token`.}
// Incorrect.message ListBooksRequest { string parent = 1; int32 max_page_size = 2; bytes page_token = 3; // Field type should be `string`.}
Correct code for this rule:
// Correct.message ListBooksRequest { string parent = 1; int32 max_page_size = 2; string page_token = 3;}
Disabling
If you need to violate this rule, use a leading comment above the message (if
the page_token
field is missing) or above the field (if it is the wrong type).
Remember to also include an aep.dev/not-precedent comment explaining why.
// (-- api-linter: core::0158::request-page-token-field=disabled// aep.dev/not-precedent: We need to do this because reasons. --)message ListBooksRequest { string name = 1; int32 max_page_size = 2; string offset = 3;}
If you need to violate this rule for an entire file, place the comment at the top of the file.
Paginated methods- skip field
Paginated methods: skip field
This rule enforces that all List
and Search
request skip
fields have type int32
, as
mandated in AEP-158.
Details
This rule looks at any message matching List*Request
or Search*Request
that
contains a skip
field, and complains if the field is not a singular int32
.
Examples
Incorrect code for this rule:
message ListBooksRequest { string parent = 1 [ (google.api.resource_reference).child_type = "library.googleapis.com/Book", (google.api.field_behavior) = REQUIRED ];
int32 max_page_size = 2;
string page_token = 3;
string skip = 4; // Field type should be `int32`.}
Correct code for this rule:
message ListBooksRequest { string parent = 1 [ (google.api.resource_reference).child_type = "library.googleapis.com/Book", (google.api.field_behavior) = REQUIRED ];
int32 max_page_size = 2;
string page_token = 3;
int32 skip = 4;}
Disabling
If you need to violate this rule, use a leading comment above the field. Remember to also include an aep.dev/not-precedent comment explaining why.
message ListBooksRequest { string parent = 1 [ (google.api.resource_reference).child_type = "library.googleapis.com/Book", (google.api.field_behavior) = REQUIRED ];
int32 max_page_size = 2;
string page_token = 3;
// (-- api-linter: core::0158::request-skip-field=disabled // aep.dev/not-precedent: We need to do this because reasons. --) string skip = 4;}
If you need to violate this rule for an entire file, place the comment at the top of the file.
Paginated methods- Next page token field
Paginated methods: Next page token field
This rule enforces that all List
and Search
methods have a
string next_page_token
field in the response message, as mandated in
AEP-158.
Details
This rule looks at any message matching List*Response
or Search*Response
and complains if either the next_page_token
field is missing, or if it has
any type other than string
.
Examples
Incorrect code for this rule:
// Incorrect.message ListBooksResponse { repeated Book books = 1; string next_page = 2; // Field name should be `next_page_token`.}
// Incorrect.message ListBooksResponse { repeated Book books = 1; bytes next_page_token = 2; // Field type should be `string`.}
Correct code for this rule:
// Correct.message ListBooksResponse { repeated Book books = 1; string next_page_token = 2;}
Disabling
If you need to violate this rule, use a leading comment above the message (if
the next_page_token
field is missing) or above the field (if it is the wrong type).
Remember to also include an aep.dev/not-precedent comment explaining why.
// (-- api-linter: core::0158::response-next-page-token-field=disabled// aep.dev/not-precedent: We need to do this because reasons. --)message ListBooksResponse { repeated Book books = 1; string next_page = 2;}
If you need to violate this rule for an entire file, place the comment at the top of the file.
Paginated methods- Page token field
Paginated methods: Page token field
This rule enforces that all List
and Search
methods have a repeatable field
in the response message, as mandated in AEP-158.
Details
This rule looks at any message matching List*Response
or Search*Response
that has next_page_token
field and complains if there does not exist a field that is repeated.
Examples
Incorrect code for this rule:
// Incorrect.message ListBooksResponse { Book books = 1; // Field should be repeated. string next_page_token = 2;}
Correct code for this rule:
// Correct.message ListBooksResponse { repeated Book 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 aep.dev/not-precedent comment explaining why.
// (-- api-linter: core::0158::response-repeated-first-field=disabled// aep.dev/not-precedent: We need to do this because reasons. --)message ListBooksResponse { Book books = 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.
Paginated methods- Unary responses
Paginated methods: Unary responses
This rule enforces that all paginated methods (List
and Search
methods, or
methods with pagination fields) use unary responses, as mandated in
AEP-158.
Details
This rule looks at any message matching List*Response
or Search*Response
,
or any response message that has next_page_token
field, and complains if the
method uses gRPC server streaming (the stream
keyword).
Examples
Incorrect code for this rule:
// Incorrect.// Streaming is prohibited on paginated responses.rpc ListBooks(ListBooksRequest) returns (stream ListBooksResponse) { option (google.api.http) = { get: "/v1/{parent=publishers/*}/books" };}
Correct code for this rule:
// 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 message or above the field. Remember to also include an aep.dev/not-precedent comment explaining why.
// (-- api-linter: core::0158::response-unary// aep.dev/not-precedent: We need to do this because reasons. --)rpc ListBooks(ListBooksRequest) returns (stream ListBooksResponse) { option (google.api.http) = { get: "/v1/{parent=publishers/*}/books" };}
If you need to violate this rule for an entire file, place the comment at the top of the file.