Let's say I have an API to fetch a user that can take a user's id or name as an argument. My Thrift definition might look like this.
struct GetUserRequest {
1: optional string user_id;
2: optional string user_name;
}
service MyService {
GetUserResponse get_user(1: GetUserRequest request);
}
but my concern is to show that GetUserRequest can take a user_id OR a user_name, but it doesn't need both fields, but it also needs one. Is there a good way to represent this intent in Thrift?
You can use union:
union GetUserRequest {
1: string user_id
2: string user_name
}