github.com/googleapis/api-linter@v1.65.2/docs/rules/0122/resource-id-output-only.md (about)

     1  ---
     2  rule:
     3    aip: 122
     4    name: [core, '0122', resource-id-output-only]
     5    summary: Resource ID fields must be classified as `OUTPUT_ONLY`.
     6  permalink: /122/resource-id-output-only
     7  redirect_from:
     8    - /0122/resource-id-output-only
     9  ---
    10  
    11  # Output Only Resource ID fields
    12  
    13  This rule enforces that resource ID fields are classified as `OUTPUT_ONLY`, as
    14  mandated in [AIP-122][].
    15  
    16  ## Details
    17  
    18  This rule scans all resource fields and complains if it sees an ID field, named
    19  as `uid` or with the `_id` suffix, that is not classified as `OUTPUT_ONLY`.
    20  
    21  ## Examples
    22  
    23  **Incorrect** code for this rule:
    24  
    25  ```proto
    26  // Incorrect.
    27  message Book {
    28    option (google.api.resource) = {
    29      type: "library.googleapis.com/Book"
    30      pattern: "books/{book}"
    31    };
    32    string name = 1;
    33    // Should have `(google.api.field_behavior) = OUTPUT_ONLY`.
    34    string book_id = 2;
    35    // Should have `(google.api.field_behavior) = OUTPUT_ONLY`.
    36    string uid = 3;
    37  }
    38  ```
    39  
    40  **Correct** code for this rule:
    41  
    42  ```proto
    43  // Correct.
    44  message Book {
    45    option (google.api.resource) = {
    46      type: "library.googleapis.com/Book"
    47      pattern: "books/{book}"
    48    };
    49    string name = 1;
    50    string book_id = 2 [(google.api.field_behavior) = OUTPUT_ONLY];
    51    string uid = 3 [(google.api.field_behavior) = OUTPUT_ONLY];
    52  }
    53  ```
    54  
    55  ## Disabling
    56  
    57  If you need to violate this rule, use a leading comment above the field.
    58  
    59  ```proto
    60  message Book {
    61    option (google.api.resource) = {
    62      type: "library.googleapis.com/Book"
    63      pattern: "books/{book}"
    64    };
    65    string name = 1;
    66    // (-- api-linter: core::0122::resource-id-output-only=disabled
    67    //     aip.dev/not-precedent: We need to do this because reasons. --)
    68    string book_id = 2;
    69    // (-- api-linter: core::0122::resource-id-output-only=disabled
    70    //     aip.dev/not-precedent: We need to do this because reasons. --)
    71    string uid = 3;
    72  }
    73  ```
    74  
    75  If you need to violate this rule for an entire file, place the comment at the
    76  top of the file.
    77  
    78  [aip-122]: http://aip.dev/122
    79  [aip.dev/not-precedent]: https://aip.dev/not-precedent