github.com/googleapis/api-linter@v1.65.2/docs/rules/0131/request-required-fields.md (about) 1 --- 2 rule: 3 aip: 131 4 name: [core, '0131', request-required-fields] 5 summary: Get RPCs must not have unexpected required fields in the request. 6 permalink: /131/request-required-fields 7 redirect_from: 8 - /0131/request-required-fields 9 --- 10 11 # Get methods: Required fields 12 13 This rule enforces that all `Get` standard methods do not have unexpected 14 required fields, as mandated in [AIP-131][]. 15 16 ## Details 17 18 This rule looks at any message matching `Get*Request` and complains if it 19 comes across any required fields other than: 20 21 - `string name` ([AIP-131][]) 22 23 ## Examples 24 25 **Incorrect** code for this rule: 26 27 ```proto 28 // Incorrect. 29 message GetBookRequest { 30 // The name of the book to retrieve. 31 // Format: publishers/{publisher}/books/{book} 32 string name = 1 [ 33 (google.api.field_behavior) = REQUIRED, 34 (google.api.resource_reference) = { 35 type: "library.googleapis.com/Book" 36 }]; 37 38 // Non-standard required field. 39 google.protobuf.FieldMask read_mask = 2 [(google.api.field_behavior) = REQUIRED]; 40 } 41 ``` 42 43 **Correct** code for this rule: 44 45 ```proto 46 // Correct. 47 message GetBookRequest { 48 // The name of the book to retrieve. 49 // Format: publishers/{publisher}/books/{book} 50 string name = 1 [ 51 (google.api.field_behavior) = REQUIRED, 52 (google.api.resource_reference) = { 53 type: "library.googleapis.com/Book" 54 }]; 55 56 google.protobuf.FieldMask read_mask = 2 [(google.api.field_behavior) = OPTIONAL]; 57 } 58 ``` 59 60 ## Disabling 61 62 If you need to violate this rule, use a leading comment above the field. 63 Remember to also include an [aip.dev/not-precedent][] comment explaining why. 64 65 ```proto 66 message GetBookRequest { 67 // The name of the book to retrieve. 68 // Format: publishers/{publisher}/books/{book} 69 string name = 1 [ 70 (google.api.field_behavior) = REQUIRED, 71 (google.api.resource_reference) = { 72 type: "library.googleapis.com/Book" 73 }]; 74 75 // (-- api-linter: core::0131::request-required-fields=disabled 76 // aip.dev/not-precedent: We really need this field to be required because 77 // reasons. --) 78 google.protobuf.FieldMask read_mask = 2 [(google.api.field_behavior) = REQUIRED]; 79 } 80 ``` 81 82 If you need to violate this rule for an entire file, place the comment at the 83 top of the file. 84 85 [aip-131]: https://aip.dev/131 86 [aip.dev/not-precedent]: https://aip.dev/not-precedent