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