github.com/googleapis/api-linter@v1.65.2/docs/rules/0123/name-never-optional.md (about)

     1  ---
     2  rule:
     3    aip: 123
     4    name: [core, '0123', name-never-optional]
     5    summary: Resource name fields must never be labeled with proto3_optional.
     6  permalink: /123/name-never-optional
     7  redirect_from:
     8    - /0123/name-never-optional
     9  ---
    10  
    11  # Resource name field never optional
    12  
    13  This rule enforces that the name field of a resource message is not labeled with
    14  proto3_optional.
    15  
    16  ## Details
    17  
    18  This rule scans for messages with a `google.api.resource` annotation and ensures
    19  that the configured name field (either `name` or whichever field specified via
    20  `name_field`) is not labeled as `optional`.
    21  
    22  ## Examples
    23  
    24  **Incorrect** code for this rule:
    25  
    26  ```proto
    27  // Incorrect.
    28  message Book {
    29    option (google.api.resource) = {
    30      type: "library.googleapis.com/Book"
    31      pattern: "publishers/{publisher}/books/{book}"
    32    };
    33  
    34    // The name field should not be labeled as optional.
    35    optional string name = 1;
    36  }
    37  ```
    38  
    39  **Correct** code for this rule:
    40  
    41  ```proto
    42  // Correct.
    43  message Book {
    44    option (google.api.resource) = {
    45      type: "library.googleapis.com/Book"
    46      pattern: "publishers/{publisher}/books/{book}"
    47    };
    48  
    49    string name = 1;
    50  }
    51  ```
    52  
    53  ## Disabling
    54  
    55  If you need to violate this rule, use a leading comment above the message.
    56  
    57  ```proto
    58  // (-- api-linter: core::0123::name-never-optional=disabled
    59  //     aip.dev/not-precedent: We need to do this because reasons. --)
    60  message Book {
    61    option (google.api.resource) = {
    62      type: "library.googleapis.com/Book"
    63      pattern: "publishers/{publisher}/books/{book}"
    64    };
    65  
    66    optional string name = 1;
    67  }
    68  ```
    69  
    70  If you need to violate this rule for an entire file, place the comment at the
    71  top of the file.
    72  
    73  [aip.dev/not-precedent]: https://aip.dev/not-precedent