|
| 1 | +--- |
| 2 | +id: 4235 |
| 3 | +state: approved |
| 4 | +created: 2024-03-07 |
| 5 | +--- |
| 6 | + |
| 7 | +# Automatically populate fields in the request message |
| 8 | + |
| 9 | +For APIs that leverage request idempotency as described via [AIP-155], APIs may |
| 10 | +choose to have the client libraries automatically populate the `request_id` |
| 11 | +if it is not already set by the customer. |
| 12 | + |
| 13 | +**Note:** This feature is primarily written for `request_id` fields within the |
| 14 | +request message. Nonetheless, this feature **must** work for a field of any |
| 15 | +name, as long as the below conditions hold true. |
| 16 | + |
| 17 | +## Guidance |
| 18 | + |
| 19 | +APIs **may** configure fields in the request message for automatic population. |
| 20 | +For a field to be automatically populated, **all** the below configurations |
| 21 | +**must** be true: |
| 22 | + |
| 23 | +- The field **must** be of type `string` |
| 24 | +- The field **must** be at the top-level of the request message |
| 25 | +- The RPC **must** be a unary RPC (i.e. streaming RPCs are not supported) |
| 26 | +- The field **must not** be annotated |
| 27 | + with [`google.api.field_behavior = REQUIRED`][required]. |
| 28 | +- The field **must** be annotated |
| 29 | + with [`google.api.field_info.format = UUID4`][uuid4]. |
| 30 | +- The field name **must** be listed |
| 31 | + in the [`google.api.MethodSettings.auto_populated_fields`][apf] entry |
| 32 | + in [`google.api.Publishing.method_settings`][apf] |
| 33 | + for the target method. |
| 34 | + |
| 35 | +### Expected Generator and Client Library Behavior |
| 36 | + |
| 37 | +If the aforementioned requirements are met for a given field, client library |
| 38 | +generators **must** enable automatic population of said field in the |
| 39 | +generated client. |
| 40 | +If a field is specified in the `auto_populated_fields`, but does not meet the |
| 41 | +structural requirements, the client library generators **must not** enable |
| 42 | +automatic population for that field. Client library generators **may** emit an |
| 43 | +error during generation. |
| 44 | + |
| 45 | +Client libraries **must** reuse automatically populated values for retries of |
| 46 | +the same request i.e., the automatically populated fields **must not** be |
| 47 | +regenerated for each RPC attempt with a single request message. |
| 48 | + |
| 49 | +[AIP-155]: https://google.aip.dev/155 |
| 50 | + |
| 51 | +[apf]: https://github.com/googleapis/googleapis/blob/master/google/api/client.proto |
| 52 | + |
| 53 | +[uuid4]: https://google.aip.dev/202#uuid4 |
| 54 | + |
| 55 | +[required]: https://google.aip.dev/203#required |
0 commit comments