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

Support nested validation #14

Open
danneu opened this issue Nov 10, 2016 · 3 comments
Open

Support nested validation #14

danneu opened this issue Nov 10, 2016 · 3 comments

Comments

@danneu
Copy link
Owner

danneu commented Nov 10, 2016

koa-bouncer's main abstraction only works on top-level values in the query/body/param objects.

One idea for solving this without changing koa-bouncer much is to support some sort of dot notation: https://www.npmjs.com/package/dot-object

ctx.validateBody('user.password').validPassword()
ctx.validateBody('user.favoriteColors[]').isIn([red, orange, yellow, green, blue, violet])

Aside:

Due to its implementation, koa-bouncer's validators aren't generic and can't be reused beyond the Koa context object. So another idea is to reabstract the library so that it's more generic. For instance, using combinators.

Here's an idea I played with in another project: https://github.com/danneu/klobb#validation

Though were I to ever reabstract koa-bouncer, I would just create a new library rather than inconveniencing anyone that uses koa-bouncer.

Just some ideas.

@varHarrie
Copy link

Awesome!

@onbjerg
Copy link
Contributor

onbjerg commented Jan 30, 2017

Another sort of inconvenience with koa-bouncer is that sometimes you want to apply the same validation rules for multiple fields, and it leads to a lot of duplicate code. It would be cool if you could do that easily.

@danneu
Copy link
Owner Author

danneu commented Oct 7, 2017

agreed. best you can do for reuse in koa-bouncer is to create a custom validator method that calls other validator methods which isn't a very good solution for ad-hoc reuse.

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