So I'm using kratos framework with Go and my API definition is:
rpc UpdateMeeting (UpdateMeetingRequest) returns (UpdateMeetingReply) {
option (google.api.http) = {
patch: "/v1/meetings/{meeting_id}"
body: "*"
};
};
And the corresponding kratos generated func
func _Meeting_UpdateMeeting_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(UpdateMeetingRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(MeetingServer).UpdateMeeting(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Meeting_UpdateMeeting_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(MeetingServer).UpdateMeeting(ctx, req.(*UpdateMeetingRequest))
}
return interceptor(ctx, in, info, handler)
}
Now if I have the following as the message request I do not have any issues unmarshalling and the request actually lands on my UpdateMeeting method being called from Kratos generated method.
message UpdateMeetingRequest {
string meeting_id = 1;
string updated_by = 2;
MeetingMeta meeting_meta = 3;
// more fields left out
}
message MeetingMeta {
string meeting_link = 1;
// more fields left out
}
But when I add FieldMask which I actually need to check which field is present and which isn't, I get this error -
message UpdateMeetingRequest {
string meeting_id = 1;
string updated_by = 2;
MeetingMeta meeting_meta = 3;
google.protobuf.FieldMask update_mask = 4;
}
Error
{
"code": 400,
"reason": "CODEC",
"message": "body unmarshal proto: (line 5:18): google.protobuf.FieldMask.paths contains invalid path: \"meeting_meta\"",
"metadata": {}
}
Payload
{
"meeting_meta": {
"meeting_link": "ac"
},
"update_mask": "meeting_meta"
}
For the update mask tried: meeting_meta.meeting_link, meeting_meta, meeting_link all three with same or similar errors.
Edit: So with approach mentioned in the answer I was able to make it work by changing the update_mask. meeting_meta -> meetingMeta.
But running into same issue, i.e., "contains invalid path" if there are two fields in the payload with '_' in name. Example:
{
"updated_by": "dsjhvg",
"meeting_meta": {
"meeting_link": "ac"
},
"update_mask": "updatedBy, meetingMeta"
}
Individually both these fields are being unmarshalled just fine. Combined I'm running into an error for the second path in the update_mask. For this payload it's meeting_meta, if I rearrange them then its updated_by.