github.com/googleapis/api-linter@v1.65.2/docs/rules/0123/resource-definition-variables.md (about) 1 --- 2 rule: 3 aip: 123 4 name: [core, '0123', resource-definition-variables] 5 summary: Resource patterns should use consistent variable naming. 6 permalink: /123/resource-definition-variables 7 redirect_from: 8 - /0123/resource-definition-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 files with `google.api.resource_definition` 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 import "google/api/resource.proto"; 27 28 // Incorrect. 29 option (google.api.resource_definition) = { 30 type: "library.googleapis.com/Book" 31 // Should be: publishers/{publisher}/books/{book} 32 pattern: "publishers/{publisher_id}/books/{book_id}" 33 }; 34 ``` 35 36 ```proto 37 import "google/api/resource.proto"; 38 39 // Incorrect. 40 option (google.api.resource_definition) = { 41 type: "library.googleapis.com/ElectronicBook" 42 // Should be: publishers/{publisher}/electronicBooks/{electronic_book} 43 pattern: "publishers/{publisher}/electronicBooks/{electronicBook}" 44 }; 45 ``` 46 47 **Correct** code for this rule: 48 49 ```proto 50 import "google/api/resource.proto"; 51 52 // Correct. 53 option (google.api.resource_definition) = { 54 type: "library.googleapis.com/Book" 55 pattern: "publishers/{publisher}/books/{book}" 56 }; 57 ``` 58 59 ```proto 60 import "google/api/resource.proto"; 61 62 // Correct. 63 option (google.api.resource_definition) = { 64 type: "library.googleapis.com/ElectronicBook" 65 pattern: "publishers/{publisher}/electronicBooks/{electronic_book}" 66 }; 67 ``` 68 69 ## Disabling 70 71 If you need to violate this rule, use a leading comment above the annotation. 72 73 ```proto 74 import "google/api/resource.proto"; 75 76 // (-- api-linter: core::0123::resource-definition-variables=disabled 77 // aip.dev/not-precedent: We need to do this because reasons. --) 78 option (google.api.resource_definition) = { 79 type: "library.googleapis.com/Book" 80 pattern: "publishers/{publisher_id}/books/{book_id}" 81 }; 82 ``` 83 84 If you need to violate this rule for an entire file, place the comment at the 85 top of the file. 86 87 [aip-123]: http://aip.dev/123 88 [aip.dev/not-precedent]: https://aip.dev/not-precedent