{"action":"created","comment":{"url":"https://api.github.com/repos/ctavan/express-validator/pulls/comments/33084432","id":33084432,"diff_hunk":"@@ -165,6 +171,29 @@ var expressValidator = function(options) {\n };\n \n /**\n+ * validate an object using a schema\n+ *\n+ * @method validateParams\n+ * @param  {Object}       schema    schema of validations\n+ * @param  {Request}      req       request to attach validation errors\n+ * @param  {string}       location  request property to find value (body, params, query, etc.)\n+ * @param  {Object}       options   options containing custom validators & errorFormatter\n+ * @return {object[]}               array of errors\n+ */\n+\n+function validateSchema(schema, req, loc, options) {\n+  for(var param in schema) {\n+    loc = (loc === 'any') ? locate(req, param) : loc;\n+    var validator = new ValidatorChain(param, null, req, loc, options);\n+\n+    for(var methodName in schema[param]) {","path":"lib/express_validator.js","position":39,"original_position":39,"commit_id":"d1c5ec3f35078b2986cbb83ec3977f031c08a2c1","original_commit_id":"d1c5ec3f35078b2986cbb83ec3977f031c08a2c1","user":{"login":"rustybailey","id":1975147,"avatar_url":"https://avatars.githubusercontent.com/u/1975147?v=3","gravatar_id":"","url":"https://api.github.com/users/rustybailey","html_url":"https://github.com/rustybailey","followers_url":"https://api.github.com/users/rustybailey/followers","following_url":"https://api.github.com/users/rustybailey/following{/other_user}","gists_url":"https://api.github.com/users/rustybailey/gists{/gist_id}","starred_url":"https://api.github.com/users/rustybailey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rustybailey/subscriptions","organizations_url":"https://api.github.com/users/rustybailey/orgs","repos_url":"https://api.github.com/users/rustybailey/repos","events_url":"https://api.github.com/users/rustybailey/events{/privacy}","received_events_url":"https://api.github.com/users/rustybailey/received_events","type":"User","site_admin":false},"body":"space after the for","created_at":"2015-06-23T19:58:55Z","updated_at":"2015-06-23T19:58:55Z","html_url":"https://github.com/ctavan/express-validator/pull/145#discussion_r33084432","pull_request_url":"https://api.github.com/repos/ctavan/express-validator/pulls/145","_links":{"self":{"href":"https://api.github.com/repos/ctavan/express-validator/pulls/comments/33084432"},"html":{"href":"https://github.com/ctavan/express-validator/pull/145#discussion_r33084432"},"pull_request":{"href":"https://api.github.com/repos/ctavan/express-validator/pulls/145"}}},"pull_request":{"url":"https://api.github.com/repos/ctavan/express-validator/pulls/145","id":38288385,"html_url":"https://github.com/ctavan/express-validator/pull/145","diff_url":"https://github.com/ctavan/express-validator/pull/145.diff","patch_url":"https://github.com/ctavan/express-validator/pull/145.patch","issue_url":"https://api.github.com/repos/ctavan/express-validator/issues/145","number":145,"state":"open","locked":false,"title":"Add validation by schema","user":{"login":"Jakeii","id":1731150,"avatar_url":"https://avatars.githubusercontent.com/u/1731150?v=3","gravatar_id":"","url":"https://api.github.com/users/Jakeii","html_url":"https://github.com/Jakeii","followers_url":"https://api.github.com/users/Jakeii/followers","following_url":"https://api.github.com/users/Jakeii/following{/other_user}","gists_url":"https://api.github.com/users/Jakeii/gists{/gist_id}","starred_url":"https://api.github.com/users/Jakeii/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Jakeii/subscriptions","organizations_url":"https://api.github.com/users/Jakeii/orgs","repos_url":"https://api.github.com/users/Jakeii/repos","events_url":"https://api.github.com/users/Jakeii/events{/privacy}","received_events_url":"https://api.github.com/users/Jakeii/received_events","type":"User","site_admin":false},"body":"I've added the functionality to be able to validate by passing an object schema to check, checkBody etc. as an alternative to chaining.\r\n\r\nexample:\r\n````javascript\r\nreq.checkBody({\r\n  'email': {\r\n    notEmpty: true,\r\n    isEmail:\r\n      failMsg: 'Invalid Email'\r\n    }\r\n  },\r\n  'password': {\r\n     notEmpty: true\r\n  },\r\n  'name.first': {\r\n    notEmpty: true,\r\n    isLength: {\r\n      options: [2, 10],\r\n      failMsg: 'Must be between 2 and 10 chars long'\r\n    }\r\n  }\r\n});\r\n````\r\npassing true will use the default error message.","created_at":"2015-06-22T23:42:11Z","updated_at":"2015-06-23T19:58:55Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1a115e5cc2da1db8280fd9859a80c24b06604b70","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ctavan/express-validator/pulls/145/commits","review_comments_url":"https://api.github.com/repos/ctavan/express-validator/pulls/145/comments","review_comment_url":"https://api.github.com/repos/ctavan/express-validator/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ctavan/express-validator/issues/145/comments","statuses_url":"https://api.github.com/repos/ctavan/express-validator/statuses/d1c5ec3f35078b2986cbb83ec3977f031c08a2c1","head":{"label":"Jakeii:schema","ref":"schema","sha":"d1c5ec3f35078b2986cbb83ec3977f031c08a2c1","user":{"login":"Jakeii","id":1731150,"avatar_url":"https://avatars.githubusercontent.com/u/1731150?v=3","gravatar_id":"","url":"https://api.github.com/users/Jakeii","html_url":"https://github.com/Jakeii","followers_url":"https://api.github.com/users/Jakeii/followers","following_url":"https://api.github.com/users/Jakeii/following{/other_user}","gists_url":"https://api.github.com/users/Jakeii/gists{/gist_id}","starred_url":"https://api.github.com/users/Jakeii/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Jakeii/subscriptions","organizations_url":"https://api.github.com/users/Jakeii/orgs","repos_url":"https://api.github.com/users/Jakeii/repos","events_url":"https://api.github.com/users/Jakeii/events{/privacy}","received_events_url":"https://api.github.com/users/Jakeii/received_events","type":"User","site_admin":false},"repo":{"id":37160666,"name":"express-validator","full_name":"Jakeii/express-validator","owner":{"login":"Jakeii","id":1731150,"avatar_url":"https://avatars.githubusercontent.com/u/1731150?v=3","gravatar_id":"","url":"https://api.github.com/users/Jakeii","html_url":"https://github.com/Jakeii","followers_url":"https://api.github.com/users/Jakeii/followers","following_url":"https://api.github.com/users/Jakeii/following{/other_user}","gists_url":"https://api.github.com/users/Jakeii/gists{/gist_id}","starred_url":"https://api.github.com/users/Jakeii/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Jakeii/subscriptions","organizations_url":"https://api.github.com/users/Jakeii/orgs","repos_url":"https://api.github.com/users/Jakeii/repos","events_url":"https://api.github.com/users/Jakeii/events{/privacy}","received_events_url":"https://api.github.com/users/Jakeii/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Jakeii/express-validator","description":"An express.js middleware for node-validator.","fork":true,"url":"https://api.github.com/repos/Jakeii/express-validator","forks_url":"https://api.github.com/repos/Jakeii/express-validator/forks","keys_url":"https://api.github.com/repos/Jakeii/express-validator/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Jakeii/express-validator/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Jakeii/express-validator/teams","hooks_url":"https://api.github.com/repos/Jakeii/express-validator/hooks","issue_events_url":"https://api.github.com/repos/Jakeii/express-validator/issues/events{/number}","events_url":"https://api.github.com/repos/Jakeii/express-validator/events","assignees_url":"https://api.github.com/repos/Jakeii/express-validator/assignees{/user}","branches_url":"https://api.github.com/repos/Jakeii/express-validator/branches{/branch}","tags_url":"https://api.github.com/repos/Jakeii/express-validator/tags","blobs_url":"https://api.github.com/repos/Jakeii/express-validator/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Jakeii/express-validator/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Jakeii/express-validator/git/refs{/sha}","trees_url":"https://api.github.com/repos/Jakeii/express-validator/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Jakeii/express-validator/statuses/{sha}","languages_url":"https://api.github.com/repos/Jakeii/express-validator/languages","stargazers_url":"https://api.github.com/repos/Jakeii/express-validator/stargazers","contributors_url":"https://api.github.com/repos/Jakeii/express-validator/contributors","subscribers_url":"https://api.github.com/repos/Jakeii/express-validator/subscribers","subscription_url":"https://api.github.com/repos/Jakeii/express-validator/subscription","commits_url":"https://api.github.com/repos/Jakeii/express-validator/commits{/sha}","git_commits_url":"https://api.github.com/repos/Jakeii/express-validator/git/commits{/sha}","comments_url":"https://api.github.com/repos/Jakeii/express-validator/comments{/number}","issue_comment_url":"https://api.github.com/repos/Jakeii/express-validator/issues/comments{/number}","contents_url":"https://api.github.com/repos/Jakeii/express-validator/contents/{+path}","compare_url":"https://api.github.com/repos/Jakeii/express-validator/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Jakeii/express-validator/merges","archive_url":"https://api.github.com/repos/Jakeii/express-validator/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Jakeii/express-validator/downloads","issues_url":"https://api.github.com/repos/Jakeii/express-validator/issues{/number}","pulls_url":"https://api.github.com/repos/Jakeii/express-validator/pulls{/number}","milestones_url":"https://api.github.com/repos/Jakeii/express-validator/milestones{/number}","notifications_url":"https://api.github.com/repos/Jakeii/express-validator/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Jakeii/express-validator/labels{/name}","releases_url":"https://api.github.com/repos/Jakeii/express-validator/releases{/id}","created_at":"2015-06-09T21:53:20Z","updated_at":"2015-06-09T21:53:20Z","pushed_at":"2015-06-23T09:47:21Z","git_url":"git://github.com/Jakeii/express-validator.git","ssh_url":"git@github.com:Jakeii/express-validator.git","clone_url":"https://github.com/Jakeii/express-validator.git","svn_url":"https://github.com/Jakeii/express-validator","homepage":"","size":264,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"ctavan:master","ref":"master","sha":"eeeb52fcdfd320a6a97161ddfd2b6abb60e6d153","user":{"login":"ctavan","id":508118,"avatar_url":"https://avatars.githubusercontent.com/u/508118?v=3","gravatar_id":"","url":"https://api.github.com/users/ctavan","html_url":"https://github.com/ctavan","followers_url":"https://api.github.com/users/ctavan/followers","following_url":"https://api.github.com/users/ctavan/following{/other_user}","gists_url":"https://api.github.com/users/ctavan/gists{/gist_id}","starred_url":"https://api.github.com/users/ctavan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ctavan/subscriptions","organizations_url":"https://api.github.com/users/ctavan/orgs","repos_url":"https://api.github.com/users/ctavan/repos","events_url":"https://api.github.com/users/ctavan/events{/privacy}","received_events_url":"https://api.github.com/users/ctavan/received_events","type":"User","site_admin":false},"repo":{"id":2518028,"name":"express-validator","full_name":"ctavan/express-validator","owner":{"login":"ctavan","id":508118,"avatar_url":"https://avatars.githubusercontent.com/u/508118?v=3","gravatar_id":"","url":"https://api.github.com/users/ctavan","html_url":"https://github.com/ctavan","followers_url":"https://api.github.com/users/ctavan/followers","following_url":"https://api.github.com/users/ctavan/following{/other_user}","gists_url":"https://api.github.com/users/ctavan/gists{/gist_id}","starred_url":"https://api.github.com/users/ctavan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ctavan/subscriptions","organizations_url":"https://api.github.com/users/ctavan/orgs","repos_url":"https://api.github.com/users/ctavan/repos","events_url":"https://api.github.com/users/ctavan/events{/privacy}","received_events_url":"https://api.github.com/users/ctavan/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ctavan/express-validator","description":"An express.js middleware for node-validator.","fork":false,"url":"https://api.github.com/repos/ctavan/express-validator","forks_url":"https://api.github.com/repos/ctavan/express-validator/forks","keys_url":"https://api.github.com/repos/ctavan/express-validator/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ctavan/express-validator/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ctavan/express-validator/teams","hooks_url":"https://api.github.com/repos/ctavan/express-validator/hooks","issue_events_url":"https://api.github.com/repos/ctavan/express-validator/issues/events{/number}","events_url":"https://api.github.com/repos/ctavan/express-validator/events","assignees_url":"https://api.github.com/repos/ctavan/express-validator/assignees{/user}","branches_url":"https://api.github.com/repos/ctavan/express-validator/branches{/branch}","tags_url":"https://api.github.com/repos/ctavan/express-validator/tags","blobs_url":"https://api.github.com/repos/ctavan/express-validator/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ctavan/express-validator/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ctavan/express-validator/git/refs{/sha}","trees_url":"https://api.github.com/repos/ctavan/express-validator/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ctavan/express-validator/statuses/{sha}","languages_url":"https://api.github.com/repos/ctavan/express-validator/languages","stargazers_url":"https://api.github.com/repos/ctavan/express-validator/stargazers","contributors_url":"https://api.github.com/repos/ctavan/express-validator/contributors","subscribers_url":"https://api.github.com/repos/ctavan/express-validator/subscribers","subscription_url":"https://api.github.com/repos/ctavan/express-validator/subscription","commits_url":"https://api.github.com/repos/ctavan/express-validator/commits{/sha}","git_commits_url":"https://api.github.com/repos/ctavan/express-validator/git/commits{/sha}","comments_url":"https://api.github.com/repos/ctavan/express-validator/comments{/number}","issue_comment_url":"https://api.github.com/repos/ctavan/express-validator/issues/comments{/number}","contents_url":"https://api.github.com/repos/ctavan/express-validator/contents/{+path}","compare_url":"https://api.github.com/repos/ctavan/express-validator/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ctavan/express-validator/merges","archive_url":"https://api.github.com/repos/ctavan/express-validator/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ctavan/express-validator/downloads","issues_url":"https://api.github.com/repos/ctavan/express-validator/issues{/number}","pulls_url":"https://api.github.com/repos/ctavan/express-validator/pulls{/number}","milestones_url":"https://api.github.com/repos/ctavan/express-validator/milestones{/number}","notifications_url":"https://api.github.com/repos/ctavan/express-validator/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ctavan/express-validator/labels{/name}","releases_url":"https://api.github.com/repos/ctavan/express-validator/releases{/id}","created_at":"2011-10-05T09:32:19Z","updated_at":"2015-06-23T12:46:34Z","pushed_at":"2015-06-23T09:47:21Z","git_url":"git://github.com/ctavan/express-validator.git","ssh_url":"git@github.com:ctavan/express-validator.git","clone_url":"https://github.com/ctavan/express-validator.git","svn_url":"https://github.com/ctavan/express-validator","homepage":"","size":1162,"stargazers_count":827,"watchers_count":827,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":129,"mirror_url":null,"open_issues_count":18,"forks":129,"open_issues":18,"watchers":827,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ctavan/express-validator/pulls/145"},"html":{"href":"https://github.com/ctavan/express-validator/pull/145"},"issue":{"href":"https://api.github.com/repos/ctavan/express-validator/issues/145"},"comments":{"href":"https://api.github.com/repos/ctavan/express-validator/issues/145/comments"},"review_comments":{"href":"https://api.github.com/repos/ctavan/express-validator/pulls/145/comments"},"review_comment":{"href":"https://api.github.com/repos/ctavan/express-validator/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ctavan/express-validator/pulls/145/commits"},"statuses":{"href":"https://api.github.com/repos/ctavan/express-validator/statuses/d1c5ec3f35078b2986cbb83ec3977f031c08a2c1"}}}}