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

     1  ---
     2  rule:
     3    aip: 123
     4    name: [core, '0123', duplicate-resource]
     5    summary: Resource types should not be defined more than once.
     6  permalink: /123/duplicate-resource
     7  redirect_from:
     8    - /0123/duplicate-resource
     9  ---
    10  
    11  # Resource annotation presence
    12  
    13  This rule enforces that the same resource type doesn't appear in more than one
    14  `google.api.resource` annotation, as described in [AIP-123][].
    15  
    16  ## Details
    17  
    18  This rule complains about messages that have the same `type` for the
    19  `google.api.resource` annotation, which frequently occur due to copy-paste
    20  errors and messages spread across multiple files and/or packages. Duplicate
    21  resource definitions can cause compilation problems in generated client code.
    22  
    23  ## Examples
    24  
    25  **Incorrect** code for this rule:
    26  
    27  ```proto
    28  message Book {
    29    option (google.api.resource) = {
    30      type: "library.googleapis.com/Book"
    31      pattern: "publishers/{publisher}/books/{book}"
    32    };
    33  
    34    string name = 1;
    35  }
    36  
    37  message Author {
    38    option (google.api.resource) = {
    39      // Incorrect: should be "library.googleapis.com/Author".
    40      type: "library.googleapis.com/Book"
    41      pattern: "authors/{author}"
    42    };
    43  
    44    string name = 1;
    45  }
    46  ```
    47  
    48  **Correct** code for this rule:
    49  
    50  ```proto
    51  // Correct.
    52  message Book {
    53    option (google.api.resource) = {
    54      type: "library.googleapis.com/Book"
    55      pattern: "publishers/{publisher}/books/{book}"
    56    };
    57  
    58    string name = 1;
    59  }
    60  
    61  message Author {
    62    option (google.api.resource) = {
    63      type: "library.googleapis.com/Author"
    64      pattern: "authors/{author}"
    65    };
    66  
    67    string name = 1;
    68  }
    69  ```
    70  
    71  ## Disabling
    72  
    73  If you need to violate this rule, use a comment at the top of the file.
    74  Remember to also include an [aip.dev/not-precedent][] comment explaining why.
    75  
    76  ```proto
    77  // (-- api-linter: core::0123::duplicate-resource=disabled
    78  //     aip.dev/not-precedent: We need to do this because reasons. --)
    79  syntax = "proto3";
    80  
    81  message Book {
    82    option (google.api.resource) = {
    83      type: "library.googleapis.com/Book"
    84      pattern: "publishers/{publisher}/books/{book}"
    85    };
    86  
    87    string name = 1;
    88  }
    89  
    90  message Author {
    91    option (google.api.resource) = {
    92      type: "library.googleapis.com/Book"
    93      pattern: "authors/{author}"
    94    };
    95  
    96    string name = 1;
    97  }
    98  ```
    99  
   100  [aip-123]: http://aip.dev/123
   101  [aip.dev/not-precedent]: https://aip.dev/not-precedent