{"action":"created","comment":{"url":"https://api.github.com/repos/apache/couchdb-couch-mrview/pulls/comments/40000043","id":40000043,"diff_hunk":"@@ -46,16 +46,103 @@\n }).\n \n \n-validate(DbName, DDoc) ->\n-    {Fields} = DDoc#doc.body,\n-    case couch_util:get_value(<<\"options\">>, Fields, {[]}) of\n-        {_} -> ok;\n-        _ -> throw({invalid_design_doc, <<\"`options` parameter must be an object.\">>})\n+\n+%% Validate \"views\" name : value mapping.\n+%%\n+%% In the most common case name is the view name and\n+%% value is an object that must have a \"map\" function,\n+%% and an optional \"reduce\" function. \"map\" and \"reduce\"\n+%% values should be strings (function contents).\n+%%\n+%% \"lib\" is a special case. The value\n+%% of \"lib\" is an object that will contain libary code\n+%% so it not validated.\n+%%\n+validate_view(<<\"lib\">>, {Libs})->\n+    ok;\n+validate_view(VName, {Views}) ->\n+    case couch_util:get_value(<<\"map\">>, Views) of\n+        MapVal when is_binary(MapVal) ->\n+            ok;\n+        undefined ->\n+            ok;\n+        _ ->\n+            Err1 = <<\"`map` in \", VName/binary, \" must be a string\">>,\n+            throw({invalid_design_doc, Err1})\n     end,\n-    case couch_util:get_value(<<\"views\">>, Fields, {[]}) of\n-        {_} -> ok;\n-        _ -> throw({invalid_design_doc, <<\"`views` parameter must be an object.\">>})\n+    case couch_util:get_value(<<\"reduce\">>, Views) of\n+        RedVal when is_binary(RedVal) ->\n+            ok;\n+        undefined ->\n+            ok; % note: unlike map,  reduce function is optional\n+        _ ->\n+            Err2 = <<\"`reduce` in \", VName/binary, \" must be a string\">>,\n+            throw({invalid_design_doc, Err2})\n     end,\n+    ok;\n+validate_view(VName, _) ->\n+    throw({invalid_design_doc, <<\"View \", VName/binary, \" must be an object\">>}).\n+\n+\n+%% Validate top level design document objects.\n+%%\n+%% Most cases (shows,lists,fitlers,...) will be","path":"src/couch_mrview.erl","position":52,"original_position":52,"commit_id":"3eafcc1924596aa3324ed5ece724980a40ce3866","original_commit_id":"3eafcc1924596aa3324ed5ece724980a40ce3866","user":{"login":"rnewson","id":47223,"avatar_url":"https://avatars.githubusercontent.com/u/47223?v=3","gravatar_id":"","url":"https://api.github.com/users/rnewson","html_url":"https://github.com/rnewson","followers_url":"https://api.github.com/users/rnewson/followers","following_url":"https://api.github.com/users/rnewson/following{/other_user}","gists_url":"https://api.github.com/users/rnewson/gists{/gist_id}","starred_url":"https://api.github.com/users/rnewson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rnewson/subscriptions","organizations_url":"https://api.github.com/users/rnewson/orgs","repos_url":"https://api.github.com/users/rnewson/repos","events_url":"https://api.github.com/users/rnewson/events{/privacy}","received_events_url":"https://api.github.com/users/rnewson/received_events","type":"User","site_admin":false},"body":"typo","created_at":"2015-09-21T17:35:02Z","updated_at":"2015-09-21T17:35:02Z","html_url":"https://github.com/apache/couchdb-couch-mrview/pull/28#discussion_r40000043","pull_request_url":"https://api.github.com/repos/apache/couchdb-couch-mrview/pulls/28","_links":{"self":{"href":"https://api.github.com/repos/apache/couchdb-couch-mrview/pulls/comments/40000043"},"html":{"href":"https://github.com/apache/couchdb-couch-mrview/pull/28#discussion_r40000043"},"pull_request":{"href":"https://api.github.com/repos/apache/couchdb-couch-mrview/pulls/28"}}},"pull_request":{"url":"https://api.github.com/repos/apache/couchdb-couch-mrview/pulls/28","id":45420686,"html_url":"https://github.com/apache/couchdb-couch-mrview/pull/28","diff_url":"https://github.com/apache/couchdb-couch-mrview/pull/28.diff","patch_url":"https://github.com/apache/couchdb-couch-mrview/pull/28.patch","issue_url":"https://api.github.com/repos/apache/couchdb-couch-mrview/issues/28","number":28,"state":"open","locked":false,"title":"Validate design documents.","user":{"login":"nickva","id":211822,"avatar_url":"https://avatars.githubusercontent.com/u/211822?v=3","gravatar_id":"","url":"https://api.github.com/users/nickva","html_url":"https://github.com/nickva","followers_url":"https://api.github.com/users/nickva/followers","following_url":"https://api.github.com/users/nickva/following{/other_user}","gists_url":"https://api.github.com/users/nickva/gists{/gist_id}","starred_url":"https://api.github.com/users/nickva/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nickva/subscriptions","organizations_url":"https://api.github.com/users/nickva/orgs","repos_url":"https://api.github.com/users/nickva/repos","events_url":"https://api.github.com/users/nickva/events{/privacy}","received_events_url":"https://api.github.com/users/nickva/received_events","type":"User","site_admin":false},"body":"Jira: COUCHDB-2818\r\n\r\nValidates:\r\n\r\n  * options,filters,lists,shows,updates,views values at\r\n    top level of document are objects\r\n\r\n  * validate_doc_upate,language are strings\r\n\r\n  * rewrites is an array\r\n\r\n  * each view inside the views object is an object\r\n\r\n  * each view object has a map function that is a string\r\n\r\n  * if a view object has a reduce function it is a string\r\n\r\nOn validation error it returns a 400 error code with exact\r\nreason what field has failed to validate.\r\n\r\nExample:\r\n\r\n```\r\nhttp PUT $DB1/db2/_design/des1 views:='{ \"m\":\"bad\"  }'{\"ok\":true}\r\nHTTP/1.1 400 Bad Request\r\n{\r\n    \"error\": \"invalid_design_doc\",\r\n    \"reason\": \"View m must be an object\"\r\n}\r\n```","created_at":"2015-09-18T15:40:14Z","updated_at":"2015-09-21T17:35:02Z","closed_at":null,"merged_at":null,"merge_commit_sha":"18d1c3ea1ac3912212cd0704cbacf543a0eccc1b","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/couchdb-couch-mrview/pulls/28/commits","review_comments_url":"https://api.github.com/repos/apache/couchdb-couch-mrview/pulls/28/comments","review_comment_url":"https://api.github.com/repos/apache/couchdb-couch-mrview/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/couchdb-couch-mrview/issues/28/comments","statuses_url":"https://api.github.com/repos/apache/couchdb-couch-mrview/statuses/3eafcc1924596aa3324ed5ece724980a40ce3866","head":{"label":"nickva:2818-validate-design-docs","ref":"2818-validate-design-docs","sha":"3eafcc1924596aa3324ed5ece724980a40ce3866","user":{"login":"nickva","id":211822,"avatar_url":"https://avatars.githubusercontent.com/u/211822?v=3","gravatar_id":"","url":"https://api.github.com/users/nickva","html_url":"https://github.com/nickva","followers_url":"https://api.github.com/users/nickva/followers","following_url":"https://api.github.com/users/nickva/following{/other_user}","gists_url":"https://api.github.com/users/nickva/gists{/gist_id}","starred_url":"https://api.github.com/users/nickva/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nickva/subscriptions","organizations_url":"https://api.github.com/users/nickva/orgs","repos_url":"https://api.github.com/users/nickva/repos","events_url":"https://api.github.com/users/nickva/events{/privacy}","received_events_url":"https://api.github.com/users/nickva/received_events","type":"User","site_admin":false},"repo":{"id":42701777,"name":"couchdb-couch-mrview","full_name":"nickva/couchdb-couch-mrview","owner":{"login":"nickva","id":211822,"avatar_url":"https://avatars.githubusercontent.com/u/211822?v=3","gravatar_id":"","url":"https://api.github.com/users/nickva","html_url":"https://github.com/nickva","followers_url":"https://api.github.com/users/nickva/followers","following_url":"https://api.github.com/users/nickva/following{/other_user}","gists_url":"https://api.github.com/users/nickva/gists{/gist_id}","starred_url":"https://api.github.com/users/nickva/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nickva/subscriptions","organizations_url":"https://api.github.com/users/nickva/orgs","repos_url":"https://api.github.com/users/nickva/repos","events_url":"https://api.github.com/users/nickva/events{/privacy}","received_events_url":"https://api.github.com/users/nickva/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/nickva/couchdb-couch-mrview","description":"Mirror of Apache CouchDB","fork":true,"url":"https://api.github.com/repos/nickva/couchdb-couch-mrview","forks_url":"https://api.github.com/repos/nickva/couchdb-couch-mrview/forks","keys_url":"https://api.github.com/repos/nickva/couchdb-couch-mrview/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nickva/couchdb-couch-mrview/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nickva/couchdb-couch-mrview/teams","hooks_url":"https://api.github.com/repos/nickva/couchdb-couch-mrview/hooks","issue_events_url":"https://api.github.com/repos/nickva/couchdb-couch-mrview/issues/events{/number}","events_url":"https://api.github.com/repos/nickva/couchdb-couch-mrview/events","assignees_url":"https://api.github.com/repos/nickva/couchdb-couch-mrview/assignees{/user}","branches_url":"https://api.github.com/repos/nickva/couchdb-couch-mrview/branches{/branch}","tags_url":"https://api.github.com/repos/nickva/couchdb-couch-mrview/tags","blobs_url":"https://api.github.com/repos/nickva/couchdb-couch-mrview/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nickva/couchdb-couch-mrview/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nickva/couchdb-couch-mrview/git/refs{/sha}","trees_url":"https://api.github.com/repos/nickva/couchdb-couch-mrview/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nickva/couchdb-couch-mrview/statuses/{sha}","languages_url":"https://api.github.com/repos/nickva/couchdb-couch-mrview/languages","stargazers_url":"https://api.github.com/repos/nickva/couchdb-couch-mrview/stargazers","contributors_url":"https://api.github.com/repos/nickva/couchdb-couch-mrview/contributors","subscribers_url":"https://api.github.com/repos/nickva/couchdb-couch-mrview/subscribers","subscription_url":"https://api.github.com/repos/nickva/couchdb-couch-mrview/subscription","commits_url":"https://api.github.com/repos/nickva/couchdb-couch-mrview/commits{/sha}","git_commits_url":"https://api.github.com/repos/nickva/couchdb-couch-mrview/git/commits{/sha}","comments_url":"https://api.github.com/repos/nickva/couchdb-couch-mrview/comments{/number}","issue_comment_url":"https://api.github.com/repos/nickva/couchdb-couch-mrview/issues/comments{/number}","contents_url":"https://api.github.com/repos/nickva/couchdb-couch-mrview/contents/{+path}","compare_url":"https://api.github.com/repos/nickva/couchdb-couch-mrview/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nickva/couchdb-couch-mrview/merges","archive_url":"https://api.github.com/repos/nickva/couchdb-couch-mrview/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nickva/couchdb-couch-mrview/downloads","issues_url":"https://api.github.com/repos/nickva/couchdb-couch-mrview/issues{/number}","pulls_url":"https://api.github.com/repos/nickva/couchdb-couch-mrview/pulls{/number}","milestones_url":"https://api.github.com/repos/nickva/couchdb-couch-mrview/milestones{/number}","notifications_url":"https://api.github.com/repos/nickva/couchdb-couch-mrview/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nickva/couchdb-couch-mrview/labels{/name}","releases_url":"https://api.github.com/repos/nickva/couchdb-couch-mrview/releases{/id}","created_at":"2015-09-18T05:33:38Z","updated_at":"2015-09-18T05:33:39Z","pushed_at":"2015-09-19T15:19:47Z","git_url":"git://github.com/nickva/couchdb-couch-mrview.git","ssh_url":"git@github.com:nickva/couchdb-couch-mrview.git","clone_url":"https://github.com/nickva/couchdb-couch-mrview.git","svn_url":"https://github.com/nickva/couchdb-couch-mrview","homepage":null,"size":918,"stargazers_count":0,"watchers_count":0,"language":"Erlang","has_issues":false,"has_downloads":true,"has_wiki":false,"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":"apache:master","ref":"master","sha":"95cbd7b2a0f2dd2f838d995fc0d677e48436b9bb","user":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"repo":{"id":15993604,"name":"couchdb-couch-mrview","full_name":"apache/couchdb-couch-mrview","owner":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apache/couchdb-couch-mrview","description":"Mirror of Apache CouchDB","fork":false,"url":"https://api.github.com/repos/apache/couchdb-couch-mrview","forks_url":"https://api.github.com/repos/apache/couchdb-couch-mrview/forks","keys_url":"https://api.github.com/repos/apache/couchdb-couch-mrview/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/couchdb-couch-mrview/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/couchdb-couch-mrview/teams","hooks_url":"https://api.github.com/repos/apache/couchdb-couch-mrview/hooks","issue_events_url":"https://api.github.com/repos/apache/couchdb-couch-mrview/issues/events{/number}","events_url":"https://api.github.com/repos/apache/couchdb-couch-mrview/events","assignees_url":"https://api.github.com/repos/apache/couchdb-couch-mrview/assignees{/user}","branches_url":"https://api.github.com/repos/apache/couchdb-couch-mrview/branches{/branch}","tags_url":"https://api.github.com/repos/apache/couchdb-couch-mrview/tags","blobs_url":"https://api.github.com/repos/apache/couchdb-couch-mrview/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/couchdb-couch-mrview/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/couchdb-couch-mrview/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/couchdb-couch-mrview/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/couchdb-couch-mrview/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/couchdb-couch-mrview/languages","stargazers_url":"https://api.github.com/repos/apache/couchdb-couch-mrview/stargazers","contributors_url":"https://api.github.com/repos/apache/couchdb-couch-mrview/contributors","subscribers_url":"https://api.github.com/repos/apache/couchdb-couch-mrview/subscribers","subscription_url":"https://api.github.com/repos/apache/couchdb-couch-mrview/subscription","commits_url":"https://api.github.com/repos/apache/couchdb-couch-mrview/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/couchdb-couch-mrview/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/couchdb-couch-mrview/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/couchdb-couch-mrview/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/couchdb-couch-mrview/contents/{+path}","compare_url":"https://api.github.com/repos/apache/couchdb-couch-mrview/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/couchdb-couch-mrview/merges","archive_url":"https://api.github.com/repos/apache/couchdb-couch-mrview/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/couchdb-couch-mrview/downloads","issues_url":"https://api.github.com/repos/apache/couchdb-couch-mrview/issues{/number}","pulls_url":"https://api.github.com/repos/apache/couchdb-couch-mrview/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/couchdb-couch-mrview/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/couchdb-couch-mrview/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/couchdb-couch-mrview/labels{/name}","releases_url":"https://api.github.com/repos/apache/couchdb-couch-mrview/releases{/id}","created_at":"2014-01-17T08:00:07Z","updated_at":"2015-04-23T20:44:22Z","pushed_at":"2015-09-19T15:19:48Z","git_url":"git://github.com/apache/couchdb-couch-mrview.git","ssh_url":"git@github.com:apache/couchdb-couch-mrview.git","clone_url":"https://github.com/apache/couchdb-couch-mrview.git","svn_url":"https://github.com/apache/couchdb-couch-mrview","homepage":null,"size":918,"stargazers_count":4,"watchers_count":4,"language":"Erlang","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":14,"mirror_url":"git://git.apache.org/couchdb-couch-mrview.git","open_issues_count":4,"forks":14,"open_issues":4,"watchers":4,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/couchdb-couch-mrview/pulls/28"},"html":{"href":"https://github.com/apache/couchdb-couch-mrview/pull/28"},"issue":{"href":"https://api.github.com/repos/apache/couchdb-couch-mrview/issues/28"},"comments":{"href":"https://api.github.com/repos/apache/couchdb-couch-mrview/issues/28/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/couchdb-couch-mrview/pulls/28/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/couchdb-couch-mrview/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/couchdb-couch-mrview/pulls/28/commits"},"statuses":{"href":"https://api.github.com/repos/apache/couchdb-couch-mrview/statuses/3eafcc1924596aa3324ed5ece724980a40ce3866"}}}}