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

     1  ---
     2  rule:
     3    aip: 123
     4    name: [core, '0123', resource-variables]
     5    summary: Resource patterns should use consistent variable naming.
     6  permalink: /123/resource-variables
     7  redirect_from:
     8    - /0123/resource-variables
     9  ---
    10  
    11  # Resource pattern variables
    12  
    13  This rule enforces that resource patterns use consistent variable naming
    14  conventions, as described in [AIP-123][].
    15  
    16  ## Details
    17  
    18  This rule scans all messages with `google.api.resource` annotations, and
    19  complains if variables in a `pattern` use camel case, or end in `_id`.
    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      // Should be: publishers/{publisher}/books/{book}
    31      pattern: "publishers/{publisher_id}/books/{book_id}"
    32    };
    33  
    34    string name = 1;
    35  }
    36  ```
    37  
    38  ```proto
    39  // Incorrect.
    40  message ElectronicBook {
    41    option (google.api.resource) = {
    42      type: "library.googleapis.com/ElectronicBook"
    43      // Should be: publishers/{publisher}/electronicBooks/{electronic_book}
    44      pattern: "publishers/{publisher}/electronicBooks/{electronicBook}"
    45    };
    46  
    47    string name = 1;
    48  }
    49  ```
    50  
    51  **Correct** code for this rule:
    52  
    53  ```proto
    54  // Correct.
    55  message Book {
    56    option (google.api.resource) = {
    57      type: "library.googleapis.com/Book"
    58      pattern: "publishers/{publisher}/books/{book}"
    59    };
    60  
    61    string name = 1;
    62  }
    63  ```
    64  
    65  ```proto
    66  // Correct.
    67  message ElectronicBook {
    68    option (google.api.resource) = {
    69      type: "library.googleapis.com/ElectronicBook"
    70      pattern: "publishers/{publisher}/electronicBooks/{electronic_book}"
    71    };
    72  
    73    string name = 1;
    74  }
    75  ```
    76  
    77  ## Disabling
    78  
    79  If you need to violate this rule, use a leading comment above the message.
    80  
    81  ```proto
    82  // (-- api-linter: core::0123::resource-variables=disabled
    83  //     aip.dev/not-precedent: We need to do this because reasons. --)
    84  message Book {
    85    option (google.api.resource) = {
    86      type: "library.googleapis.com/Book"
    87      pattern: "publishers/{publisher_id}/books/{book_id}"
    88    };
    89  
    90    string name = 1;
    91  }
    92  ```
    93  
    94  If you need to violate this rule for an entire file, place the comment at the
    95  top of the file.
    96  
    97  [aip-123]: http://aip.dev/123
    98  [aip.dev/not-precedent]: https://aip.dev/not-precedent