Giter VIP home page Giter VIP logo

Comments (6)

geek avatar geek commented on May 10, 2024

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.

dacbd avatar dacbd commented on May 10, 2024
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.

geek avatar geek commented on May 10, 2024

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.

dacbd avatar dacbd commented on May 10, 2024

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.

geek avatar geek commented on May 10, 2024

Awesome idea, we should throw when the args aren't strings. Do you want to do a PR for this?

from joi.

dacbd avatar dacbd commented on May 10, 2024

sure.

from joi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.