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

validator params does not act as documented #90

Open
LeviSchuck opened this issue Apr 30, 2021 · 1 comment
Open

validator params does not act as documented #90

LeviSchuck opened this issue Apr 30, 2021 · 1 comment

Comments

@LeviSchuck
Copy link

If I set up a params object (naming it validate-account to not shadow the params function, which I think is a bad example)

(def validate-account
     (params :accounts
       (validates [:name :real-name] :required true)
       (permit [:name :real-name])))

The documented behavior is not met, in fact both the error case and the successful case do not work as described.

repl:39:> (rescue (validate-account {:name "hello"}))
(@{:name "name is required" :real-name "real-name is required"} nil)
repl:40:> (rescue (validate-account {:name "hello" :real-name "real"}))
(@{:name "name is required" :real-name "real-name is required"} nil)

Instead the true behavior is found when it is wrapped in {:body {...}}

repl:41:> (rescue (validate-account {:body {:name "hello"}}))
(@{:real-name "real-name is required"} nil)
repl:42:> (rescue (validate-account {:body {:name "hello" :real-name "real"}}))
(nil @{:db/table :accounts :name "hello" :real-name "real"})
@swlkr
Copy link
Collaborator

swlkr commented Apr 30, 2021

Hmm maybe there should be a validate-body and validate for requests and for regular dictionaries

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