AIP-4235
Automatically populate fields in the request message
For APIs that leverage request idempotency as described via AIP-155, APIs may
choose to have the client libraries automatically populate fields such as
request_id
if they are not already set by the customer.
Note: This feature is primarily written for request_id
fields within the
request message. Nonetheless, this feature must work for a field of any
name, as long as the conditions below hold true.
Guidance
APIs may configure fields in the request message for automatic population. For a field to be automatically populated, all the conditions below must be true:
- The field must be of type
string
- The field must be at the top-level of the request message
- The RPC must be a unary RPC (i.e. streaming RPCs are not supported)
- The field must not be annotated
with
google.api.field_behavior = REQUIRED
. - The field must be annotated
with
google.api.field_info.format = UUID4
. - The field name must be listed
in the
google.api.MethodSettings.auto_populated_fields
entry ingoogle.api.Publishing.method_settings
for the target method.
Expected Generator and Client Library Behavior
If the aforementioned requirements are met for a given field, client library generators must enable automatic population of said field in the generated client.
The field must be automatically populated if and only if one of the following conditions holds:
- The field supports explicit presence, and has not been set by the user
- The field doesn't support explicit presence, and its value is the empty string (i.e. the default value)
If a field is specified in the auto_populated_fields
, but does not meet the
structural requirements, the client library generators must not enable
automatic population for that field. Client library generators may emit an
error during generation.
Client libraries must reuse automatically populated values for retries of the same request. In other words, the automatically populated fields must not be regenerated for each RPC attempt with the same request message.