Closed marcoshuck closed 4 months ago
@mennanov any chances you can take a look at this?
I'll take a look within the next few days
I wrote a similar test that passes:
func TestTitleBug(t *testing.T) {
mask := &fieldmaskpb.FieldMask{Paths: []string{"title"}}
mask.Normalize()
task := &testproto.Task{
Title: "test",
}
require.True(t, mask.IsValid(task))
protoMask, err := fieldmask_utils.MaskFromProtoFieldMask(mask, func(s string) string { return generator.CamelCase(s) })
require.Nil(t, err)
m := make(map[string]any)
err = fieldmask_utils.StructToMap(protoMask, task, m)
require.Nil(t, err)
assert.Equal(t, map[string]any{"Title": "test"}, m)
}
Try using generator.CamelCase(s)
which converts a lower case field name (in the field mask) into a camel case (golang struct naming).
Thanks for the information, will give it a try! We should probably add this test case as it would help future devs that find this issue.
I can take care of creating a PR for this test and adding some docs about the generator
package (which I was completely unaware of).
A PR is welcomed!
Resolved in PR #42
Context
I'm trying to convert a proto message to map using this library in order to perform a
PATCH
update in an endpoint. I'm getting an empty map instead of a single field map with the respective value.Relevant code
Current behavior
m
is emptyExpected behavior
Reference
Protobuf messages: https://github.com/marcoshuck/todo/blob/main/api/tasks/v1/tasks.proto#L60