23andMe / Yamale

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

Validate multiple alternative schemas #48

Closed ulope closed 5 years ago

ulope commented 5 years ago

I'm trying to build a validator for a configuration file format that has multiple mutually incompatible versions (similar to docker-compose files for example).

Example of how I had hoped to express this:

# The following line does *not* work
any(include('v1_config'), include('v2_config'))
---
v1_config:
  version: int(min=1, max=1, required=False)
  settings:
    v1_setting_a: str()
    v1_setting_b: str(required=False)
---
v2_config:
  version: int(min=2, max=2)
  settings:
    v2_setting_c: str()
    v2_setting_d: int()

Is there any way to express what I'm trying to do here, or is that simply not supported (yet)?

blopker commented 5 years ago

There's actually a PR out for this: https://github.com/23andMe/Yamale/pull/38 It's just quite large and complicated so I haven't been comfortable merging it. If you try it and it works for you please let me know.

drmull commented 5 years ago

PR #60 will solve this issue

mildebrandt commented 5 years ago

This is available in version 2.0.