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): clarify immutable optional, required fields #1120

Merged

Conversation

toumorokoshi
Copy link
Contributor

Previous guidance had OPTIONAL as a singular value that had to be mutually exclusive with every other annotation. This eliminates the ability to express fine-grained details like OPTIONAL + INPUT_ONLY.

In a similar vain, IMMUTABLE does not imply required, nor input.

Clarifying which annotations are required based on these update.

fixes #1119

Previous guidance had OPTIONAL as a singular value that
had to be mutually exclusive with every other annotation. This
eliminates the ability to express fine-grained details like
OPTIONAL + INPUT_ONLY.

In a similar vain, IMMUTABLE does not imply required, nor input.

Clarifying which annotations are required based on these update.
@toumorokoshi toumorokoshi requested a review from a team as a code owner May 24, 2023 17:14
aip/general/0203.md Show resolved Hide resolved
aip/general/0203.md Outdated Show resolved Hide resolved
removed missed wording on optional.
@@ -171,6 +163,15 @@ A resource with an unordered list **may** return the list in a stable order, or

## Rationale

### Required set of annotations

A field used in a request message must be either an input or an output.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section explains why some combination of annotations are required, and was trying to explain that a field is either and input or and output, and therefore a full description of the behavior should include at least one of required, optional, or output_only.

@@ -171,6 +163,15 @@ A resource with an unordered list **may** return the list in a stable order, or

## Rationale

### Required set of annotations
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this section should exist.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you clarify which section, and clarify why you think it shouldn't exist? If you're referring to the rationale section, there was several requests internally and unanimous support among the current API design team. Public discussion is at: #1058.


In the case of an output, the `OUTPUT_ONLY` annotation is sufficient.

In the case of an input, a field is either required or optional, and therefore
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We specifically didn't want to mandate OPTIONAL. (There was debate on whether to even provide it.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, and after a decent amount of discussion it was agreed that field_behavior should be required: #1100. See the rationale section for more details, but this choice has lead to a lot of incorrectly documented fields since developers did not think through the field behavior choice. field behavior is being used as forcing function.

@@ -24,10 +24,12 @@ field behavior, such as a field being required or immutable.
RecognitionAudio audio = 2 [(google.api.field_behavior) = REQUIRED];
```

- APIs **must** apply the `google.api.field_behavior` annotation on every field.
- APIs **must** apply the `google.api.field_behavior` annotation on every field
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When did this become a requirement? It shouldn't be one. Leaving off a field_behavior annotation is equivalent to specifying OPTIONAL.

Copy link
Contributor Author

@toumorokoshi toumorokoshi May 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #1100, there's a separate thread you opened we could discuss this too.

@@ -142,20 +148,6 @@ Potential use cases for immutable fields (this is not an exhaustive list) are:
**Note:** Fields which are "conditionally immutable" **must not** be given the
immutable annotation.

### Optional

The use of `OPTIONAL` indicates that a field is not required, nor covered by
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason that "not covered by any of the above descriptions" was included is because when the annotation was being debated, API producers wanted to avoid the outcome of having to specify field_behavior on every field. We almost didn't provide OPTIONAL at all, but Docgen wanted it for cases where documentation needed to call out that the field was optional (e.g. if it was counter-intuitive).

Copy link
Contributor Author

@toumorokoshi toumorokoshi May 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, that matches my understanding as well. There's been a lot of discussion internally around this and the conclusion (with ATL review) was that we should require these, as the cost to API producers is worth the benefit to clients.

@toumorokoshi
Copy link
Contributor Author

@lukesneeringer thanks! I really appreciate the time to review.

I answered your questions, so hopefully that provides context. Let me know if you have blockers. Regarding the requirement of field_behavior overall, that's a decision we made internally (that this CL is intended to publicize).

@toumorokoshi
Copy link
Contributor Author

@lukesneeringer gentle ping. Since we have agreement internally to move forward with this, and all current Googlers approve, I'm inclined to merge this.

If you think there is a strong technical reason, I'm definitely open to talking those out.

@lukesneeringer
Copy link
Contributor

@toumorokoshi Sure, that's fine. I'm not particularly concerned about whether field_behavior is mandatory since, well, I don't work at Google anymore and thus am not affected by the decision. :-)

@toumorokoshi
Copy link
Contributor Author

@toumorokoshi Sure, that's fine. I'm not particularly concerned about whether field_behavior is mandatory since, well, I don't work at Google anymore and thus am not affected by the decision. :-)

Of course, and I think despite your xoogler status, your opinion is still very valuable.

Thank you for taking our time to review! I do really appreciate it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AIP-203 IMMUTABLE + REQUIRED should be valid.
4 participants