{"action":"opened","number":1126,"pull_request":{"url":"https://api.github.com/repos/phoenixframework/phoenix/pulls/1126","id":42422484,"html_url":"https://github.com/phoenixframework/phoenix/pull/1126","diff_url":"https://github.com/phoenixframework/phoenix/pull/1126.diff","patch_url":"https://github.com/phoenixframework/phoenix/pull/1126.patch","issue_url":"https://api.github.com/repos/phoenixframework/phoenix/issues/1126","number":1126,"state":"open","locked":false,"title":"Include generated model fields in JSON output","user":{"login":"dmarkow","id":8009,"avatar_url":"https://avatars.githubusercontent.com/u/8009?v=3","gravatar_id":"","url":"https://api.github.com/users/dmarkow","html_url":"https://github.com/dmarkow","followers_url":"https://api.github.com/users/dmarkow/followers","following_url":"https://api.github.com/users/dmarkow/following{/other_user}","gists_url":"https://api.github.com/users/dmarkow/gists{/gist_id}","starred_url":"https://api.github.com/users/dmarkow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dmarkow/subscriptions","organizations_url":"https://api.github.com/users/dmarkow/orgs","repos_url":"https://api.github.com/users/dmarkow/repos","events_url":"https://api.github.com/users/dmarkow/events{/privacy}","received_events_url":"https://api.github.com/users/dmarkow/received_events","type":"User","site_admin":false},"body":"Addresses #1125.\r\n\r\nThis will include generated fields in the default JSON output. So if you run `mix phoenix.gen.json User users name:string email:string` you'll get the following in the `web/views/user_view.ex` file:\r\n\r\n```elixir\r\ndef render(\"user.json\", %{user: user}) do\r\n  %{\r\n    id: user.id,\r\n    name: user.name,\r\n    email: user.email\r\n  }\r\nend\r\n```\r\n\r\nI added tests similar to how the HTML generator did it (it didn't explicitly check for all fields, just one of them). \r\n\r\nI opted to build the list of fields in the generator itself instead of iterating inside the template as I found it easier to get clean output without extra whitespace, without an errant comma after the last field, etc. This also gracefully handles the case where the user doesn't provide any fields (e.g. `mix phoenix.gen.json User users`).\r\n\r\nLet me know if I should approach this differently; any feedback is welcome. Thanks!\r\n","created_at":"2015-08-14T04:02:57Z","updated_at":"2015-08-14T04:02:57Z","closed_at":null,"merged_at":null,"merge_commit_sha":null,"assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/phoenixframework/phoenix/pulls/1126/commits","review_comments_url":"https://api.github.com/repos/phoenixframework/phoenix/pulls/1126/comments","review_comment_url":"https://api.github.com/repos/phoenixframework/phoenix/pulls/comments{/number}","comments_url":"https://api.github.com/repos/phoenixframework/phoenix/issues/1126/comments","statuses_url":"https://api.github.com/repos/phoenixframework/phoenix/statuses/a1542ce23364ec3921a05fe1c49654f34a4909c5","head":{"label":"dmarkow:json-fields","ref":"json-fields","sha":"a1542ce23364ec3921a05fe1c49654f34a4909c5","user":{"login":"dmarkow","id":8009,"avatar_url":"https://avatars.githubusercontent.com/u/8009?v=3","gravatar_id":"","url":"https://api.github.com/users/dmarkow","html_url":"https://github.com/dmarkow","followers_url":"https://api.github.com/users/dmarkow/followers","following_url":"https://api.github.com/users/dmarkow/following{/other_user}","gists_url":"https://api.github.com/users/dmarkow/gists{/gist_id}","starred_url":"https://api.github.com/users/dmarkow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dmarkow/subscriptions","organizations_url":"https://api.github.com/users/dmarkow/orgs","repos_url":"https://api.github.com/users/dmarkow/repos","events_url":"https://api.github.com/users/dmarkow/events{/privacy}","received_events_url":"https://api.github.com/users/dmarkow/received_events","type":"User","site_admin":false},"repo":{"id":40692611,"name":"phoenix","full_name":"dmarkow/phoenix","owner":{"login":"dmarkow","id":8009,"avatar_url":"https://avatars.githubusercontent.com/u/8009?v=3","gravatar_id":"","url":"https://api.github.com/users/dmarkow","html_url":"https://github.com/dmarkow","followers_url":"https://api.github.com/users/dmarkow/followers","following_url":"https://api.github.com/users/dmarkow/following{/other_user}","gists_url":"https://api.github.com/users/dmarkow/gists{/gist_id}","starred_url":"https://api.github.com/users/dmarkow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dmarkow/subscriptions","organizations_url":"https://api.github.com/users/dmarkow/orgs","repos_url":"https://api.github.com/users/dmarkow/repos","events_url":"https://api.github.com/users/dmarkow/events{/privacy}","received_events_url":"https://api.github.com/users/dmarkow/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/dmarkow/phoenix","description":"Productive. Reliable. Fast.","fork":true,"url":"https://api.github.com/repos/dmarkow/phoenix","forks_url":"https://api.github.com/repos/dmarkow/phoenix/forks","keys_url":"https://api.github.com/repos/dmarkow/phoenix/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dmarkow/phoenix/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dmarkow/phoenix/teams","hooks_url":"https://api.github.com/repos/dmarkow/phoenix/hooks","issue_events_url":"https://api.github.com/repos/dmarkow/phoenix/issues/events{/number}","events_url":"https://api.github.com/repos/dmarkow/phoenix/events","assignees_url":"https://api.github.com/repos/dmarkow/phoenix/assignees{/user}","branches_url":"https://api.github.com/repos/dmarkow/phoenix/branches{/branch}","tags_url":"https://api.github.com/repos/dmarkow/phoenix/tags","blobs_url":"https://api.github.com/repos/dmarkow/phoenix/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dmarkow/phoenix/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dmarkow/phoenix/git/refs{/sha}","trees_url":"https://api.github.com/repos/dmarkow/phoenix/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dmarkow/phoenix/statuses/{sha}","languages_url":"https://api.github.com/repos/dmarkow/phoenix/languages","stargazers_url":"https://api.github.com/repos/dmarkow/phoenix/stargazers","contributors_url":"https://api.github.com/repos/dmarkow/phoenix/contributors","subscribers_url":"https://api.github.com/repos/dmarkow/phoenix/subscribers","subscription_url":"https://api.github.com/repos/dmarkow/phoenix/subscription","commits_url":"https://api.github.com/repos/dmarkow/phoenix/commits{/sha}","git_commits_url":"https://api.github.com/repos/dmarkow/phoenix/git/commits{/sha}","comments_url":"https://api.github.com/repos/dmarkow/phoenix/comments{/number}","issue_comment_url":"https://api.github.com/repos/dmarkow/phoenix/issues/comments{/number}","contents_url":"https://api.github.com/repos/dmarkow/phoenix/contents/{+path}","compare_url":"https://api.github.com/repos/dmarkow/phoenix/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dmarkow/phoenix/merges","archive_url":"https://api.github.com/repos/dmarkow/phoenix/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dmarkow/phoenix/downloads","issues_url":"https://api.github.com/repos/dmarkow/phoenix/issues{/number}","pulls_url":"https://api.github.com/repos/dmarkow/phoenix/pulls{/number}","milestones_url":"https://api.github.com/repos/dmarkow/phoenix/milestones{/number}","notifications_url":"https://api.github.com/repos/dmarkow/phoenix/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dmarkow/phoenix/labels{/name}","releases_url":"https://api.github.com/repos/dmarkow/phoenix/releases{/id}","created_at":"2015-08-14T02:52:06Z","updated_at":"2015-08-14T02:52:06Z","pushed_at":"2015-08-14T03:53:16Z","git_url":"git://github.com/dmarkow/phoenix.git","ssh_url":"git@github.com:dmarkow/phoenix.git","clone_url":"https://github.com/dmarkow/phoenix.git","svn_url":"https://github.com/dmarkow/phoenix","homepage":"http://www.phoenixframework.org","size":9806,"stargazers_count":0,"watchers_count":0,"language":"Elixir","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":"phoenixframework:master","ref":"master","sha":"3fe31179631f921da39f3057ee1ff77a8a89a441","user":{"login":"phoenixframework","id":6510388,"avatar_url":"https://avatars.githubusercontent.com/u/6510388?v=3","gravatar_id":"","url":"https://api.github.com/users/phoenixframework","html_url":"https://github.com/phoenixframework","followers_url":"https://api.github.com/users/phoenixframework/followers","following_url":"https://api.github.com/users/phoenixframework/following{/other_user}","gists_url":"https://api.github.com/users/phoenixframework/gists{/gist_id}","starred_url":"https://api.github.com/users/phoenixframework/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phoenixframework/subscriptions","organizations_url":"https://api.github.com/users/phoenixframework/orgs","repos_url":"https://api.github.com/users/phoenixframework/repos","events_url":"https://api.github.com/users/phoenixframework/events{/privacy}","received_events_url":"https://api.github.com/users/phoenixframework/received_events","type":"Organization","site_admin":false},"repo":{"id":16072585,"name":"phoenix","full_name":"phoenixframework/phoenix","owner":{"login":"phoenixframework","id":6510388,"avatar_url":"https://avatars.githubusercontent.com/u/6510388?v=3","gravatar_id":"","url":"https://api.github.com/users/phoenixframework","html_url":"https://github.com/phoenixframework","followers_url":"https://api.github.com/users/phoenixframework/followers","following_url":"https://api.github.com/users/phoenixframework/following{/other_user}","gists_url":"https://api.github.com/users/phoenixframework/gists{/gist_id}","starred_url":"https://api.github.com/users/phoenixframework/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phoenixframework/subscriptions","organizations_url":"https://api.github.com/users/phoenixframework/orgs","repos_url":"https://api.github.com/users/phoenixframework/repos","events_url":"https://api.github.com/users/phoenixframework/events{/privacy}","received_events_url":"https://api.github.com/users/phoenixframework/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/phoenixframework/phoenix","description":"Productive. Reliable. Fast.","fork":false,"url":"https://api.github.com/repos/phoenixframework/phoenix","forks_url":"https://api.github.com/repos/phoenixframework/phoenix/forks","keys_url":"https://api.github.com/repos/phoenixframework/phoenix/keys{/key_id}","collaborators_url":"https://api.github.com/repos/phoenixframework/phoenix/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/phoenixframework/phoenix/teams","hooks_url":"https://api.github.com/repos/phoenixframework/phoenix/hooks","issue_events_url":"https://api.github.com/repos/phoenixframework/phoenix/issues/events{/number}","events_url":"https://api.github.com/repos/phoenixframework/phoenix/events","assignees_url":"https://api.github.com/repos/phoenixframework/phoenix/assignees{/user}","branches_url":"https://api.github.com/repos/phoenixframework/phoenix/branches{/branch}","tags_url":"https://api.github.com/repos/phoenixframework/phoenix/tags","blobs_url":"https://api.github.com/repos/phoenixframework/phoenix/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/phoenixframework/phoenix/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/phoenixframework/phoenix/git/refs{/sha}","trees_url":"https://api.github.com/repos/phoenixframework/phoenix/git/trees{/sha}","statuses_url":"https://api.github.com/repos/phoenixframework/phoenix/statuses/{sha}","languages_url":"https://api.github.com/repos/phoenixframework/phoenix/languages","stargazers_url":"https://api.github.com/repos/phoenixframework/phoenix/stargazers","contributors_url":"https://api.github.com/repos/phoenixframework/phoenix/contributors","subscribers_url":"https://api.github.com/repos/phoenixframework/phoenix/subscribers","subscription_url":"https://api.github.com/repos/phoenixframework/phoenix/subscription","commits_url":"https://api.github.com/repos/phoenixframework/phoenix/commits{/sha}","git_commits_url":"https://api.github.com/repos/phoenixframework/phoenix/git/commits{/sha}","comments_url":"https://api.github.com/repos/phoenixframework/phoenix/comments{/number}","issue_comment_url":"https://api.github.com/repos/phoenixframework/phoenix/issues/comments{/number}","contents_url":"https://api.github.com/repos/phoenixframework/phoenix/contents/{+path}","compare_url":"https://api.github.com/repos/phoenixframework/phoenix/compare/{base}...{head}","merges_url":"https://api.github.com/repos/phoenixframework/phoenix/merges","archive_url":"https://api.github.com/repos/phoenixframework/phoenix/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/phoenixframework/phoenix/downloads","issues_url":"https://api.github.com/repos/phoenixframework/phoenix/issues{/number}","pulls_url":"https://api.github.com/repos/phoenixframework/phoenix/pulls{/number}","milestones_url":"https://api.github.com/repos/phoenixframework/phoenix/milestones{/number}","notifications_url":"https://api.github.com/repos/phoenixframework/phoenix/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/phoenixframework/phoenix/labels{/name}","releases_url":"https://api.github.com/repos/phoenixframework/phoenix/releases{/id}","created_at":"2014-01-20T14:14:11Z","updated_at":"2015-08-13T19:02:37Z","pushed_at":"2015-08-13T18:49:20Z","git_url":"git://github.com/phoenixframework/phoenix.git","ssh_url":"git@github.com:phoenixframework/phoenix.git","clone_url":"https://github.com/phoenixframework/phoenix.git","svn_url":"https://github.com/phoenixframework/phoenix","homepage":"http://www.phoenixframework.org","size":9806,"stargazers_count":3258,"watchers_count":3258,"language":"Elixir","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":358,"mirror_url":null,"open_issues_count":11,"forks":358,"open_issues":11,"watchers":3258,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/phoenixframework/phoenix/pulls/1126"},"html":{"href":"https://github.com/phoenixframework/phoenix/pull/1126"},"issue":{"href":"https://api.github.com/repos/phoenixframework/phoenix/issues/1126"},"comments":{"href":"https://api.github.com/repos/phoenixframework/phoenix/issues/1126/comments"},"review_comments":{"href":"https://api.github.com/repos/phoenixframework/phoenix/pulls/1126/comments"},"review_comment":{"href":"https://api.github.com/repos/phoenixframework/phoenix/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/phoenixframework/phoenix/pulls/1126/commits"},"statuses":{"href":"https://api.github.com/repos/phoenixframework/phoenix/statuses/a1542ce23364ec3921a05fe1c49654f34a4909c5"}},"merged":false,"mergeable":null,"mergeable_state":"unknown","merged_by":null,"comments":0,"review_comments":0,"commits":1,"additions":13,"deletions":2,"changed_files":3}}