Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
AndersonTaylor opened this issue Mar 17, 2023 · 2 comments
Open

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

AndersonTaylor opened this issue Mar 17, 2023 · 2 comments

Comments

@AndersonTaylor
Copy link

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
Copy link

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
Copy link

sabik commented Aug 16, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants