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

Support schema keys with '.' (without forcing path reach) #1695

Closed
peterkuiper opened this issue Jan 10, 2019 · 1 comment
Closed

Support schema keys with '.' (without forcing path reach) #1695

peterkuiper opened this issue Jan 10, 2019 · 1 comment
Assignees
Labels
bug Bug or defect feature New functionality or improvement
Milestone

Comments

@peterkuiper
Copy link

Context

  • node version: v8.11.4
  • joi version: v14.0.0+
  • environment (node, browser): node
  • used with (hapi, standalone, ...): standalone
  • any other relevant information: Schema below works with v13. We upgraded Joi and some of our tests failed.

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

const schema = Joi.object().keys({
  'mail.from': Joi.string().lowercase().email().optional(),
  'mail.url': Joi.string().uri({ scheme: ['https'] }).optional(),
}).xor(
  'mail.from',
  'mail.url',
);

Joi.validate({ 'mail.url': 'https://example.com' }, schema));

Removing .xor() seems to fix the validation.

Which result you had ?

{ error:
   { ValidationError: "value" must contain at least one of [mail.from, mail.url]
    at Object.exports.process (node_modules/joi/lib/errors.js:201:19)
    at internals.Object._validateWithOptions (node_modules/joi/lib/types/any/index.js:722:31)
    at module.exports.internals.Any.root.validate node_modules/joi/lib/index.js:146:23)
    at Object.<anonymous> (joi.js:13:17)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Function.Module.runMain (module.js:693:10)
     isJoi: true,
     name: 'ValidationError',
     details: [ [Object] ],
     _object: { 'mail.url': 'https://example.com' },
     annotate: [Function] },
  value: { 'mail.url': 'https://example.com' },
  then: [Function: then],
  catch: [Function: catch] }

What did you expect ?

{ error: null,
  value: { 'mail.url': 'https://example.com' },
  then: [Function: then],
  catch: [Function: catch] }
@hueniverse hueniverse self-assigned this Jun 2, 2019
@hueniverse hueniverse added bug Bug or defect feature New functionality or improvement labels Jun 2, 2019
@hueniverse hueniverse added this to the 16.0.0 milestone Jun 2, 2019
@hueniverse
Copy link
Contributor

The problem is that many methods support key reaching (e.g. a.b is translated into ['a']['b']).

@hueniverse hueniverse changed the title Schema keys with . and xor does not work with v14 Schema keys with '.' and xor forces reach Jun 2, 2019
@hueniverse hueniverse changed the title Schema keys with '.' and xor forces reach Support schema keys with '.' (without forcing path reach) Jun 2, 2019
@Marsup Marsup mentioned this issue Jun 9, 2019
@hueniverse hueniverse added breaking changes Change that can breaking existing code v16 and removed breaking changes Change that can breaking existing code labels Aug 10, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Feb 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Bug or defect feature New functionality or improvement
Projects
None yet
Development

No branches or pull requests

2 participants