-
Notifications
You must be signed in to change notification settings - Fork 42
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
Set required proto fields for rules and invitations #5110
Set required proto fields for rules and invitations #5110
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like it improves the swagger output so a general 👍 , but one concern about invitations.
@@ -3170,7 +3170,9 @@ message ListRolesRequest { | |||
} | |||
|
|||
message ListRolesResponse { | |||
repeated Role roles = 1; | |||
repeated Role roles = 1 [ | |||
(google.api.field_behavior) = REQUIRED |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for approving the other PR, it turns out that REQUIRED
applies to requests, but it's not clear what it means for replies.
https://google.aip.dev/203 is probably a good reference here, despite being Google-specific. In that context, it means:
A field should only be described as required if either:
- It is a field on a resource that a user provides somewhere as input. In this case, the resource is only valid if a "truthy" value is stored.
- When creating the resource, a value must be provided for the field on the create request.
- When updating the resource, the user may omit the field provided that the field is also absent from the field mask, indicating no change to the field (otherwise it must be provided).
- It is a field on a request message (a message that is an argument to an RPC, with a name usually ending in Request). In this case, a value must be provided as part of the request, and failure to do so must cause an error (usually INVALID_ARGUMENT).
We define the term "truthy" above as follows:
- For primitives, values other than 0, 0.0, empty string/bytes, and false
- For repeated fields maps, values with at least one entry
- For messages, any message with at least one "truthy" field.
So ListRoles is probably required here (as the user themselves should have a role), but invitations would not be because the list of outstanding invitations might be zero-length.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Empty lists are tricky because some languages consider them truthy and some don't.
From a typescript perspective, an empty list is truthy and different than a nil list.
In the generated typescript type, setting a list field in a response as REQUIRED
means it's not optional, and the client can safely do things like get the length, or iterate over it.
If we didn't set the field as required the client would have to perform a null check before using the field.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, interesting! it sounds like this is a difference between swagger semantics and proto semantics. TIL!
|
||
// invitations contains outstanding role invitations which have not yet | ||
// been accepted by a user. | ||
repeated Invitation invitations = 2; | ||
repeated Invitation invitations = 2 [ | ||
(google.api.field_behavior) = REQUIRED |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above, probably not required.
Summary
Ref #4952
Change Type
Mark the type of change your PR introduces:
Testing
Outline how the changes were tested, including steps to reproduce and any relevant configurations.
Attach screenshots if helpful.
Review Checklist: