{"action":"created","issue":{"url":"https://api.github.com/repos/hapijs/joi/issues/632","labels_url":"https://api.github.com/repos/hapijs/joi/issues/632/labels{/name}","comments_url":"https://api.github.com/repos/hapijs/joi/issues/632/comments","events_url":"https://api.github.com/repos/hapijs/joi/issues/632/events","html_url":"https://github.com/hapijs/joi/issues/632","id":70241860,"number":632,"title":"Nested whens don't work","user":{"login":"mgartner","id":1128750,"avatar_url":"https://avatars.githubusercontent.com/u/1128750?v=3","gravatar_id":"","url":"https://api.github.com/users/mgartner","html_url":"https://github.com/mgartner","followers_url":"https://api.github.com/users/mgartner/followers","following_url":"https://api.github.com/users/mgartner/following{/other_user}","gists_url":"https://api.github.com/users/mgartner/gists{/gist_id}","starred_url":"https://api.github.com/users/mgartner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mgartner/subscriptions","organizations_url":"https://api.github.com/users/mgartner/orgs","repos_url":"https://api.github.com/users/mgartner/repos","events_url":"https://api.github.com/users/mgartner/events{/privacy}","received_events_url":"https://api.github.com/users/mgartner/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-04-22T21:37:37Z","updated_at":"2015-04-23T02:12:37Z","closed_at":null,"body":"Why doesn't this work in my schema:\r\n\r\n```js\r\nvar schema = Joi.object().keys({\r\n  setting: Joi.alternatives().when('$auth.credentials.cond1', {\r\n    is: true,\r\n    then: Joi.number().integer().required().when('$auth.credentials.cond2', {\r\n      is: true,\r\n      then: Joi.invalid(100, 101)\r\n    }),\r\n    otherwise: Joi.forbidden()\r\n  })\r\n});\r\n```\r\n\r\nWhen `$auth.credentials.cond1` is true, and `setting` is not provided in the input object, there is no validation error when there should be because it is required."},"comment":{"url":"https://api.github.com/repos/hapijs/joi/issues/comments/95392139","html_url":"https://github.com/hapijs/joi/issues/632#issuecomment-95392139","issue_url":"https://api.github.com/repos/hapijs/joi/issues/632","id":95392139,"user":{"login":"mgartner","id":1128750,"avatar_url":"https://avatars.githubusercontent.com/u/1128750?v=3","gravatar_id":"","url":"https://api.github.com/users/mgartner","html_url":"https://github.com/mgartner","followers_url":"https://api.github.com/users/mgartner/followers","following_url":"https://api.github.com/users/mgartner/following{/other_user}","gists_url":"https://api.github.com/users/mgartner/gists{/gist_id}","starred_url":"https://api.github.com/users/mgartner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mgartner/subscriptions","organizations_url":"https://api.github.com/users/mgartner/orgs","repos_url":"https://api.github.com/users/mgartner/repos","events_url":"https://api.github.com/users/mgartner/events{/privacy}","received_events_url":"https://api.github.com/users/mgartner/received_events","type":"User","site_admin":false},"created_at":"2015-04-23T02:12:37Z","updated_at":"2015-04-23T02:12:37Z","body":"Also, regarding your comment above about `any.when()`, in my experience this correctly ensures that setting is an integer, which contradicts what you said:\r\n\r\n```js\r\nvar schema = Joi.object().keys({\r\n  setting: Joi.number().integer().when('$auth.credentials.cond1', {\r\n    is: true,\r\n    then: Joi.required(),\r\n    otherwise: Joi.forbidden()\r\n  })\r\n});\r\n```"}}