github.com/googleapis/api-linter@v1.65.2/docs/rules/0216/state-field-output-only.md (about)

     1  ---
     2  rule:
     3    aip: 216
     4    name: [core, '0216', state-field-output-only]
     5    summary: Lifecycle State enum fields should be marked OUTPUT_ONLY
     6  permalink: /216/state-field-output-only
     7  redirect_from:
     8    - /0216/state-field-output-only
     9  ---
    10  
    11  # States
    12  
    13  This rule requires that all lifecycle state fields whose names end with `State`
    14  are marked as `OUTPUT_ONLY`, as mandated in [AIP-216][].
    15  
    16  ## Details
    17  
    18  This rule iterates over message fields that have an `enum` type, and the type
    19  name ends with `State`. Each field should have the annotation
    20  `[(google.api.field_behavior) = OUTPUT_ONLY]`.
    21  
    22  Note that the field name is ignored for the purposes of this rule.
    23  
    24  ## Examples
    25  
    26  **Incorrect** code for this rule:
    27  
    28  ```proto
    29  // Incorrect.
    30  enum State {  // Should be `State`.
    31    STATUS_UNSPECIFIED = 0;
    32  }
    33  
    34  State state = 1; // Should be marked OUTPUT_ONLY
    35  
    36  ```
    37  
    38  ```proto
    39  // Incorrect.
    40  enum BookState {
    41    BOOK_STATUS_UNSPECIFIED = 0;
    42    HARDCOVER = 1;
    43  }
    44  
    45  BookState state = 1; // Should be marked OUTPUT_ONLY
    46  ```
    47  
    48  **Correct** code for this rule:
    49  
    50  ```proto
    51  // Correct.
    52  enum State {
    53    STATE_UNSPECIFIED = 0;
    54  }
    55  
    56  State state = 1 [(google.api.field_behavior) = OUTPUT_ONLY];
    57  ```
    58  
    59  ## Disabling
    60  
    61  If you need to violate this rule, use a leading comment above the field
    62  Remember to also include an [aip.dev/not-precedent][] comment explaining why.
    63  
    64  ```proto
    65  enum BookState {
    66    UNSPECIFIED = 0;
    67  }
    68  
    69  // (-- api-linter: core::0216::state-field-output-only=disabled
    70  //     aip.dev/not-precedent: We need to do this because reasons. --)
    71  BookState state = 1;
    72  ```
    73  
    74  If you need to violate this rule for an entire file, place the comment at the
    75  top of the file.
    76  
    77  [aip-216]: https://aip.dev/216
    78  [aip.dev/not-precedent]: https://aip.dev/not-precedent