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

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