jmattheis / goverter

Generate type-safe Go converters by simply defining an interface
https://goverter.jmattheis.de/
MIT License
496 stars 46 forks source link

Add ignore missing fields support #23

Closed dansimau closed 1 year ago

dansimau commented 2 years ago

Currently, fields to be ignored must be explicitly specified using a // goverter:ignore FieldName comment.

I.e.: https://github.com/jmattheis/goverter/blob/edc349e6e6a7f48d692325a952bf4411dcef9470/builder/struct.go#L29

However, in my case I want to ignore missing fields by default.

Possible solutions I can think of:

jmattheis commented 2 years ago

I'm unsure if this should be implemented, I really like explicitly defining what goverter should do as this makes things more obvious. Adding this, could produce unwanted behavior. F.ex when renaming struct fields goverter would not warn that there are more fields which have no mapping.

nissim-natanov-outreach commented 2 years ago

This would be a breaking change for us (we actually want goverter to stay strict and report missing fields by default). If you decide to take this on, please expose a global flag to enable strict behavior back on.

AnatolyRugalev commented 2 years ago

Having explicit missing fields definition is a nice feature, so I vote against having this behavior by default.

However, having explicit annotation for pattern matching seems like a reasonable feature to have, and also I don't see how this is a breaking change. This can be done with a new annotation like goverter:ignorePattern

jmattheis commented 1 year ago

I'm okay with adding another tag like goverter:ignoreMissing that can be added to a method or the converter to support this behavior. This is similar to the proposal in #58.

jmattheis commented 1 year ago

With v0.16.0 you can use goverter:ignoreMissing to ignore all missing exported fields. https://goverter.jmattheis.de/#/conversion/mapping?id=ignore If you also want to ignore unexported fields, then you've to add goverter:ignoreUnexported