ability to specify Joi validation options without using Joi objects as schemas
kotarac opened this issue · comments
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:
- have individual options in the validation spec (abortEarly, convert, etc.)
- 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.
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.
@kotarac I'm curious, do you have a branch with your fixes in it? I might want to try that out
@paul42 I'll get back to you, I've since decided against using joi-router but think I still have the option 1. somewhere.
Was looking for the same, would be a good idea to have global options.
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?
@rodolfoamarques please open a PR.