@@ -16,22 +16,29 @@ behavior (for example, to optimize client library signatures).
1616
1717## Guidance
1818
19- APIs ** should** use the ` google.api.field_behavior ` annotation to describe
20- well-understood field behavior, such as a field's being required, immutable, or
21- output only:
19+ APIs use the ` google.api.field_behavior ` annotation to describe well-understood
20+ field behavior, such as a field being required or immutable.
2221
2322``` proto
2423// The audio data to be recognized.
2524RecognitionAudio audio = 2 [(google.api.field_behavior) = REQUIRED];
2625```
2726
28- Additionally, APIs ** may** use the ` OPTIONAL ` value to describe none of the
29- above. However, it is never mandatory to explicitly describe a field as
30- optional.
27+ - APIs ** must** apply the ` google.api.field_behavior ` annotation on every field.
28+ - The annotation ** must** include any [ google.api.FieldBehavior] [ ] values that
29+ accurately describe the behavior of the field.
30+ - ` FIELD_BEHAVIOR_UNSPECIFIED ` ** must not** be used.
31+
32+ ** Warning:** Although ` field_behavior ` does not impact proto-level behavior,
33+ many clients (e.g. CLIs and SDKs) rely on them to generate code. Thoroughly
34+ review and consider which values are relevant when adding a new field.
35+
36+ Fields with no annotation are interpreted as ` OPTIONAL ` for
37+ backwards-compatility. Nontheless, this annotation ** must not** be omitted.
3138
3239** Note:** The vocabulary given in this document is for _ descriptive_ purposes
3340only, and does not itself add any validation. The purpose is to consistently
34- document this behavior for users .
41+ document this behavior for clients .
3542
3643## Vocabulary
3744
@@ -162,11 +169,41 @@ the user's behalf.
162169A resource with an unordered list ** may** return the list in a stable order, or
163170** may** return the list in a randomized, unstable order.
164171
172+ ## Rationale
173+
174+ ### Requiring field behavior
175+
176+ By including the field behavior annotation for each field, the overall behavior
177+ that the resource exhibits is more clearly defined. Clearly defined field
178+ behavior improves programmatic clients and user understanding.
179+
180+ Requiring the annotation also forces the API author to explicitly consider the
181+ behavior when initially authoring of the API.
182+
183+ Modifying field behavior after initial authoring results in
184+ backwards-incompatible changes in clients. For example, making an optional field
185+ required, results in backwards-incompatible changes in the method signature of
186+ an RPC or a resource in an [ IaC] [ ] client.
187+
188+ ## History
189+
190+ In 2023-05 field_behavior was made mandatory. Prior to this change, the
191+ annotation was often omitted. Its values, e.g. REQUIRED, OUTPUT_ONLY, and
192+ IMMUTABLE, are relied upon to produce high quality clients. Further, when the
193+ value is added after the fact or changes, within a major version, it is
194+ backwards-incompatible, which is likely to break clients.
195+
196+ The benefits of requiring field_behavior, at the time that the API is authored,
197+ surpass the costs to clients and API users of not doing so.
198+
165199[ aip-133 ] : ./0133.md
166200[ aip-134 ] : ./0134.md
201+ [ google.api.FieldBehavior ] : https://github.com/googleapis/googleapis/blob/master/google/api/field_behavior.proto#L49
202+ [ IaC ] : ./0009.md#iac
167203
168204## Changelog
169205
206+ - ** 2023-05-10** : Added guidance to require the annotation.
170207- ** 2020-12-15** : Added guidance for ` UNORDERED_LIST ` .
171208- ** 2020-05-27** : Clarify behavior when receiving an immutable field in an
172209 update.
0 commit comments