23andMe / Yamale

A schema and validator for YAML.
MIT License
679 stars 88 forks source link

Multiple field validation #154

Closed YaronFruchtmann closed 3 years ago

YaronFruchtmann commented 3 years ago

Hey, This is a great repo! I am trying to validate a yaml, not sure this is within the scope of schema validation: Suppose I have some parents and for each their children. I want to validate "a group" which consists of one parent and a subset of their children. Group: Parent: enum('John','Mike', 'Peter', ...) Children: list( enum( children[Parent]) )

It is possible to "work around" this by defining GroupJohn, GroupMike ... and then use the any() validator, but I am looking for a more straightforward method.

Similarly, if the schemas has both minAge: int() maxAge: int() and I'd like to validate that maxAge > minAge

Thanks!

mildebrandt commented 3 years ago

Thanks for your interest in Yamale!

I think you have hit some of the limitations of Yamale. The library validates each element of the yaml separately...so you wouldn't be able to validate that minAge is less than maxAge.

For the parent and children, I think you've outlined in your "work around" the only way to make that happen. To handle this specific case in a generic way, the library would need to read the value from the input yaml (validating that item), insert it into the schema, and then re-validate the yaml. That's something that also requires validating one element based on the value of another.

I'm sorry, while this is an interesting use case, both of these items are out of the current scope of Yamale.

YaronFruchtmann commented 3 years ago

Thanks!