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

Example for Array Schema Not Possible #828

Closed
jasonmcaffee opened this issue Feb 19, 2016 · 2 comments
Closed

Example for Array Schema Not Possible #828

jasonmcaffee opened this issue Feb 19, 2016 · 2 comments
Labels
bug Bug or defect
Milestone

Comments

@jasonmcaffee
Copy link

Context

It is not possible to create an example for an array schema, as the value passed into the example function is concatenated with existing examples.

  • node version: 4.0.0
  • joi version: 7.2.3
  • environment (node, browser): no
  • used with (hapi, standalone, ...): standalone
  • any other relevant information:

What are you trying to achieve or the steps to reproduce ?

Trying to provide examples for a joi.array, so that schema.describe().examples will provide an array of arrays.
Describe your issue here, include schemas and inputs you are validating if needed.

const schema = Joi.array()
   .example(['a', 'b'])
   .example(['c', 'd'])

let examples = schema.describe().examples;
assert(examples.length == 2); //fails

Which result you had ?

examples.length is 1

What did you expect ?

examples.length is 2

Offending line of code:

https://github.com/hapijs/joi/blob/master/lib/any.js#L447

@ChopperLee2011
Copy link

i think the result for examples.length is 4 followed by your code. and i agree the expect is 2, even i never read the Joi._examples things back.

@Marsup Marsup closed this as completed in 7757539 Feb 19, 2016
@Marsup Marsup added the bug Bug or defect label Feb 19, 2016
@Marsup Marsup added this to the 8.0.2 milestone Feb 19, 2016
@Marsup Marsup self-assigned this Feb 19, 2016
@jasonmcaffee
Copy link
Author

Yeah, meant 4. thanks!

@lock lock bot locked as resolved and limited conversation to collaborators Jan 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Bug or defect
Projects
None yet
Development

No branches or pull requests

3 participants