idodod / protoc-gen-fieldmask

A protoc plugin that generates fieldmask paths
MIT License
23 stars 3 forks source link

Full path generation #13

Closed andrey308 closed 1 year ago

andrey308 commented 2 years ago

Let's add generation full path generator, which will generate path from message name to field name.

Problem: for example in one proto file can be several duplicated field names:

syntax = "proto3";

package casesa;

option go_package = "cases/a;a";

message Foo {
  string bar = 1;
  int32 baz = 2;
}

message Bar {
  string bar = 1;
}

After generation we will receive smth like this:

f := Foo{}
f.FieldMaskPaths().Bar() // will return "bar"
b := Bar{}
b.FieldMaskPaths().Bar() // will also return "bar"

It is a problem due to one proto file can be like namespace. So it can be useful to have absolute path of each field in namespace.

f := Foo{}
f.FullFieldMaskPaths().Bar() // will return "foo.bar"
b := Bar{}
b.FullFieldMaskPaths().Bar() // will return "bar.bar"
idodod commented 1 year ago

Hi @andrey308 , Full path is supported starting from the first known field name. Notice that even in your example, foo and bar are not fields name but just the lower case name so the messages. for foo or bar to be part of the fieldmask path, they need to be the name of a field in message that contains them.

For example:

message Baz {
  Foo foo = 1;
}
baz := Baz{}
baz.FieldMaskPaths().Foo().Bar() // will return "foo.bar"

I'm closing this issue for now, but feel free to respond if you still disagree.