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

     1  ---
     2  rule:
     3    aip: 123
     4    name: [core, '0123', resource-name-field]
     5    summary: Resource messages should have a `string name` field.
     6  permalink: /123/resource-name-field
     7  redirect_from:
     8    - /0123/resource-name-field
     9  ---
    10  
    11  # Resource `name` field
    12  
    13  This rule enforces that messages that appear to represent resources have a
    14  `string name` field, as described in [AIP-123][].
    15  
    16  ## Details
    17  
    18  This rule scans all messages that have a `google.api.resource` annotation, and
    19  complains if the `name` field is missing or if it is any type other than
    20  singular `string`.
    21  
    22  ## Examples
    23  
    24  **Incorrect** code for this rule:
    25  
    26  ```proto
    27  // Incorrect: missing `string name` field.
    28  message Book {
    29    option (google.api.resource) = {
    30      type: "library.googleapis.com/Book"
    31      pattern: "publishers/{publisher}/books/{book}"
    32    };
    33  }
    34  ```
    35  
    36  ```proto
    37  // Incorrect.
    38  message Book {
    39    option (google.api.resource) = {
    40      type: "library.googleapis.com/Book"
    41      pattern: "publishers/{publisher}/books/{book}"
    42    };
    43  
    44    // Should be `string`, not `bytes`.
    45    bytes name = 1;
    46  }
    47  ```
    48  
    49  **Correct** code for this rule:
    50  
    51  ```proto
    52  // Correct.
    53  message Book {
    54    option (google.api.resource) = {
    55      type: "library.googleapis.com/Book"
    56      pattern: "publishers/{publisher}/books/{book}"
    57    };
    58  
    59    string name = 1;
    60  }
    61  ```
    62  
    63  ## Disabling
    64  
    65  If you need to violate this rule, use a leading comment above the message, or
    66  above the field if it is the wrong type.
    67  
    68  ```proto
    69  // (-- api-linter: core::0123::resource-name-field=disabled
    70  //     aip.dev/not-precedent: We need to do this because reasons. --)
    71  message Book {
    72    option (google.api.resource) = {
    73      type: "library.googleapis.com/Book"
    74      pattern: "publishers/{publisher}/books/{book}"
    75    };
    76  }
    77  ```
    78  
    79  If you need to violate this rule for an entire file, place the comment at the
    80  top of the file.
    81  
    82  [aip-123]: http://aip.dev/123
    83  [aip.dev/not-precedent]: https://aip.dev/not-precedent