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

     1  ---
     2  rule:
     3    aip: 127
     4    name: [core, '0127', resource-name-extraction]
     5    summary: HTTP annotations should extract full resource names into variables.
     6  permalink: /127/resource-name-extraction
     7  redirect_from:
     8    - /0127/resource-name-extraction
     9  ---
    10  
    11  # HTTP URI case
    12  
    13  This rule enforces that HTTP annotations pull whole resource names into
    14  variables, and not just the ID components, as mandated in [AIP-127][].
    15  
    16  ## Details
    17  
    18  This rule scans all methods and complains if it finds a URI with a variable
    19  whose value is `*`.
    20  
    21  ## Examples
    22  
    23  **Incorrect** code for this rule:
    24  
    25  ```proto
    26  // Incorrect.
    27  rpc GetBook(GetBookRequest) returns (Book) {
    28    // Should be /v1/{name=publishers/*/books/*}
    29    get: "/v1/publishers/{publisher_id}/books/{book_id}"
    30  }
    31  ```
    32  
    33  ```proto
    34  // Incorrect.
    35  rpc GetBook(GetBookRequest) returns (Book) {
    36    // Should be /v1/{name=publishers/*/books/*}
    37    get: "/v1/publishers/{publisher_id=*}/books/{book_id=*}"
    38  }
    39  ```
    40  
    41  **Correct** code for this rule:
    42  
    43  ```proto
    44  // Correct.
    45  rpc GetBook(GetBookRequest) returns (Book) {
    46    option (google.api.http) = {
    47      get: "/v1/{name=publishers/*/books/*}"
    48    };
    49  }
    50  ```
    51  
    52  ## Disabling
    53  
    54  If you need to violate this rule, use a leading comment above the method.
    55  Remember to also include an [aip.dev/not-precedent][] comment explaining why.
    56  
    57  ```proto
    58  // (-- api-linter: core::0127::resource-name-extraction=disabled
    59  //     aip.dev/not-precedent: We need to do this because reasons. --)
    60  rpc GetBook(GetBookRequest) returns (Book) {
    61    get: "/v1/publishers/{publisher_id}/books/{book_id}"
    62  }
    63  ```
    64  
    65  If you need to violate this rule for an entire file, place the comment at the
    66  top of the file.
    67  
    68  [aip-127]: https://aip.dev/127
    69  [aip.dev/not-precedent]: https://aip.dev/not-precedent