{"action":"created","issue":{"url":"https://api.github.com/repos/hapijs/joi/issues/914","repository_url":"https://api.github.com/repos/hapijs/joi","labels_url":"https://api.github.com/repos/hapijs/joi/issues/914/labels{/name}","comments_url":"https://api.github.com/repos/hapijs/joi/issues/914/comments","events_url":"https://api.github.com/repos/hapijs/joi/issues/914/events","html_url":"https://github.com/hapijs/joi/issues/914","id":158815201,"number":914,"title":"Joi.lazy() does not validate nested schema correctly with stripUnknown: true","user":{"login":"MarkHerhold","id":4934732,"avatar_url":"https://avatars.githubusercontent.com/u/4934732?v=3","gravatar_id":"","url":"https://api.github.com/users/MarkHerhold","html_url":"https://github.com/MarkHerhold","followers_url":"https://api.github.com/users/MarkHerhold/followers","following_url":"https://api.github.com/users/MarkHerhold/following{/other_user}","gists_url":"https://api.github.com/users/MarkHerhold/gists{/gist_id}","starred_url":"https://api.github.com/users/MarkHerhold/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MarkHerhold/subscriptions","organizations_url":"https://api.github.com/users/MarkHerhold/orgs","repos_url":"https://api.github.com/users/MarkHerhold/repos","events_url":"https://api.github.com/users/MarkHerhold/events{/privacy}","received_events_url":"https://api.github.com/users/MarkHerhold/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/hapijs/joi/labels/non-issue","name":"non-issue","color":"c7def8"}],"state":"closed","locked":false,"assignee":{"login":"Marsup","id":796194,"avatar_url":"https://avatars.githubusercontent.com/u/796194?v=3","gravatar_id":"","url":"https://api.github.com/users/Marsup","html_url":"https://github.com/Marsup","followers_url":"https://api.github.com/users/Marsup/followers","following_url":"https://api.github.com/users/Marsup/following{/other_user}","gists_url":"https://api.github.com/users/Marsup/gists{/gist_id}","starred_url":"https://api.github.com/users/Marsup/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Marsup/subscriptions","organizations_url":"https://api.github.com/users/Marsup/orgs","repos_url":"https://api.github.com/users/Marsup/repos","events_url":"https://api.github.com/users/Marsup/events{/privacy}","received_events_url":"https://api.github.com/users/Marsup/received_events","type":"User","site_admin":false},"milestone":null,"comments":2,"created_at":"2016-06-07T02:06:18Z","updated_at":"2016-06-07T16:44:06Z","closed_at":"2016-06-07T07:04:12Z","body":"Feedback for #379 \r\n\r\n#### Context\r\n\r\n* *node version*: 6.2.0\r\n* *joi version*: 9.0.0-3\r\n* *environment* (node, browser): node\r\n* *used with* (hapi, standalone, ...): standalone\r\n* *Other info* Joi options always use` { stripUnknown: true }` in the below examples\r\n\r\n#### What are you trying to achieve or the steps to reproduce ?\r\nI'm attempting to get Joi to properly validate nested schema. It appears that fields are not respected when using `Joi.lazy()` with the `stripUnknown` options set to `true`.\r\n\r\n👍  Base example (validates, no errors):\r\n```js\r\nJoi = require(\"joi@9.0.0-3\")\r\nconst options = { stripUnknown: true };\r\n\r\nconst group = Joi.object().keys({\r\n    name: Joi.string().required(),\r\n    groups: Joi.array().items(\r\n        Joi.lazy(() => group)\r\n    ).default([]).required()\r\n});\r\n\r\ngroup.validate({\r\n    name: 'button',\r\n    groups: [{\r\n        name: 'other',\r\n        groups: []\r\n    }]\r\n}, options);\r\n\r\n// no error :)\r\n```\r\n\r\n👍  Example that breaks validation of the root schema\r\n\r\n```js\r\nJoi = require(\"joi@9.0.0-3\")\r\nconst options = { stripUnknown: true };\r\n\r\nconst group = Joi.object().keys({\r\n    name: Joi.string().required(),\r\n    groups: Joi.array().items(\r\n        Joi.lazy(() => group)\r\n    ).default([]).required()\r\n});\r\n\r\ngroup.validate({\r\n    name: false, // <--- changed to boolean to break validation\r\n    groups: [{\r\n        name: 'other',\r\n        groups: []\r\n    }]\r\n}, options);\r\n\r\n// Error: child \"name\" fails because [\"name\" must be a string] :)\r\n```\r\n\r\n\r\n### What I have\r\n👎  Example that doesn't break validation of the nested schema\r\n\r\n```js\r\nJoi = require(\"joi@9.0.0-3\")\r\nconst options = { stripUnknown: true };\r\n\r\nconst group = Joi.object().keys({\r\n    name: Joi.string().required(),\r\n    groups: Joi.array().items(\r\n        Joi.lazy(() => group)\r\n    ).default([]).required()\r\n});\r\n\r\ngroup.validate({\r\n    name: 'button',\r\n    groups: [{\r\n        name: false, // <--- changing this to a boolean should cause an error but doesn't\r\n        groups: []\r\n    }]\r\n}, options);\r\n\r\n// no error :(\r\n```\r\n\r\nNote that this correctly returns an error if `stripUnknown` is set to `false`.\r\n\r\n### What I expect\r\n\r\nI expect to receive an error like: `Error: child \"groups\" fails because [\"groups\" at position 0 fails because [child \"name\" fails because [\"name\" must be a string]]]`\r\n"},"comment":{"url":"https://api.github.com/repos/hapijs/joi/issues/comments/224340901","html_url":"https://github.com/hapijs/joi/issues/914#issuecomment-224340901","issue_url":"https://api.github.com/repos/hapijs/joi/issues/914","id":224340901,"user":{"login":"MarkHerhold","id":4934732,"avatar_url":"https://avatars.githubusercontent.com/u/4934732?v=3","gravatar_id":"","url":"https://api.github.com/users/MarkHerhold","html_url":"https://github.com/MarkHerhold","followers_url":"https://api.github.com/users/MarkHerhold/followers","following_url":"https://api.github.com/users/MarkHerhold/following{/other_user}","gists_url":"https://api.github.com/users/MarkHerhold/gists{/gist_id}","starred_url":"https://api.github.com/users/MarkHerhold/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MarkHerhold/subscriptions","organizations_url":"https://api.github.com/users/MarkHerhold/orgs","repos_url":"https://api.github.com/users/MarkHerhold/repos","events_url":"https://api.github.com/users/MarkHerhold/events{/privacy}","received_events_url":"https://api.github.com/users/MarkHerhold/received_events","type":"User","site_admin":false},"created_at":"2016-06-07T16:44:06Z","updated_at":"2016-06-07T16:44:06Z","body":"```\r\nJoi = require(\"joi@9.0.0-3\")\r\nconst options = { stripUnknown: true };\r\n\r\nconst group = Joi.object().keys({\r\n    name: Joi.string().required(),\r\n    groups: Joi.array().items(\r\n        Joi.lazy(() => group)\r\n    ).default([]).required().options({ stripUnknown: { arrays: false, objects: true } })\r\n});\r\n```\r\nIt looks like this is what I want then. Tanks for the pointer @Marsup "}}
{"actor":{"display_login":"MarkHerhold"}}