Hi!
I'm one of the maintainers of the grpc-gateway
<https://github.com/grpc-ecosystem/grpc-gateway>, a popular third-party
generator for Protobuf. As part of our runtime implementation, we have an
automatic JSON-body-to-fieldmask-generator
<https://github.com/grpc-ecosystem/grpc-gateway/blob/68878db0032aae8413e99ba833fcaa8568a28182/runtime/fieldmask.go#L23>.
It was written before the availability of the official Go WKT helpers
<https://pkg.go.dev/google.golang.org/[email protected]/types/known/fieldmaskpb>
for the google.protobuf.FieldMask message type, and so has a custom idea of
what constitutes a valid field mask path, based on the input JSON
structure. In a recent contribution
<https://github.com/grpc-ecosystem/grpc-gateway/pull/1595>, we added
support for creating a field mask from the dynamic struct.proto types. For
example:
Given a field named struct_field with a type google.protobuf.Struct and the
incoming JSON:
{"struct_field": {"name":{"first": "bob"}, "amount": 2}}
We create the FieldMask with paths:
["struct_field.name.first", "struct_field.amount"]
This is apparently not considered a valid field mask path according to the
spec in field_mask.proto
<https://github.com/protocolbuffers/protobuf/blob/de5d1b98c27428450b9a38ab5c2de479f59025af/src/google/protobuf/field_mask.proto#L43-L241>
.
My proposal is to extend what is considered a valid FieldMask to include
this special case for the struct.proto types google.protobuf.Struct and
google.protobuf.Value *only*.
My rationale for this is that special casing well known types is a widely
practiced in the Protobuf community, and I think this field mask
representation of these types will make sense to users of these types,
since they're for use with fundamentally dynamic data.
For example, in JavaScript the google.protobuf.Struct type is represented
by an Object, for which such a field mask would make sense. For other
languages that don't have a special in-language representation for these
types, field masks are generally useless already since they can't currently
be used to reference anything consistently, because of the discrepancy of
the implementation with other languages. We could generalise the meaning of
a field mask for these types to be that which makes sense for the *intent*
of these types.
I originally raised this idea with the Go protobuf maintainers
<https://github.com/golang/protobuf/issues/1227> but it was agreed that it
requires a wider discussion.
Thanks for reading,
Johan Brandhorst
--
You received this message because you are subscribed to the Google Groups
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/protobuf/380bae2f-d41b-4545-a1f7-57eb89a7962fn%40googlegroups.com.