Ignoring key validation completely

I would like to be able to opt-out of key validation entirely, rather than having to decide between required and optional, because, for example, we’ve validated earlier that keys are present if they need to be.

It would work like this:

key(:something).filled(:string)

and whether or not the key was present, we would get back a filled? error if the value isn’t present (because either the key is missing or the key is there but no value is).

I’ve hacked this in myself, but it’s ugly because I need to either always define my params with key(:something, macro: CustomKey) or monkey patch the DSL class to add my own method.

It’s great that dry-schema has the ability to distinguish between missing keys and missing values (and I do use this), but sometimes you don’t care and just want the value validation to happen.

Is this something you’d consider allowing (either natively or by allowing extension of the DSL)?

1 Like

@adamransom this makes sense, we’d only have to tweak key method in the DSL to make it simpler to use w/o any extra options. Feel free to report an issue about it :slight_smile:

I’ve been doing a lot of schemas lately and while this specific use-case hasn’t come up, it does sound pretty useful.