23andMe / Yamale

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

Issue with using map validator "key" option with any/subset. #217

Open AndersonTaylor opened 1 year ago

AndersonTaylor commented 1 year ago

Hello, I'm attempting to validate keys of a map match against at least one of two different validators using any or subset.

example yaml:

my_properties:
    one: "should pass"
    two: "should pass" 
    3: "should pass"
    four: "should fail"

I've tried:

my_properties: map(key=any(enum('one', 'two'), int()))
OR
my_properties: map(key=subset(enum('one', 'two'), int()))

but both options pass as valid. Doing the same with only enum/int/other validators validates as expected.

Is this a bug, not possible, or am I just using the wrong syntax? (on version 4.0.4) Thanks.

mildebrandt commented 1 year ago

Looks like a bug in the interaction between the Subset validator and the Key constraint. It's not just the Subset validator, but any validator that sets additional validators within its constructor would have a problem...i.e. Map, List, Any, and Subset.

It's hard to see a quick fix for this one. It may be faster to write a regex to cover all your cases.

sabik commented 1 year ago

Cross-reference: this also applies to Include, per #133, and potentially Map and List