github.com/googleapis/api-linter@v1.65.2/docs/rules/0233/resource-reference-type.md (about) 1 --- 2 rule: 3 aip: 233 4 name: [core, '0233', resource-reference-type] 5 summary: BatchCreate should use a `child_type` reference to the created resource. 6 permalink: /233/resource-reference-type 7 redirect_from: 8 - /0233/resource-reference-type 9 --- 10 11 # BatchCreate methods: Parent field resource reference 12 13 This rule enforces that all `BatchCreate` standard methods with a 14 `string parent` field use a proper `google.api.resource_reference`, that being 15 either a `child_type` referring to the created resource or a `type` referring 16 directly to the parent resource, as mandated in [AIP-233][]. 17 18 ## Details 19 20 This rule looks at any message matching `BatchCreate*Request` and complains if 21 the `google.api.resource_reference` on the `parent` field refers to the wrong 22 resource. 23 24 ## Examples 25 26 **Incorrect** code for this rule: 27 28 ```proto 29 // Incorrect. 30 message BatchCreateBooksRequest { 31 // `child_type` should be used instead of `type` when referring to the 32 // created resource on a parent field. 33 string parent = 1 [(google.api.resource_reference).type = "library.googleapis.com/Book"]; 34 repeated CreateBooksRequest requests = 2 [(google.api.field_behavior) = REQUIRED]; 35 } 36 ``` 37 38 **Correct** code for this rule: 39 40 ```proto 41 // Correct. 42 message BatchCreateBooksRequest { 43 string parent = 1 [(google.api.resource_reference).child_type = "library.googleapis.com/Book"]; 44 repeated CreateBooksRequest requests = 2 [(google.api.field_behavior) = REQUIRED]; 45 } 46 ``` 47 48 ## Disabling 49 50 If you need to violate this rule, use a leading comment above the field. 51 Remember to also include an [aip.dev/not-precedent][] comment explaining why. 52 53 ```proto 54 message BatchCreateBooksRequest { 55 // (-- api-linter: core::0233::resource-reference-type=disabled 56 // aip.dev/not-precedent: We need to do this because reasons. --) 57 string parent = 1 [(google.api.resource_reference).type = "library.googleapis.com/Book"]; 58 repeated CreateBooksRequest requests = 2 [(google.api.field_behavior) = REQUIRED]; 59 } 60 ``` 61 62 If you need to violate this rule for an entire file, place the comment at the 63 top of the file. 64 65 [aip-233]: https://aip.dev/233 66 [aip.dev/not-precedent]: https://aip.dev/not-precedent