@@ -24,10 +24,12 @@ field behavior, such as a field being required or immutable.
2424RecognitionAudio audio = 2 [(google.api.field_behavior) = REQUIRED];
2525```
2626
27- - APIs ** must** apply the ` google.api.field_behavior ` annotation on every field.
27+ - APIs ** must** apply the ` google.api.field_behavior ` annotation on every field
28+ on a message or sub-message used in a request.
2829- The annotation ** must** include any [ google.api.FieldBehavior] [ ] values that
2930 accurately describe the behavior of the field.
3031 - ` FIELD_BEHAVIOR_UNSPECIFIED ` ** must not** be used.
32+ - APIs ** must** at minimum use one of ` REQUIRED ` , ` OPTIONAL ` , or ` OUTPUT_ONLY ` .
3133
3234** Warning:** Although ` field_behavior ` does not impact proto-level behavior,
3335many clients (e.g. CLIs and SDKs) rely on them to generate code. Thoroughly
@@ -79,6 +81,14 @@ integers, or the unspecified value for enums) are indistinguishable from unset
7981values, and therefore setting a required field to a falsy value yields an
8082error. A corollary to this is that a required boolean must be set to ` true ` .
8183
84+ ### Optional
85+
86+ The use of ` OPTIONAL ` indicates that a field is not required.
87+
88+ A field ** may** be described as optional if it is a field on a request message
89+ (a message that is an argument to an RPC, usually ending in ` Request ` ), or a
90+ field on a submessage.
91+
8292### Output only
8393
8494The use of ` OUTPUT_ONLY ` indicates that the field is provided in responses, but
@@ -122,13 +132,9 @@ before use.
122132
123133### Immutable
124134
125- The use of ` IMMUTABLE ` indicates that a field may be set once in a request to
126- create a resource but may not be changed thereafter.
127-
128- Additionally, a field ** should** only be described as immutable if it is a
129- field on a request message (a message that is an argument to an RPC, usually
130- ending in ` Request ` ), or a field of a message included within a request
131- message.
135+ The use of ` IMMUTABLE ` indicates that a field on a resource cannot be changed
136+ after it's creation. This can apply to either fields that are input or outputs,
137+ required or optional.
132138
133139When a service receives an immutable field in an update request (or similar),
134140even if included in the update mask, the service ** should** ignore the field if
@@ -142,20 +148,6 @@ Potential use cases for immutable fields (this is not an exhaustive list) are:
142148** Note:** Fields which are "conditionally immutable" ** must not** be given the
143149immutable annotation.
144150
145- ### Optional
146-
147- The use of ` OPTIONAL ` indicates that a field is not required, nor covered by
148- any of the above descriptions.
149-
150- A field ** may** be described as optional if none of the above vocabulary
151- applies, and it is a field on a request message (a message that is an argument
152- to an RPC, usually ending in ` Request ` ), or a field on a submessage, but it is
153- not mandatory to describe optional fields in this way.
154-
155- If you do choose to explicitly describe a field as optional, ensure that every
156- optional field on the message has this indicator. Within a single message,
157- either all optional fields should be indicated, or none of them should be.
158-
159151### Unordered List
160152
161153The use of ` UNORDERED_LIST ` on a repeated field of a resource indicates that
@@ -171,6 +163,15 @@ A resource with an unordered list **may** return the list in a stable order, or
171163
172164## Rationale
173165
166+ ### Required set of annotations
167+
168+ A field used in a request message must be either an input or an output.
169+
170+ In the case of an output, the ` OUTPUT_ONLY ` annotation is sufficient.
171+
172+ In the case of an input, a field is either required or optional, and therefore
173+ should have at least the ` REQUIRED ` or ` OPTIONAL ` annotation, respectively.
174+
174175### Requiring field behavior
175176
176177By including the field behavior annotation for each field, the overall behavior
@@ -203,6 +204,7 @@ surpass the costs to clients and API users of not doing so.
203204
204205## Changelog
205206
207+ - ** 2023-05-24** : Clarify that ` IMMUTABLE ` does not imply input nor required.
206208- ** 2023-05-10** : Added guidance to require the annotation.
207209- ** 2020-12-15** : Added guidance for ` UNORDERED_LIST ` .
208210- ** 2020-05-27** : Clarify behavior when receiving an immutable field in an
0 commit comments