mapstructure icon indicating copy to clipboard operation
mapstructure copied to clipboard

Add config to error if field is NOT set

Open mitchellh opened this issue 12 years ago • 9 comments

mitchellh avatar Nov 22 '13 21:11 mitchellh

/cc @armon

mitchellh avatar Nov 22 '13 21:11 mitchellh

I may take a stab at this if I find some time this weekend. Not to overly complicate things but it might be nice to have more fine grained control over which fields are required and which are not. I'd consider adding one or more tags related to this:

  1. "required" which would trigger an error if a specified field is omitted and the new config flag is enabled. Alternatively the new config flag wouldn't need to exist at all, but maybe you're importing someone else's type that has "required" fields and you don't want them to be required.
  2. "omissible" which would suppress an error if a specified field is omitted and the new config flag is enabled. I'm not sure it it makes sense to have this double up on "omitempty". It seems like they'd likely often be set together on the same field, but that's not a compelling enough reason to lump them together to me.

abursavich avatar Nov 29 '13 05:11 abursavich

@ambify I think to begin, a blanket all required and all not required bool would make sense to the Config.

In the future, a better way to do it more fine grained would be good.

mitchellh avatar Nov 30 '13 16:11 mitchellh

:+1: required fields would be great. Any progress on it?

bsideup avatar Feb 03 '16 06:02 bsideup

so it's now 2018, any progress?

BrendanBall avatar Jan 22 '18 14:01 BrendanBall

I have submitted https://github.com/mitchellh/mapstructure/pull/167 which implements this.

bonifaido avatar Jul 03 '19 14:07 bonifaido

+1 for this Looking for this to be configurable, similar to something like https://github.com/mitchellh/mapstructure/pull/27

HavaH123 avatar Dec 01 '20 02:12 HavaH123

There is another PR with this useful feature too https://github.com/mitchellh/mapstructure/pull/225. Please choose one and merge 🎉

programmer04 avatar Feb 03 '21 18:02 programmer04

Very useful for my requirements - please merge :+1:

D-MarcFrank avatar Apr 16 '21 12:04 D-MarcFrank