{"action":"created","comment":{"url":"https://api.github.com/repos/strongloop/generator-loopback/pulls/comments/66616297","id":66616297,"diff_hunk":"@@ -166,3 +156,68 @@ module.exports = yeoman.generators.Base.extend({\n \n   saveProject: actions.saveProject\n });\n+\n+function coerceDefault(def, value) {\n+  var isSupported = typeChoices.indexOf(def.type) !== -1;\n+  debug('property type \"%s\" >> supported: %s', def.type, isSupported);\n+\n+  if (typeof value === 'string' && isSupported) {\n+    switch ((def.type || '').toLowerCase()) {\n+      case 'string':\n+        if (value === 'uuid' || value === 'guid'){\n+          def.defaultFn = value;\n+        } else {\n+          def.default = value;\n+        }\n+        break;\n+      case 'number':\n+        def.default = Number(value);\n+        break;\n+      case 'boolean':\n+        if (['true', '1', 't'].indexOf(value) !== -1 ){\n+          def.default = true;\n+        } else {\n+          def.default = false;\n+        }\n+        break;\n+      case 'object':\n+        def.default = JSON.parse(value);\n+        break;\n+      case 'array':\n+        def.default = value.replace(/[\\s,]+/g, ',').split(',');","path":"property/index.js","position":66,"original_position":66,"commit_id":"0c1c9bf9d56cfe8a56fcd93af25b9b454be93e77","original_commit_id":"0c1c9bf9d56cfe8a56fcd93af25b9b454be93e77","user":{"login":"bajtos","id":1140553,"avatar_url":"https://avatars.githubusercontent.com/u/1140553?v=3","gravatar_id":"","url":"https://api.github.com/users/bajtos","html_url":"https://github.com/bajtos","followers_url":"https://api.github.com/users/bajtos/followers","following_url":"https://api.github.com/users/bajtos/following{/other_user}","gists_url":"https://api.github.com/users/bajtos/gists{/gist_id}","starred_url":"https://api.github.com/users/bajtos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bajtos/subscriptions","organizations_url":"https://api.github.com/users/bajtos/orgs","repos_url":"https://api.github.com/users/bajtos/repos","events_url":"https://api.github.com/users/bajtos/events{/privacy}","received_events_url":"https://api.github.com/users/bajtos/received_events","type":"User","site_admin":false},"body":"IIRC, when the user specifies `array` type, we ask them to provide `itemType` too. We should coerce array items of the default value depending on `itemType`. For example, when users selects \"array of numbers\" and provide default value `1,2`, then we should set the default value to `[1,2]` instead of `[\"1\",\"2\"]`.","created_at":"2016-06-10T13:54:02Z","updated_at":"2016-06-10T13:54:02Z","html_url":"https://github.com/strongloop/generator-loopback/pull/200#discussion_r66616297","pull_request_url":"https://api.github.com/repos/strongloop/generator-loopback/pulls/200","_links":{"self":{"href":"https://api.github.com/repos/strongloop/generator-loopback/pulls/comments/66616297"},"html":{"href":"https://github.com/strongloop/generator-loopback/pull/200#discussion_r66616297"},"pull_request":{"href":"https://api.github.com/repos/strongloop/generator-loopback/pulls/200"}}},"pull_request":{"url":"https://api.github.com/repos/strongloop/generator-loopback/pulls/200","id":73124812,"html_url":"https://github.com/strongloop/generator-loopback/pull/200","diff_url":"https://github.com/strongloop/generator-loopback/pull/200.diff","patch_url":"https://github.com/strongloop/generator-loopback/pull/200.patch","issue_url":"https://api.github.com/repos/strongloop/generator-loopback/issues/200","number":200,"state":"open","locked":false,"title":"Validate the default-value type of a model property","user":{"login":"alexpit","id":18721610,"avatar_url":"https://avatars.githubusercontent.com/u/18721610?v=3","gravatar_id":"","url":"https://api.github.com/users/alexpit","html_url":"https://github.com/alexpit","followers_url":"https://api.github.com/users/alexpit/followers","following_url":"https://api.github.com/users/alexpit/following{/other_user}","gists_url":"https://api.github.com/users/alexpit/gists{/gist_id}","starred_url":"https://api.github.com/users/alexpit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexpit/subscriptions","organizations_url":"https://api.github.com/users/alexpit/orgs","repos_url":"https://api.github.com/users/alexpit/repos","events_url":"https://api.github.com/users/alexpit/events{/privacy}","received_events_url":"https://api.github.com/users/alexpit/received_events","type":"User","site_admin":false},"body":"connect to #185","created_at":"2016-06-08T21:37:19Z","updated_at":"2016-06-10T13:54:02Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d67de463152008000e5beb9f92be827d5f3ffb50","assignee":{"login":"richardpringle","id":3286504,"avatar_url":"https://avatars.githubusercontent.com/u/3286504?v=3","gravatar_id":"","url":"https://api.github.com/users/richardpringle","html_url":"https://github.com/richardpringle","followers_url":"https://api.github.com/users/richardpringle/followers","following_url":"https://api.github.com/users/richardpringle/following{/other_user}","gists_url":"https://api.github.com/users/richardpringle/gists{/gist_id}","starred_url":"https://api.github.com/users/richardpringle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/richardpringle/subscriptions","organizations_url":"https://api.github.com/users/richardpringle/orgs","repos_url":"https://api.github.com/users/richardpringle/repos","events_url":"https://api.github.com/users/richardpringle/events{/privacy}","received_events_url":"https://api.github.com/users/richardpringle/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/strongloop/generator-loopback/pulls/200/commits","review_comments_url":"https://api.github.com/repos/strongloop/generator-loopback/pulls/200/comments","review_comment_url":"https://api.github.com/repos/strongloop/generator-loopback/pulls/comments{/number}","comments_url":"https://api.github.com/repos/strongloop/generator-loopback/issues/200/comments","statuses_url":"https://api.github.com/repos/strongloop/generator-loopback/statuses/0c1c9bf9d56cfe8a56fcd93af25b9b454be93e77","head":{"label":"strongloop:fix-gen-default","ref":"fix-gen-default","sha":"0c1c9bf9d56cfe8a56fcd93af25b9b454be93e77","user":{"login":"strongloop","id":3020012,"avatar_url":"https://avatars.githubusercontent.com/u/3020012?v=3","gravatar_id":"","url":"https://api.github.com/users/strongloop","html_url":"https://github.com/strongloop","followers_url":"https://api.github.com/users/strongloop/followers","following_url":"https://api.github.com/users/strongloop/following{/other_user}","gists_url":"https://api.github.com/users/strongloop/gists{/gist_id}","starred_url":"https://api.github.com/users/strongloop/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/strongloop/subscriptions","organizations_url":"https://api.github.com/users/strongloop/orgs","repos_url":"https://api.github.com/users/strongloop/repos","events_url":"https://api.github.com/users/strongloop/events{/privacy}","received_events_url":"https://api.github.com/users/strongloop/received_events","type":"Organization","site_admin":false},"repo":{"id":19692503,"name":"generator-loopback","full_name":"strongloop/generator-loopback","owner":{"login":"strongloop","id":3020012,"avatar_url":"https://avatars.githubusercontent.com/u/3020012?v=3","gravatar_id":"","url":"https://api.github.com/users/strongloop","html_url":"https://github.com/strongloop","followers_url":"https://api.github.com/users/strongloop/followers","following_url":"https://api.github.com/users/strongloop/following{/other_user}","gists_url":"https://api.github.com/users/strongloop/gists{/gist_id}","starred_url":"https://api.github.com/users/strongloop/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/strongloop/subscriptions","organizations_url":"https://api.github.com/users/strongloop/orgs","repos_url":"https://api.github.com/users/strongloop/repos","events_url":"https://api.github.com/users/strongloop/events{/privacy}","received_events_url":"https://api.github.com/users/strongloop/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/strongloop/generator-loopback","description":"Yeoman generator that scaffolds out a LoopBack application","fork":false,"url":"https://api.github.com/repos/strongloop/generator-loopback","forks_url":"https://api.github.com/repos/strongloop/generator-loopback/forks","keys_url":"https://api.github.com/repos/strongloop/generator-loopback/keys{/key_id}","collaborators_url":"https://api.github.com/repos/strongloop/generator-loopback/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/strongloop/generator-loopback/teams","hooks_url":"https://api.github.com/repos/strongloop/generator-loopback/hooks","issue_events_url":"https://api.github.com/repos/strongloop/generator-loopback/issues/events{/number}","events_url":"https://api.github.com/repos/strongloop/generator-loopback/events","assignees_url":"https://api.github.com/repos/strongloop/generator-loopback/assignees{/user}","branches_url":"https://api.github.com/repos/strongloop/generator-loopback/branches{/branch}","tags_url":"https://api.github.com/repos/strongloop/generator-loopback/tags","blobs_url":"https://api.github.com/repos/strongloop/generator-loopback/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/strongloop/generator-loopback/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/strongloop/generator-loopback/git/refs{/sha}","trees_url":"https://api.github.com/repos/strongloop/generator-loopback/git/trees{/sha}","statuses_url":"https://api.github.com/repos/strongloop/generator-loopback/statuses/{sha}","languages_url":"https://api.github.com/repos/strongloop/generator-loopback/languages","stargazers_url":"https://api.github.com/repos/strongloop/generator-loopback/stargazers","contributors_url":"https://api.github.com/repos/strongloop/generator-loopback/contributors","subscribers_url":"https://api.github.com/repos/strongloop/generator-loopback/subscribers","subscription_url":"https://api.github.com/repos/strongloop/generator-loopback/subscription","commits_url":"https://api.github.com/repos/strongloop/generator-loopback/commits{/sha}","git_commits_url":"https://api.github.com/repos/strongloop/generator-loopback/git/commits{/sha}","comments_url":"https://api.github.com/repos/strongloop/generator-loopback/comments{/number}","issue_comment_url":"https://api.github.com/repos/strongloop/generator-loopback/issues/comments{/number}","contents_url":"https://api.github.com/repos/strongloop/generator-loopback/contents/{+path}","compare_url":"https://api.github.com/repos/strongloop/generator-loopback/compare/{base}...{head}","merges_url":"https://api.github.com/repos/strongloop/generator-loopback/merges","archive_url":"https://api.github.com/repos/strongloop/generator-loopback/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/strongloop/generator-loopback/downloads","issues_url":"https://api.github.com/repos/strongloop/generator-loopback/issues{/number}","pulls_url":"https://api.github.com/repos/strongloop/generator-loopback/pulls{/number}","milestones_url":"https://api.github.com/repos/strongloop/generator-loopback/milestones{/number}","notifications_url":"https://api.github.com/repos/strongloop/generator-loopback/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/strongloop/generator-loopback/labels{/name}","releases_url":"https://api.github.com/repos/strongloop/generator-loopback/releases{/id}","deployments_url":"https://api.github.com/repos/strongloop/generator-loopback/deployments","created_at":"2014-05-12T09:15:28Z","updated_at":"2016-06-04T02:26:43Z","pushed_at":"2016-06-10T12:29:07Z","git_url":"git://github.com/strongloop/generator-loopback.git","ssh_url":"git@github.com:strongloop/generator-loopback.git","clone_url":"https://github.com/strongloop/generator-loopback.git","svn_url":"https://github.com/strongloop/generator-loopback","homepage":"http://loopback.io","size":1462,"stargazers_count":77,"watchers_count":77,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":34,"mirror_url":null,"open_issues_count":33,"forks":34,"open_issues":33,"watchers":77,"default_branch":"master"}},"base":{"label":"strongloop:master","ref":"master","sha":"f257078b4f340434b0bcfc201d2758861733a7c7","user":{"login":"strongloop","id":3020012,"avatar_url":"https://avatars.githubusercontent.com/u/3020012?v=3","gravatar_id":"","url":"https://api.github.com/users/strongloop","html_url":"https://github.com/strongloop","followers_url":"https://api.github.com/users/strongloop/followers","following_url":"https://api.github.com/users/strongloop/following{/other_user}","gists_url":"https://api.github.com/users/strongloop/gists{/gist_id}","starred_url":"https://api.github.com/users/strongloop/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/strongloop/subscriptions","organizations_url":"https://api.github.com/users/strongloop/orgs","repos_url":"https://api.github.com/users/strongloop/repos","events_url":"https://api.github.com/users/strongloop/events{/privacy}","received_events_url":"https://api.github.com/users/strongloop/received_events","type":"Organization","site_admin":false},"repo":{"id":19692503,"name":"generator-loopback","full_name":"strongloop/generator-loopback","owner":{"login":"strongloop","id":3020012,"avatar_url":"https://avatars.githubusercontent.com/u/3020012?v=3","gravatar_id":"","url":"https://api.github.com/users/strongloop","html_url":"https://github.com/strongloop","followers_url":"https://api.github.com/users/strongloop/followers","following_url":"https://api.github.com/users/strongloop/following{/other_user}","gists_url":"https://api.github.com/users/strongloop/gists{/gist_id}","starred_url":"https://api.github.com/users/strongloop/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/strongloop/subscriptions","organizations_url":"https://api.github.com/users/strongloop/orgs","repos_url":"https://api.github.com/users/strongloop/repos","events_url":"https://api.github.com/users/strongloop/events{/privacy}","received_events_url":"https://api.github.com/users/strongloop/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/strongloop/generator-loopback","description":"Yeoman generator that scaffolds out a LoopBack application","fork":false,"url":"https://api.github.com/repos/strongloop/generator-loopback","forks_url":"https://api.github.com/repos/strongloop/generator-loopback/forks","keys_url":"https://api.github.com/repos/strongloop/generator-loopback/keys{/key_id}","collaborators_url":"https://api.github.com/repos/strongloop/generator-loopback/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/strongloop/generator-loopback/teams","hooks_url":"https://api.github.com/repos/strongloop/generator-loopback/hooks","issue_events_url":"https://api.github.com/repos/strongloop/generator-loopback/issues/events{/number}","events_url":"https://api.github.com/repos/strongloop/generator-loopback/events","assignees_url":"https://api.github.com/repos/strongloop/generator-loopback/assignees{/user}","branches_url":"https://api.github.com/repos/strongloop/generator-loopback/branches{/branch}","tags_url":"https://api.github.com/repos/strongloop/generator-loopback/tags","blobs_url":"https://api.github.com/repos/strongloop/generator-loopback/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/strongloop/generator-loopback/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/strongloop/generator-loopback/git/refs{/sha}","trees_url":"https://api.github.com/repos/strongloop/generator-loopback/git/trees{/sha}","statuses_url":"https://api.github.com/repos/strongloop/generator-loopback/statuses/{sha}","languages_url":"https://api.github.com/repos/strongloop/generator-loopback/languages","stargazers_url":"https://api.github.com/repos/strongloop/generator-loopback/stargazers","contributors_url":"https://api.github.com/repos/strongloop/generator-loopback/contributors","subscribers_url":"https://api.github.com/repos/strongloop/generator-loopback/subscribers","subscription_url":"https://api.github.com/repos/strongloop/generator-loopback/subscription","commits_url":"https://api.github.com/repos/strongloop/generator-loopback/commits{/sha}","git_commits_url":"https://api.github.com/repos/strongloop/generator-loopback/git/commits{/sha}","comments_url":"https://api.github.com/repos/strongloop/generator-loopback/comments{/number}","issue_comment_url":"https://api.github.com/repos/strongloop/generator-loopback/issues/comments{/number}","contents_url":"https://api.github.com/repos/strongloop/generator-loopback/contents/{+path}","compare_url":"https://api.github.com/repos/strongloop/generator-loopback/compare/{base}...{head}","merges_url":"https://api.github.com/repos/strongloop/generator-loopback/merges","archive_url":"https://api.github.com/repos/strongloop/generator-loopback/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/strongloop/generator-loopback/downloads","issues_url":"https://api.github.com/repos/strongloop/generator-loopback/issues{/number}","pulls_url":"https://api.github.com/repos/strongloop/generator-loopback/pulls{/number}","milestones_url":"https://api.github.com/repos/strongloop/generator-loopback/milestones{/number}","notifications_url":"https://api.github.com/repos/strongloop/generator-loopback/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/strongloop/generator-loopback/labels{/name}","releases_url":"https://api.github.com/repos/strongloop/generator-loopback/releases{/id}","deployments_url":"https://api.github.com/repos/strongloop/generator-loopback/deployments","created_at":"2014-05-12T09:15:28Z","updated_at":"2016-06-04T02:26:43Z","pushed_at":"2016-06-10T12:29:07Z","git_url":"git://github.com/strongloop/generator-loopback.git","ssh_url":"git@github.com:strongloop/generator-loopback.git","clone_url":"https://github.com/strongloop/generator-loopback.git","svn_url":"https://github.com/strongloop/generator-loopback","homepage":"http://loopback.io","size":1462,"stargazers_count":77,"watchers_count":77,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":34,"mirror_url":null,"open_issues_count":33,"forks":34,"open_issues":33,"watchers":77,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/strongloop/generator-loopback/pulls/200"},"html":{"href":"https://github.com/strongloop/generator-loopback/pull/200"},"issue":{"href":"https://api.github.com/repos/strongloop/generator-loopback/issues/200"},"comments":{"href":"https://api.github.com/repos/strongloop/generator-loopback/issues/200/comments"},"review_comments":{"href":"https://api.github.com/repos/strongloop/generator-loopback/pulls/200/comments"},"review_comment":{"href":"https://api.github.com/repos/strongloop/generator-loopback/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/strongloop/generator-loopback/pulls/200/commits"},"statuses":{"href":"https://api.github.com/repos/strongloop/generator-loopback/statuses/0c1c9bf9d56cfe8a56fcd93af25b9b454be93e77"}}}}
{"actor":{"display_login":"bajtos"}}