goverter icon indicating copy to clipboard operation
goverter copied to clipboard

interface level option inheritance

Open kamiLez opened this issue 3 years ago • 1 comments

Let's consider example based on code generated by grpc that adds 3 additional fields state, sizeCache and unknownFields to every generated structure. In case when I've defined interface that will translate multiple structures I have to repeat myself on every structure to ignore those fields and additionally matchIgnoreCase. It would be cool to be able to define ignore and matchIgnoreCase at the level of interface so that every method has them in common defined.

Instead of:

type Transformer interface {
 //goverter:matchIgnoreCase
 //goverter:ignore state
 //goverter:ignore sizeCache
 //goverter:ignore unknownFields
 Value(in.Struct1) out.Struct1
 //goverter:matchIgnoreCase
 //goverter:ignore state
 //goverter:ignore sizeCache
 //goverter:ignore unknownFields
 Value(in.Struct2) out.Struct2 
 //goverter:matchIgnoreCase
 //goverter:ignore state
 //goverter:ignore sizeCache
 //goverter:ignore unknownFields
 Value(in.Struct3) out.Struct3
}

do this:

//goverter:matchIgnoreCase
//goverter:ignore state
//goverter:ignore sizeCache
//goverter:ignore unknownFields
type Transformer interface {
 Value(in.Struct1) out.Struct1
 Value(in.Struct2) out.Struct2
 Value(in.Struct3) out.Struct3
}

kamiLez avatar Jul 29 '22 18:07 kamiLez

I agree, it should be possible to set these options globally.

jmattheis avatar Aug 11 '22 17:08 jmattheis

When you run goverter, you can pass -ignoreUnexportedFields, to automatically ignore all unexported fields. I feel like globally ignoring exported fields should be a rare use-case, and can possibly lead to unwanted behavior, thus, I'll close this issue.

jmattheis avatar Feb 11 '23 10:02 jmattheis