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

ability to specify Joi validation options without using Joi objects as schemas #41

Closed
kotarac opened this issue Mar 24, 2017 · 6 comments · Fixed by #119
Closed

ability to specify Joi validation options without using Joi objects as schemas #41

kotarac opened this issue Mar 24, 2017 · 6 comments · Fixed by #119

Comments

@kotarac
Copy link

kotarac commented Mar 24, 2017

Hey there!

Considering using koa-joi-router on our next few projects.

One issue I ran into is no ability to set options for Joi other than specifying the validation as Joi objects everytime and chaining an options call.
body: joi.object({ email: joi.string().email().required(), password: joi.string().required(), }).options({abortEarly: false}),

This is a bit tedious if you want something set for every validation everywhere.
F.ex. I'd like abortEarly: false to get all validation errors at once.

The way I see it, it could be done 2 ways:

  1. have individual options in the validation spec (abortEarly, convert, etc.)
  2. whole options object in the validation spec

Potential problems:
These "global" options overriding individual validations sent as Joi objects with options specified (like in the example above).

I'd be willing to tackle this and submit a PR if everyone's ok with the changes - already have solution 1. ready.

@paul42
Copy link
Contributor

paul42 commented Apr 8, 2017

I think this sounds like a cool idea, I too like the abortEarly:false, and would like to be able to tweak the skipUnknown option.

I think (in my humble opinion as a user and not a contributor) that if you have a 'stained-glass' model, where more local overwrites more global defaults with 'route' options taking precedence over global options would be super flexible.

@paul42
Copy link
Contributor

paul42 commented May 6, 2017

@kotarac I'm curious, do you have a branch with your fixes in it? I might want to try that out

@kotarac
Copy link
Author

kotarac commented May 8, 2017

@paul42 I'll get back to you, I've since decided against using joi-router but think I still have the option 1. somewhere.

@escobar5
Copy link

Was looking for the same, would be a good idea to have global options.

@rodolfoamarques
Copy link

i'd second (more like tenth) this as well. just ran into similar issues as described by @kotarac.

since this has been marked as help wanted, i may get around to create an PR for this. Please let me if someone is already working on it?

@aheckmann
Copy link
Member

@rodolfoamarques please open a PR.

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

Successfully merging a pull request may close this issue.

5 participants