Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(AIP-203): require field behavior #1100

Merged
merged 13 commits into from
May 23, 2023
38 changes: 32 additions & 6 deletions aip/general/0203.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,19 @@ behavior (for example, to optimize client library signatures).

## Guidance

APIs **should** use the `google.api.field_behavior` annotation to describe
well-understood field behavior, such as a field's being required, immutable, or
output only:
APIs use the `google.api.field_behavior` annotation to describe well-understood
field behavior, such as a field's being required or immutable.
toumorokoshi marked this conversation as resolved.
Show resolved Hide resolved

```proto
// The audio data to be recognized.
RecognitionAudio audio = 2 [(google.api.field_behavior) = REQUIRED];
```

Additionally, APIs **may** use the `OPTIONAL` value to describe none of the
above. However, it is never mandatory to explicitly describe a field as
optional.
APIs **must** use the `google.api.field_behavior` annotation on every message
field and have one of [`REQUIRED`][], [`OPTIONAL`][], or [`OUTPUT_ONLY`][].

Fields with no annotation are interpreted as `OPTIONAL` for
backwards-compatility, but this annotation **must not** be omitted.
toumorokoshi marked this conversation as resolved.
Show resolved Hide resolved

**Note:** The vocabulary given in this document is for _descriptive_ purposes
only, and does not itself add any validation. The purpose is to consistently
Expand Down Expand Up @@ -162,11 +163,36 @@ the user's behalf.
A resource with an unordered list **may** return the list in a stable order, or
**may** return the list in a randomized, unstable order.

## Rationale

### Requiring field behavior

The field behavior annotation explicitly states the intended behavior of the
resource which enables better documentation. In addition, requiring the
toumorokoshi marked this conversation as resolved.
Show resolved Hide resolved
annotation forces the API author to explicitly consider the behavior during
toumorokoshi marked this conversation as resolved.
Show resolved Hide resolved
authoring of the API.

Modifying field behavior after initial authoring results in
toumorokoshi marked this conversation as resolved.
Show resolved Hide resolved
backwards-incompatible changes in clients. For example, making an optional field
required results in backwards-incompatible changes in the method signature of
toumorokoshi marked this conversation as resolved.
Show resolved Hide resolved
an RPC, or the require property for an [IaC][] client.
toumorokoshi marked this conversation as resolved.
Show resolved Hide resolved
toumorokoshi marked this conversation as resolved.
Show resolved Hide resolved

## History

In 2023-05, field behavior was made mandatory due to required and immutable
toumorokoshi marked this conversation as resolved.
Show resolved Hide resolved
field behavior annotations being missed often, resulting in poor quality
clients that had to deal with backward-incompatible changes.

The cost of clients and API users addressing breaking changes outweighed the
cost of a one-line annotation per field during API authoring.
toumorokoshi marked this conversation as resolved.
Show resolved Hide resolved

[aip-133]: ./0133.md
[aip-134]: ./0134.md
[IaC]: ./0009.md#iac

## Changelog

- **2023-05-10**: Added guidance to require the annotation.
- **2020-12-15**: Added guidance for `UNORDERED_LIST`.
- **2020-05-27**: Clarify behavior when receiving an immutable field in an
update.
Expand Down