github.com/googleapis/api-linter@v1.65.2/docs/rules/0203/resource-identifier-only.md (about) 1 --- 2 rule: 3 aip: 203 4 name: [core, '0203', resource-identifier-only] 5 summary: Only the resource's name field can have field behavior IDENTIFIER. 6 permalink: /203/resource-identifier-only 7 redirect_from: 8 - /0203/resource-identifier-only 9 --- 10 11 # Resource name: IDENTIFIER 12 13 This rule enforces that only the field representing the resource's name is 14 annotated with with `(google.api.field_behavior) = IDENTIFIER`, as mandated 15 by [AIP-203][]. 16 17 ## Details 18 19 This rule looks at every field with `(google.api.field_behavior) = IDENTIFER` 20 and complains if that field is not the resource's name field. 21 22 ## Examples 23 24 **Incorrect** code for this rule: 25 26 ```proto 27 message Book { 28 option (google.api.resource) = { 29 type: "library.googleapis.com/Book" 30 pattern: "books/{book}" 31 }; 32 string name = 1 [(google.api.field_behavior) = IDENTIFER]; 33 34 // Incorrect. Must not be assigned IDENTIFIER. 35 string description = 2 [(google.api.field_behavior) = IDENTIFER]; 36 } 37 ``` 38 39 **Correct** code for this rule: 40 41 ```proto 42 message Book { 43 option (google.api.resource) = { 44 type: "library.googleapis.com/Book" 45 pattern: "books/{book}" 46 }; 47 string name = 1 [(google.api.field_behavior) = IDENTIFIER]; 48 49 // Correct. 50 string description = 2; 51 } 52 ``` 53 54 ## Disabling 55 56 If you need to violate this rule, use a leading comment above the field. 57 Remember to also include an [aip.dev/not-precedent][] comment explaining why. 58 59 ```proto 60 message Book { 61 option (google.api.resource) = { 62 type: "library.googleapis.com/Book" 63 pattern: "books/{book}" 64 }; 65 string name = 1 [(google.api.field_behavior) = IDENTIFER]; 66 67 // (-- api-linter: core::0203::resource-identifier-only=disabled 68 // aip.dev/not-precedent: We need to do this because reasons. --) 69 string description = 2 [(google.api.field_behavior) = IDENTIFER]; 70 } 71 ``` 72 73 If you need to violate this rule for an entire file, place the comment at the 74 top of the file. 75 76 [aip-203]: https://aip.dev/203 77 [aip.dev/not-precedent]: https://aip.dev/not-precedent