23andMe / Yamale

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

How to specify that at least one of two optional properties must be present? #214

Closed Bascy closed 1 year ago

Bascy commented 1 year ago

I have a yaml structure that contains 2 optional properties. Like:

IntegerMonitor:
   message: str()
   minValue: int(required=False)
   maxValue: int(required=False)

How can I specify that at least on of minValue or maxValue needs to be present?

mildebrandt commented 1 year ago

It's a little verbose, but this is how you'd define that:

IntegerMonitor: any(include('min_required'), include('max_required'))
---
min_required:
  message: str()
  minValue: int()
  maxValue: int(required=False)

max_required:
  message: str()
  minValue: int(required=False)
  maxValue: int()
Bascy commented 1 year ago

Thanks