Comments (6)
How would .with(['latitude', 'longitude'], 'something')
be handled, or multiple arrays as arguments. Instead, can you do a with.apply(n, ['latitude', 'longitude'])
if you want to pass in the args as an array.
from joi.
var args = Array.isArray(arguments[0]) ? arguments[0].concat(arguments.slice(1) : arguments
Its an idea and by the looks you aren't fond of it, you could argue what if's all day .with( 'something', ['latitude', 'longitude'], something2)
It would either be as it is now, or the current way and with the arguments[0] being an array of what you want, not a combination of the two.
I'll close the issue in a bit incase someone has any other input.
from joi.
I am not opposed to it, but can't think of a good use case. Any thoughts on a valid use case? The other edge case may be with([], [], [], 'something')
from joi.
So this isn't really about expanding to a new use case its more of increasing usability. This is quite possibly the wrong approach to the problem I encountered.
When I incorrectly used arrays i received this as a response:
{ code: 400,
error: 'Bad Request',
message: 'not valid, not valid, not valid' }
It is my understanding that the .with/.without should only ever have other key names of the object you are validating as input, so those methods are only expecting strings as input. When it received an array it choked and said the payload was invalid when it tried to check and see if the key objectToBeValidated[[]]
was present in said object.
maybe a more appropriate action would be to check and make sure arguments only contains strings? and to throw an error with inappropriate use of the method.
calling the method like so: .with([])
would be the same as .with()
If you understand what I'm saying better than we can:
- implement a single array of args as valid input
- throw an error for arguments that aren't strings (unless [] {} or 123 is valid for said function) which case you are correct and there isn't a use case
- change the error message so its more clear what is really happening in this case
- leave everything the way it is, maybe add an example to the readme of what not todo
Overall you are correct, there isn't a great use case for it. I made the mistake and it wasn't clear what the problem was until I dug a little deeper.
from joi.
Awesome idea, we should throw when the args aren't strings. Do you want to do a PR for this?
from joi.
sure.
from joi.
Related Issues (20)
- v17.10.0 Typed schema on validate is returning value:any HOT 5
- Nuxt 3.7.4 + Joi 17.11.0 not functioning correctly in the built project HOT 3
- Docs: Changelog HOT 4
- StrictSchemaMap type does not strictly check keys in Joi objects HOT 1
- website doesn't mention how to install HOT 3
- What version of node does this library support? HOT 11
- I can't validate with the Joi class. HOT 2
- Incorrectly loose types for strict object schema for non-string values
- How to get resolved reference value of provided object instead of Ref Object in ValidationError ? HOT 1
- Property 'validate' does not exist on type 'Root'.ts(2339)
- Field validation HOT 3
- TS won't compile when using array fields in a strict object schema HOT 2
- Can't use validateAsync is giving error if no external validation rule HOT 7
- array().items() fails validation when items contains more than 3 items HOT 2
- Error.captureStackTrace(this, exports.assert); HOT 7
- Property 'min' does not exist on type 'StringSchema<string>'. HOT 2
- Domain validation not checking IANA registry by default HOT 1
- abortEarrly = false and formatting the return of multiple errors HOT 1
- joi.allow array HOT 2
- Optional is missing in definition file HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from joi.