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

v/matches implies v/required? #40

Closed
jonase opened this issue Oct 17, 2015 · 1 comment
Closed

v/matches implies v/required? #40

jonase opened this issue Oct 17, 2015 · 1 comment

Comments

@jonase
Copy link

jonase commented Oct 17, 2015

I'm not sure if this is intended behaviour but

(bouncer/validate {}
                  :id [v/string [v/matches #"a*"]])

evaluates to

[{:id ("id must be a string")} {:bouncer.core/errors {:id ("id must be a string")}}]

I would have expected the validation to pass since :id is not v/required.

If this is expected how do I create a validator where an optional string value must match a regex only if the key exists?

Edit After some digging it's actually v/string that makes the key-value non-optional. This was a surprise for me

@theleoborges
Copy link
Owner

This has been changed on #41 so bouncer will behave like this:

user=> (b/validate {} :id [v/string [v/matches #"a*"]])
[nil {}]
user=> (b/validate {} :id [v/required v/string [v/matches #"a*"]])
[{:id ("id must be present")} {:bouncer.core/errors {:id ("id must be present")}}]

I've just released a new version containing this change. Give that a go and let me know if you run into issues.

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

2 participants