Skip to content

Commit d97fd2e

Browse files
authored
feat(AIP-133) up resource_id guidance to should (#1019)
* feat(AIP-133) up resource_id guidance to should The current wording implies that user-settable resource_ids are somewhat helpful *may*, when in most cases they are very beneficial: they are critical for declarative clients to uniquely identify resources and prevent duplicates, and enable the user to provide semantic names and organization for resources. Generally the guidance would be better for APIs if they were added if at all possible, and only skipped if there the usage pattern is exceptional (e.g. job resources with significant churn, revisions where a unique identifier is determined by the custom method). * addressing feedback - make user-settable IDs a must. - add rationale * address feedback - removed must on resource_id in AIP-128 * more wording tweaks - clarifying and fixing user-settable ID section. * addressing feedback user-settable -> client-settable. Adding more rationale, fixing ordering so ID is required first, then the body of the resource.
1 parent 467d01f commit d97fd2e

2 files changed

Lines changed: 38 additions & 38 deletions

File tree

aip/general/0128.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,15 @@ A significant amount of guidance is more strict for declarative-friendly
101101
interfaces, due to the focus on automation on top of these resources. This list
102102
is a comprehensive reference to declarative-friendly guidance in other AIPs:
103103

104-
- Resources **must** use user-settable resource IDs: see AIP-133.
105104
- Resources **should not** employ custom methods: see AIP-136.
106105
- Resources **must** use the `Update` method for repeated fields: see AIP-144.
107106
- Resources **must** include certain standard fields: see AIP-148.
108107
- Resources **must** have an `etag` field: see AIP-154.
109108
- Resources **should** provide change validation: see AIP-163.
110109
- Resources **should not** implement soft-delete. If the id cannot be re-used,
111-
the resource **must** implement soft-delete and the undelete RPC: see AIP-164
110+
the resource **must** implement soft-delete and the undelete RPC: see AIP-164
111+
112+
## Changelog
113+
114+
- **2023-05-11**: removed must on resource_id, which was upstreamd to a general
115+
must

aip/general/0133.md

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,8 @@ rpc CreateBook(CreateBookRequest) returns (Book) {
5858
**must** map to the resource field in the request message.
5959
- All remaining fields **should** map to URI query parameters.
6060
- There **should** be exactly one `google.api.method_signature` annotation,
61-
with a value of `"parent,{resource}"` if the resource being created is not a
62-
top-level resource, or with a value of `"{resource}"` if the resource being
63-
created is a top-level resource (unless the method supports [user-specified
64-
IDs](#user-specified-ids)).
61+
with a value of `"parent,{resource},{resource}_id"`, or "`"parent,{resource}"`
62+
if the resource ID is not required.
6563

6664
### Request message
6765

@@ -77,8 +75,15 @@ message CreateBookRequest {
7775
child_type: "library.googleapis.com/Book"
7876
}];
7977
78+
// The ID to use for the book, which will become the final component of
79+
// the book's resource name.
80+
//
81+
// This value should be 4-63 characters, and valid characters
82+
// are /[a-z][0-9]-/.
83+
string book_id = 2 [(google.api.field_behavior) = REQUIRED];
84+
8085
// The book to create.
81-
Book book = 2 [(google.api.field_behavior) = REQUIRED];
86+
Book book = 3 [(google.api.field_behavior) = REQUIRED];
8287
}
8388
```
8489

@@ -87,6 +92,7 @@ message CreateBookRequest {
8792
- The field **should** be [annotated as required][aip-203].
8893
- The field **must** identify the [resource type][aip-123] of the resource
8994
being created.
95+
- A `{resource}_id` field **must** be included.
9096
- The resource field **must** be included and **must** map to the POST body.
9197
- The request message **must not** contain any other required fields and
9298
**should not** contain other optional fields except those described in this
@@ -120,9 +126,10 @@ to done if the request is effectively immediate.
120126

121127
### User-specified IDs
122128

123-
Sometimes, an API needs to allow a client to specify the ID component of a
124-
resource (the last segment of the resource name) on creation. This is common if
125-
users are allowed to choose that portion of their resource names.
129+
An API **must** allow a client to specify the ID component
130+
of a resource (the last segment of the resource name) on creation. An API
131+
**may** allow the `{resource}_id` field have the [field_behavior][] `OPTIONAL`,
132+
and generate a system-generated ID if one is not specified.
126133

127134
For example:
128135

@@ -134,31 +141,6 @@ publishers/lacroix/books/les-miserables
134141
publishers/012345678-abcd-cdef/books/12341234-5678-abcd
135142
```
136143

137-
Create RPCs **may** support this behavior by providing a `string {resource}_id`
138-
field on the request message:
139-
140-
```proto
141-
message CreateBookRequest {
142-
// The parent resource where this book will be created.
143-
// Format: publishers/{publisher}
144-
string parent = 1 [
145-
(google.api.field_behavior) = REQUIRED,
146-
(google.api.resource_reference) = {
147-
child_type: "library.googleapis.com/Book"
148-
}];
149-
150-
// The book to create.
151-
Book book = 2 [(google.api.field_behavior) = REQUIRED];
152-
153-
// The ID to use for the book, which will become the final component of
154-
// the book's resource name.
155-
//
156-
// This value should be 4-63 characters, and valid characters
157-
// are /[a-z][0-9]-/.
158-
string book_id = 3;
159-
}
160-
```
161-
162144
- The `{resource}_id` field **must** exist on the request message, not the
163145
resource itself.
164146
- The field **may** be required or optional. If it is required, it **should**
@@ -181,9 +163,6 @@ message CreateBookRequest {
181163
**Note:** For REST APIs, the user-specified ID field, `{resource}_id`,
182164
is provided as a query parameters on the request URI.
183165

184-
**Important:** Declarative-friendly resources (AIP-128) **must** support
185-
user-specified IDs.
186-
187166
### Errors
188167

189168
See [errors][], in particular [when to use PERMISSION_DENIED and
@@ -194,17 +173,34 @@ NOT_FOUND errors][permission-denied].
194173
- For ensuring idempotency in `Create` methods, see [AIP-155][].
195174
- For naming resources involving Unicode, see [AIP-210][].
196175

176+
## Rationale
177+
178+
### Requiring client-settable ids
179+
180+
[IaC][] clients use the resource ID as a way to identify a resource for applying
181+
updates and for conflict resolution. The lack of a client-settable ID means a
182+
client is unable to find the resource unless they store the identifier locally,
183+
and can result in re-creating the resource. This in turn has a downstream effect
184+
on all resources that reference it, forcing them to update to the the ID of the
185+
newly-created resource.
186+
187+
Having a client-settable ID also means the client can precalculate the resource
188+
name and use it in references from other resources.
189+
197190
[aip-121]: ./0121.md
198191
[aip-122]: ./0122.md
199192
[aip-123]: ./0123.md
200193
[aip-155]: ./0155.md
201194
[aip-203]: ./0203.md
202195
[aip-210]: ./0210.md
203196
[errors]: ./0193.md
197+
[field_behavior]: ./203.md
198+
[IaC]: ./0009.md#iac
204199
[permission-denied]: ./0193.md#permission-denied
205200

206201
## Changelog
207202

203+
- **2023-05-11**: Changing guidance around resource_id to a must.
208204
- **2022-11-04**: Referencing aggregated error guidance in AIP-193, similar to other CRUDL AIPs.
209205
- **2022-06-02**: Changed suffix descriptions to eliminate superfluous "-".
210206
- **2020-10-06**: Added declarative-friendly guidance.

0 commit comments

Comments
 (0)