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

Validate object keys related to another value #1761

Closed
jinliming2 opened this issue Mar 26, 2019 · 2 comments
Closed

Validate object keys related to another value #1761

jinliming2 opened this issue Mar 26, 2019 · 2 comments
Assignees
Labels
bug Bug or defect
Milestone

Comments

@jinliming2
Copy link

Assume I have objects like this:

{
  a: 'key',
  b: 'value',
  data: [
    { key: 'keyA', value: 1 },
    { key: 'keyB', value: 2 }
  ]
}
{
  a: 'anotherKey',
  b: 'anotherValue',
  data: [
    { anotherKey: 'keyA', anotherValue: 1 },
    { anotherKey: 'keyB', anotherValue: 2 }
  ]
}

Keys of object in array data must specify by key a and b.
I think it would be:

Joi.object({
  a: Joi.string().required(),
  b: Joi.string().required(),
  data: Joi.array()
    .items(
      Joi.object()
        .pattern(Joi.ref('a'), Joi.string().required())
        .pattern(Joi.ref('b'), Joi.number().required())
    )
    .required(),
})

Seems like #1382, but different.

@Marsup Marsup self-assigned this Apr 12, 2019
@Marsup Marsup added the bug Bug or defect label Apr 12, 2019
@Marsup Marsup closed this as completed in f51e98f Apr 12, 2019
@Marsup Marsup added this to the 15.0.1 milestone Apr 12, 2019
@Marsup
Copy link
Collaborator

Marsup commented Apr 12, 2019

Thanks, it was a bug, but be careful that there is currently no way to enforce the presence of a pattern.

@lock
Copy link

lock bot commented Jan 9, 2020

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 9, 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

2 participants