github.com/googleapis/api-linter@v1.65.2/docs/rules/0203/field-behavior-required.md (about)

     1  ---
     2  rule:
     3    aip: 203
     4    name: [core, '0203', field-behavior-required]
     5    summary: |
     6      Field behavior is required, and must have one of OUTPUT_ONLY, REQUIRED, or
     7      OPTIONAL.
     8  permalink: /203/field-behavior-required
     9  redirect_from:
    10    - /0203/field-behavior-required
    11  ---
    12  
    13  # Field Behavior Required
    14  
    15  This rule enforces that each field in a message used in a request has a
    16  `google.api.field_behavior` annotation with valid values, as mandated by
    17  [AIP-203][].
    18  
    19  ## Details
    20  
    21  This rule looks at all fields except those nested inside a OneOf and ensures
    22  they have a `google.api.field_behavior` annotation. It also verifies that they
    23  have at least one of the options `OUTPUT_ONLY`, `REQUIRED`, or `OPTIONAL`: all
    24  fields must fall into one of these categories.
    25  
    26  Although all request messages **must** be annotated, this linter only verifies
    27  messages that are in the same package as some upstream protos (e.g. common
    28  protos) may be difficult to modify.
    29  
    30  ## Examples
    31  
    32  **Incorrect** code for this rule:
    33  
    34  ```proto
    35  // Incorrect.
    36  message Book {
    37    string name = 1;
    38  
    39    // No field behavior
    40    optional string title = 2;
    41  }
    42  ```
    43  
    44  **Correct** code for this rule:
    45  
    46  ```proto
    47  // Correct.
    48  message Book {
    49    string name = 1;
    50  
    51    string title = 2 [(google.api.field_behavior) = REQUIRED];
    52  }
    53  ```
    54  
    55  ## Disabling
    56  
    57  If you need to violate this rule, use a leading comment above the field.
    58  Remember to also include an [aip.dev/not-precedent][] comment explaining why.
    59  
    60  ```proto
    61  message Book {
    62    string name = 1;
    63  
    64    // Required. The title of the book.
    65    // (-- api-linter: core::0203::field-behavior-required=disabled
    66    //     aip.dev/not-precedent: We need to do this because reasons. --)
    67    optional string title = 2;
    68  }
    69  ```
    70  
    71  If you need to violate this rule for an entire file, place the comment at the
    72  top of the file.
    73  
    74  [aip-203]: https://aip.dev/203
    75  [aip.dev/not-precedent]: https://aip.dev/not-precedent