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

     1  ---
     2  rule:
     3    aip: 123
     4    name: [core, '0123', resource-pattern]
     5    summary: Resource annotations should define a pattern.
     6  permalink: /123/resource-pattern
     7  redirect_from:
     8    - /0123/resource-pattern
     9  ---
    10  
    11  # Resource patterns
    12  
    13  This rule enforces that messages that appear to represent resources have a
    14  `pattern` defined on their `google.api.resource` annotation, as described in
    15  [AIP-123][].
    16  
    17  ## Details
    18  
    19  This rule scans all messages with `google.api.resource` annotations, and
    20  complains if `pattern` is not provided at least once. It also complains if the
    21  segments outside of variable names contain underscores.
    22  
    23  ## Examples
    24  
    25  **Incorrect** code for this rule:
    26  
    27  ```proto
    28  // Incorrect.
    29  message Book {
    30    option (google.api.resource) = {
    31      type: "library.googleapis.com/Book"
    32      // pattern should be here
    33    };
    34  
    35    string name = 1;
    36  }
    37  ```
    38  
    39  ```proto
    40  // Incorrect.
    41  message ElectronicBook {
    42    option (google.api.resource) = {
    43      type: "library.googleapis.com/ElectronicBook"
    44      // Should be: publishers/{publisher}/electronicBooks/{electronic_book}
    45      pattern: "publishers/{publisher}/electronic_books/{electronic_book}"
    46    };
    47  
    48    string name = 1;
    49  }
    50  ```
    51  
    52  **Correct** code for this rule:
    53  
    54  ```proto
    55  // Correct.
    56  message Book {
    57    option (google.api.resource) = {
    58      type: "library.googleapis.com/Book"
    59      pattern: "publishers/{publisher}/books/{book}"
    60    };
    61  
    62    string name = 1;
    63  }
    64  ```
    65  
    66  ```proto
    67  // Correct.
    68  message ElectronicBook {
    69    option (google.api.resource) = {
    70      type: "library.googleapis.com/ElectronicBook"
    71      pattern: "publishers/{publisher}/electronicBooks/{electronic_book}"
    72    };
    73  
    74    string name = 1;
    75  }
    76  ```
    77  
    78  ## Disabling
    79  
    80  If you need to violate this rule, use a leading comment above the message.
    81  
    82  ```proto
    83  // (-- api-linter: core::0123::resource-pattern=disabled
    84  //     aip.dev/not-precedent: We need to do this because reasons. --)
    85  message Book {
    86    option (google.api.resource) = {
    87      type: "library.googleapis.com/Book"
    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