Hi!
I'm one of the maintainers of the
grpc-gateway, a popular third-party generator for Protobuf. As part of our runtime implementation, we have an automatic
JSON-body-to-fieldmask-generator. It was written before the availability of the
official Go WKT helpers 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, 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.
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 but it was agreed that it requires a wider discussion.
Thanks for reading,
Johan Brandhorst