genomoncology / related

Nested Object Models in Python with dictionary, YAML, and JSON transformation support
MIT License
198 stars 15 forks source link

Passing additional validators #24

Open GeorgeLubaretsi opened 5 years ago

GeorgeLubaretsi commented 5 years ago

init_validator intializer that is called in declared fields accepts additional_validators, but it's not exposed in built-in fields. It would be nice to have that exposed.

I created custom fields that accepts list of validators that is passed to the validators composer and subsequently to the attr which works fine for required fields, but when the field is optional, validators.optional is called with the _CompositeValidator object, which contains validators as a tuple, but validators.optional only checks if the validators is type of list.

It's not very easy to override the composer, so perhaps it's a good idea to make it extensible too. Additional benefits would be that we can use composed functions for field converters too

Valian commented 5 years ago

I also have this problem. There is no easy way to pass additional_validatators to fields, potentially a very simple fix. @imaurer what is your opinion?