github.com/googleapis/api-linter@v1.65.2/docs/rules/0231/request-names-field.md (about)

     1  ---
     2  rule:
     3    aip: 231
     4    name: [core, '0231', request-names-field]
     5    summary: Batch Get RPCs should have a `names` field in the request.
     6  permalink: /231/request-names-field
     7  redirect_from:
     8    - /0231/request-names-field
     9  ---
    10  
    11  # Batch Get methods: Names field
    12  
    13  This rule enforces that all `BatchGet` methods have a `repeated string names`
    14  field in the request message, as mandated in [AIP-231][].
    15  
    16  ## Details
    17  
    18  This rule looks at any message matching `BatchGet*Request` and complains if
    19  either the `names` field is missing, if it has any type other than `string`, or
    20  if it is not `repeated`.
    21  
    22  Alternatively, if there is a `repeated GetBookRequest requests` field, this is
    23  accepted in its place.
    24  
    25  ## Examples
    26  
    27  **Incorrect** code for this rule:
    28  
    29  ```proto
    30  // Incorrect.
    31  message BatchGetBooksRequest {
    32    string parent = 1 [
    33      (google.api.resource_reference).child_type = "library.googleapis.com/Book"
    34    ];
    35  
    36    repeated string books = 2;  // Field name should be `names`.
    37  }
    38  ```
    39  
    40  ```proto
    41  // Incorrect.
    42  message BatchGetBooksRequest {
    43    string parent = 1 [
    44      (google.api.resource_reference).child_type = "library.googleapis.com/Book"
    45    ];
    46  
    47    string names = 2;  // Field should be repeated.
    48  }
    49  ```
    50  
    51  **Correct** code for this rule:
    52  
    53  ```proto
    54  // Correct.
    55  message BatchGetBooksRequest {
    56    string parent = 1 [
    57      (google.api.resource_reference).child_type = "library.googleapis.com/Book"
    58    ];
    59  
    60    repeated string names = 2 [
    61      (google.api.field_behavior) = REQUIRED,
    62      (google.api.resource_reference).type = "library.googleapis.com/Book"
    63    ];
    64  }
    65  ```
    66  
    67  ## Disabling
    68  
    69  If you need to violate this rule, use a leading comment above the message (if
    70  the `names` field is missing) or above the field (if it is the wrong type).
    71  Remember to also include an [aip.dev/not-precedent][] comment explaining why.
    72  
    73  ```proto
    74  // (-- api-linter: core::0231::request-names-field=disabled
    75  //     aip.dev/not-precedent: We need to do this because reasons. --)
    76  message BatchGetBooksRequest {
    77    string parent = 1;
    78    repeated string books = 2;
    79  }
    80  ```
    81  
    82  If you need to violate this rule for an entire file, place the comment at the
    83  top of the file.
    84  
    85  [aip-231]: https://aip.dev/231
    86  [aip.dev/not-precedent]: https://aip.dev/not-precedent