forked from mitchellh/mapstructure
-
Notifications
You must be signed in to change notification settings - Fork 32
Open
Description
Issue mitchellh#350 in the original repo by mateusoliveira43 should be addressed:
If I use ErrorUnset = true and add mapstructure:"-" to my struct field, I get the following error:
* '' has unset fields: -
But since that field is ignored, it should not trigger an error, right?
Also tried using with IgnoreUntaggedFields = true, but got the same result
Current workaround is to check the mapstructure.Metadata
manually. Minimal example:
md := mapstructure.Metadata{}
opts := func(mcfg *mapstructure.DecoderConfig) {
mcfg.Metadata = &md
}
viper.Unmarshal(&cfg, opts)
// Ignore unset fields that have the "-" mapstruct tag.
md.Unset = slices.DeleteFunc(md.Unset, func(s string) bool {
return strings.HasSuffix(s, ".-")
})
require.Empty(t, md.Unused, "unused config keys: %v", md.Unused)
Here is also a playground example, however it's build times out, playground has limited resources.
If this is by design? Any clarification is appreciated!
Metadata
Metadata
Assignees
Labels
No labels