@@ -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
127134For example:
128135
@@ -134,31 +141,6 @@ publishers/lacroix/books/les-miserables
134141publishers/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 ` ,
182164is 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
189168See [ 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