github.com/googleapis/api-linter@v1.65.2/docs/rules/0123/resource-name-components-alternate.md (about) 1 --- 2 rule: 3 aip: 123 4 name: [core, '0123', resource-name-components-alternate] 5 summary: | 6 Resource name components should alternate between collection and 7 identifiers. 8 permalink: /123/resource-name-components-alternate 9 redirect_from: 10 - /0123/resource-name-components-alternate 11 --- 12 13 # Resource name components alternate 14 15 This rule enforces that messages that have a `google.api.resource` annotation 16 have `pattern` annotations that alternate between collection and identifier, as 17 described in [AIP-123][]. 18 19 ## Details 20 21 This rule scans messages with a `google.api.resource` annotation, and validates 22 that each `pattern` alternated between collection and identifiers. 23 24 ## Examples 25 26 **Incorrect** code for this rule: 27 28 ```proto 29 // Incorrect. 30 message Book { 31 option (google.api.resource) = { 32 type: "library.googleapis.com/Book" 33 // two collections next to each other. 34 pattern: "publishers/books/{book}" 35 }; 36 string name = 1; 37 } 38 ``` 39 40 **Correct** code for this rule: 41 42 ```proto 43 // Correct. 44 message Book { 45 option (google.api.resource) = { 46 type: "library.googleapis.com/Book" 47 pattern: "publishers/{publisher}/books/{book}" 48 }; 49 string name = 1; 50 } 51 ``` 52 53 ## Disabling 54 55 If you need to violate this rule, use a leading comment above the message. 56 57 ```proto 58 // (-- api-linter: core::0123::resource-name-components-alternate=disabled 59 // aip.dev/not-precedent: We need to do this because reasons. --) 60 message Book { 61 option (google.api.resource) = { 62 type: "library.googleapis.com/Book" 63 pattern: "publishers/books/{book}" 64 }; 65 string name = 1; 66 } 67 ``` 68 69 If you need to violate this rule for an entire file, place the comment at the 70 top of the file. 71 72 [aip-123]: http://aip.dev/123 73 [aip.dev/not-precedent]: https://aip.dev/not-precedent