{"action":"created","comment":{"url":"https://api.github.com/repos/thriftrw/thriftrw-go/pulls/comments/64313958","id":64313958,"diff_hunk":"@@ -81,57 +86,95 @@ func (f fieldGroupGenerator) DefineStruct(g Generator) error {\n }\n \n func (f fieldGroupGenerator) ToWire(g Generator) error {\n-\t// TODO(abg): Default values\n \treturn g.DeclareFromTemplate(\n \t\t`\n \t\t<$wire := import \"github.com/thriftrw/thriftrw-go/wire\">\n \n \t\t<$v := newVar \"v\">\n-\t\tfunc (<$v> *<.Name>) ToWire() <$wire>.Value {\n+\t\tfunc (<$v> *<.Name>) ToWire() (<$wire>.Value, error) {\n     \t\t<$fields := newVar \"fields\">\n     \t\t<$i := newVar \"i\">\n-\t\t\t// TODO check if required fields that are reference types are nil\n+\t\t\t<$wVal := newVar \"w\">\n \n-\t\t\tvar <$fields> [<len .Fields>]<$wire>.Field\n-\t\t\t<$i> := 0\n+\t\t\t<if and .IsUnion (len .Fields)>\n+\t\t\t\t<$fmt := import \"fmt\">\n+\t\t\t\t<$count := newVar \"count\">\n+\t\t\t\t<$count> := 0\n+\t\t\t\t<range .Fields>\n+\t\t\t\t\tif <$v>.<goCase .Name> != nil { <$count>++ }\n+\t\t\t\t<end>\n+\t\t\t\t<if .AllowEmptyUnion>\n+\t\t\t\t\tif <$count> > 1 {\n+\t\t\t\t\t\treturn <$wire>.Value{}, <$fmt>.Errorf(\n+\t\t\t\t\t\t\t\"<.Name> should receive at most one field value: received %v values\", <$count>)\n+\t\t\t\t\t}\n+\t\t\t\t<else>\n+\t\t\t\t\tif <$count> != 1 {\n+\t\t\t\t\t\treturn <$wire>.Value{}, <$fmt>.Errorf(\n+\t\t\t\t\t\t\t\"<.Name> should receive exactly one field value: received %v values\", <$count>)\n+\t\t\t\t\t}\n+\t\t\t\t<end>\n+\t\t\t<end>\n+\n+\t\t\tvar (\n+\t\t\t\t\t<$fields> [<len .Fields>]<$wire>.Field\n+\t\t\t\t\t<$i> int = 0\n+\t\t\t\t<if len .Fields>\n+\t\t\t\t\t<$wVal> <$wire>.Value\n+\t\t\t\t\terr error\n+\t\t\t\t<end>\n+\t\t\t)\n \n+\t\t\t<$structName := .Name>\n \t\t\t<range .Fields>\n \t\t\t\t<$f := printf \"%s.%s\" $v (goCase .Name)>\n \t\t\t\t<if .Required>\n-\t\t\t\t\t<$wVal := toWire .Type $f>\n-\t\t\t\t\t<$fields>[<$i>] = <$wire>.Field{ID: <.ID>, Value: <$wVal>}\n-\t\t\t\t\t<$i>++\n-\t\t\t\t<else>\n-\t\t\t\t\t<if .Default>\n+\t\t\t\t\t<if not (isPrimitiveType .Type)>","path":"gen/field.go","position":69,"original_position":69,"commit_id":"6035f4c9a9c3f63ecac6c8e859f254c37feaff49","original_commit_id":"6035f4c9a9c3f63ecac6c8e859f254c37feaff49","user":{"login":"abhinav","id":41730,"avatar_url":"https://avatars.githubusercontent.com/u/41730?v=3","gravatar_id":"","url":"https://api.github.com/users/abhinav","html_url":"https://github.com/abhinav","followers_url":"https://api.github.com/users/abhinav/followers","following_url":"https://api.github.com/users/abhinav/following{/other_user}","gists_url":"https://api.github.com/users/abhinav/gists{/gist_id}","starred_url":"https://api.github.com/users/abhinav/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/abhinav/subscriptions","organizations_url":"https://api.github.com/users/abhinav/orgs","repos_url":"https://api.github.com/users/abhinav/repos","events_url":"https://api.github.com/users/abhinav/events{/privacy}","received_events_url":"https://api.github.com/users/abhinav/received_events","type":"User","site_admin":false},"body":"Discussed offline. Invalid comment.","created_at":"2016-05-24T00:55:20Z","updated_at":"2016-05-24T00:55:20Z","html_url":"https://github.com/thriftrw/thriftrw-go/pull/129#discussion_r64313958","pull_request_url":"https://api.github.com/repos/thriftrw/thriftrw-go/pulls/129","_links":{"self":{"href":"https://api.github.com/repos/thriftrw/thriftrw-go/pulls/comments/64313958"},"html":{"href":"https://github.com/thriftrw/thriftrw-go/pull/129#discussion_r64313958"},"pull_request":{"href":"https://api.github.com/repos/thriftrw/thriftrw-go/pulls/129"}}},"pull_request":{"url":"https://api.github.com/repos/thriftrw/thriftrw-go/pulls/129","id":70934393,"html_url":"https://github.com/thriftrw/thriftrw-go/pull/129","diff_url":"https://github.com/thriftrw/thriftrw-go/pull/129.diff","patch_url":"https://github.com/thriftrw/thriftrw-go/pull/129.patch","issue_url":"https://api.github.com/repos/thriftrw/thriftrw-go/issues/129","number":129,"state":"open","locked":false,"title":"gen: validate structs and unions","user":{"login":"abhinav","id":41730,"avatar_url":"https://avatars.githubusercontent.com/u/41730?v=3","gravatar_id":"","url":"https://api.github.com/users/abhinav","html_url":"https://github.com/abhinav","followers_url":"https://api.github.com/users/abhinav/followers","following_url":"https://api.github.com/users/abhinav/following{/other_user}","gists_url":"https://api.github.com/users/abhinav/gists{/gist_id}","starred_url":"https://api.github.com/users/abhinav/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/abhinav/subscriptions","organizations_url":"https://api.github.com/users/abhinav/orgs","repos_url":"https://api.github.com/users/abhinav/repos","events_url":"https://api.github.com/users/abhinav/events{/privacy}","received_events_url":"https://api.github.com/users/abhinav/received_events","type":"User","site_admin":false},"body":"This changes the generated code for struct-like types to check the following:\r\n\r\n-   structs and exceptions: All required fields must be set. Note that\r\n    primitive required fields are always set so they cannot be checked during\r\n    serialization.\r\n-   unions: For non-empty unions, exactly one field must be set.\r\n-   function results: Exactly one field must be set if the function has a\r\n    non-void return value. At most one field must be set if the function\r\n    has a void return value.\r\n\r\nResolves #76\r\n","created_at":"2016-05-21T00:44:37Z","updated_at":"2016-05-24T00:55:20Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1ec55fdfcba4ea06fa8b96acd1c4ecf706d9605b","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/thriftrw/thriftrw-go/pulls/129/commits","review_comments_url":"https://api.github.com/repos/thriftrw/thriftrw-go/pulls/129/comments","review_comment_url":"https://api.github.com/repos/thriftrw/thriftrw-go/pulls/comments{/number}","comments_url":"https://api.github.com/repos/thriftrw/thriftrw-go/issues/129/comments","statuses_url":"https://api.github.com/repos/thriftrw/thriftrw-go/statuses/6035f4c9a9c3f63ecac6c8e859f254c37feaff49","head":{"label":"thriftrw:wire-validate","ref":"wire-validate","sha":"6035f4c9a9c3f63ecac6c8e859f254c37feaff49","user":{"login":"thriftrw","id":16569516,"avatar_url":"https://avatars.githubusercontent.com/u/16569516?v=3","gravatar_id":"","url":"https://api.github.com/users/thriftrw","html_url":"https://github.com/thriftrw","followers_url":"https://api.github.com/users/thriftrw/followers","following_url":"https://api.github.com/users/thriftrw/following{/other_user}","gists_url":"https://api.github.com/users/thriftrw/gists{/gist_id}","starred_url":"https://api.github.com/users/thriftrw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thriftrw/subscriptions","organizations_url":"https://api.github.com/users/thriftrw/orgs","repos_url":"https://api.github.com/users/thriftrw/repos","events_url":"https://api.github.com/users/thriftrw/events{/privacy}","received_events_url":"https://api.github.com/users/thriftrw/received_events","type":"Organization","site_admin":false},"repo":{"id":45574831,"name":"thriftrw-go","full_name":"thriftrw/thriftrw-go","owner":{"login":"thriftrw","id":16569516,"avatar_url":"https://avatars.githubusercontent.com/u/16569516?v=3","gravatar_id":"","url":"https://api.github.com/users/thriftrw","html_url":"https://github.com/thriftrw","followers_url":"https://api.github.com/users/thriftrw/followers","following_url":"https://api.github.com/users/thriftrw/following{/other_user}","gists_url":"https://api.github.com/users/thriftrw/gists{/gist_id}","starred_url":"https://api.github.com/users/thriftrw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thriftrw/subscriptions","organizations_url":"https://api.github.com/users/thriftrw/orgs","repos_url":"https://api.github.com/users/thriftrw/repos","events_url":"https://api.github.com/users/thriftrw/events{/privacy}","received_events_url":"https://api.github.com/users/thriftrw/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/thriftrw/thriftrw-go","description":"A Thrift encoding code generator and library for Go","fork":false,"url":"https://api.github.com/repos/thriftrw/thriftrw-go","forks_url":"https://api.github.com/repos/thriftrw/thriftrw-go/forks","keys_url":"https://api.github.com/repos/thriftrw/thriftrw-go/keys{/key_id}","collaborators_url":"https://api.github.com/repos/thriftrw/thriftrw-go/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/thriftrw/thriftrw-go/teams","hooks_url":"https://api.github.com/repos/thriftrw/thriftrw-go/hooks","issue_events_url":"https://api.github.com/repos/thriftrw/thriftrw-go/issues/events{/number}","events_url":"https://api.github.com/repos/thriftrw/thriftrw-go/events","assignees_url":"https://api.github.com/repos/thriftrw/thriftrw-go/assignees{/user}","branches_url":"https://api.github.com/repos/thriftrw/thriftrw-go/branches{/branch}","tags_url":"https://api.github.com/repos/thriftrw/thriftrw-go/tags","blobs_url":"https://api.github.com/repos/thriftrw/thriftrw-go/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/thriftrw/thriftrw-go/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/thriftrw/thriftrw-go/git/refs{/sha}","trees_url":"https://api.github.com/repos/thriftrw/thriftrw-go/git/trees{/sha}","statuses_url":"https://api.github.com/repos/thriftrw/thriftrw-go/statuses/{sha}","languages_url":"https://api.github.com/repos/thriftrw/thriftrw-go/languages","stargazers_url":"https://api.github.com/repos/thriftrw/thriftrw-go/stargazers","contributors_url":"https://api.github.com/repos/thriftrw/thriftrw-go/contributors","subscribers_url":"https://api.github.com/repos/thriftrw/thriftrw-go/subscribers","subscription_url":"https://api.github.com/repos/thriftrw/thriftrw-go/subscription","commits_url":"https://api.github.com/repos/thriftrw/thriftrw-go/commits{/sha}","git_commits_url":"https://api.github.com/repos/thriftrw/thriftrw-go/git/commits{/sha}","comments_url":"https://api.github.com/repos/thriftrw/thriftrw-go/comments{/number}","issue_comment_url":"https://api.github.com/repos/thriftrw/thriftrw-go/issues/comments{/number}","contents_url":"https://api.github.com/repos/thriftrw/thriftrw-go/contents/{+path}","compare_url":"https://api.github.com/repos/thriftrw/thriftrw-go/compare/{base}...{head}","merges_url":"https://api.github.com/repos/thriftrw/thriftrw-go/merges","archive_url":"https://api.github.com/repos/thriftrw/thriftrw-go/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/thriftrw/thriftrw-go/downloads","issues_url":"https://api.github.com/repos/thriftrw/thriftrw-go/issues{/number}","pulls_url":"https://api.github.com/repos/thriftrw/thriftrw-go/pulls{/number}","milestones_url":"https://api.github.com/repos/thriftrw/thriftrw-go/milestones{/number}","notifications_url":"https://api.github.com/repos/thriftrw/thriftrw-go/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/thriftrw/thriftrw-go/labels{/name}","releases_url":"https://api.github.com/repos/thriftrw/thriftrw-go/releases{/id}","deployments_url":"https://api.github.com/repos/thriftrw/thriftrw-go/deployments","created_at":"2015-11-04T23:43:00Z","updated_at":"2016-05-20T19:29:46Z","pushed_at":"2016-05-23T19:17:36Z","git_url":"git://github.com/thriftrw/thriftrw-go.git","ssh_url":"git@github.com:thriftrw/thriftrw-go.git","clone_url":"https://github.com/thriftrw/thriftrw-go.git","svn_url":"https://github.com/thriftrw/thriftrw-go","homepage":"","size":579,"stargazers_count":5,"watchers_count":5,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":19,"forks":0,"open_issues":19,"watchers":5,"default_branch":"master"}},"base":{"label":"thriftrw:master","ref":"master","sha":"9e0f33c6d2e7a07b35a94f05006b1a9a5dc1242a","user":{"login":"thriftrw","id":16569516,"avatar_url":"https://avatars.githubusercontent.com/u/16569516?v=3","gravatar_id":"","url":"https://api.github.com/users/thriftrw","html_url":"https://github.com/thriftrw","followers_url":"https://api.github.com/users/thriftrw/followers","following_url":"https://api.github.com/users/thriftrw/following{/other_user}","gists_url":"https://api.github.com/users/thriftrw/gists{/gist_id}","starred_url":"https://api.github.com/users/thriftrw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thriftrw/subscriptions","organizations_url":"https://api.github.com/users/thriftrw/orgs","repos_url":"https://api.github.com/users/thriftrw/repos","events_url":"https://api.github.com/users/thriftrw/events{/privacy}","received_events_url":"https://api.github.com/users/thriftrw/received_events","type":"Organization","site_admin":false},"repo":{"id":45574831,"name":"thriftrw-go","full_name":"thriftrw/thriftrw-go","owner":{"login":"thriftrw","id":16569516,"avatar_url":"https://avatars.githubusercontent.com/u/16569516?v=3","gravatar_id":"","url":"https://api.github.com/users/thriftrw","html_url":"https://github.com/thriftrw","followers_url":"https://api.github.com/users/thriftrw/followers","following_url":"https://api.github.com/users/thriftrw/following{/other_user}","gists_url":"https://api.github.com/users/thriftrw/gists{/gist_id}","starred_url":"https://api.github.com/users/thriftrw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thriftrw/subscriptions","organizations_url":"https://api.github.com/users/thriftrw/orgs","repos_url":"https://api.github.com/users/thriftrw/repos","events_url":"https://api.github.com/users/thriftrw/events{/privacy}","received_events_url":"https://api.github.com/users/thriftrw/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/thriftrw/thriftrw-go","description":"A Thrift encoding code generator and library for Go","fork":false,"url":"https://api.github.com/repos/thriftrw/thriftrw-go","forks_url":"https://api.github.com/repos/thriftrw/thriftrw-go/forks","keys_url":"https://api.github.com/repos/thriftrw/thriftrw-go/keys{/key_id}","collaborators_url":"https://api.github.com/repos/thriftrw/thriftrw-go/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/thriftrw/thriftrw-go/teams","hooks_url":"https://api.github.com/repos/thriftrw/thriftrw-go/hooks","issue_events_url":"https://api.github.com/repos/thriftrw/thriftrw-go/issues/events{/number}","events_url":"https://api.github.com/repos/thriftrw/thriftrw-go/events","assignees_url":"https://api.github.com/repos/thriftrw/thriftrw-go/assignees{/user}","branches_url":"https://api.github.com/repos/thriftrw/thriftrw-go/branches{/branch}","tags_url":"https://api.github.com/repos/thriftrw/thriftrw-go/tags","blobs_url":"https://api.github.com/repos/thriftrw/thriftrw-go/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/thriftrw/thriftrw-go/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/thriftrw/thriftrw-go/git/refs{/sha}","trees_url":"https://api.github.com/repos/thriftrw/thriftrw-go/git/trees{/sha}","statuses_url":"https://api.github.com/repos/thriftrw/thriftrw-go/statuses/{sha}","languages_url":"https://api.github.com/repos/thriftrw/thriftrw-go/languages","stargazers_url":"https://api.github.com/repos/thriftrw/thriftrw-go/stargazers","contributors_url":"https://api.github.com/repos/thriftrw/thriftrw-go/contributors","subscribers_url":"https://api.github.com/repos/thriftrw/thriftrw-go/subscribers","subscription_url":"https://api.github.com/repos/thriftrw/thriftrw-go/subscription","commits_url":"https://api.github.com/repos/thriftrw/thriftrw-go/commits{/sha}","git_commits_url":"https://api.github.com/repos/thriftrw/thriftrw-go/git/commits{/sha}","comments_url":"https://api.github.com/repos/thriftrw/thriftrw-go/comments{/number}","issue_comment_url":"https://api.github.com/repos/thriftrw/thriftrw-go/issues/comments{/number}","contents_url":"https://api.github.com/repos/thriftrw/thriftrw-go/contents/{+path}","compare_url":"https://api.github.com/repos/thriftrw/thriftrw-go/compare/{base}...{head}","merges_url":"https://api.github.com/repos/thriftrw/thriftrw-go/merges","archive_url":"https://api.github.com/repos/thriftrw/thriftrw-go/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/thriftrw/thriftrw-go/downloads","issues_url":"https://api.github.com/repos/thriftrw/thriftrw-go/issues{/number}","pulls_url":"https://api.github.com/repos/thriftrw/thriftrw-go/pulls{/number}","milestones_url":"https://api.github.com/repos/thriftrw/thriftrw-go/milestones{/number}","notifications_url":"https://api.github.com/repos/thriftrw/thriftrw-go/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/thriftrw/thriftrw-go/labels{/name}","releases_url":"https://api.github.com/repos/thriftrw/thriftrw-go/releases{/id}","deployments_url":"https://api.github.com/repos/thriftrw/thriftrw-go/deployments","created_at":"2015-11-04T23:43:00Z","updated_at":"2016-05-20T19:29:46Z","pushed_at":"2016-05-23T19:17:36Z","git_url":"git://github.com/thriftrw/thriftrw-go.git","ssh_url":"git@github.com:thriftrw/thriftrw-go.git","clone_url":"https://github.com/thriftrw/thriftrw-go.git","svn_url":"https://github.com/thriftrw/thriftrw-go","homepage":"","size":579,"stargazers_count":5,"watchers_count":5,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":19,"forks":0,"open_issues":19,"watchers":5,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/thriftrw/thriftrw-go/pulls/129"},"html":{"href":"https://github.com/thriftrw/thriftrw-go/pull/129"},"issue":{"href":"https://api.github.com/repos/thriftrw/thriftrw-go/issues/129"},"comments":{"href":"https://api.github.com/repos/thriftrw/thriftrw-go/issues/129/comments"},"review_comments":{"href":"https://api.github.com/repos/thriftrw/thriftrw-go/pulls/129/comments"},"review_comment":{"href":"https://api.github.com/repos/thriftrw/thriftrw-go/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/thriftrw/thriftrw-go/pulls/129/commits"},"statuses":{"href":"https://api.github.com/repos/thriftrw/thriftrw-go/statuses/6035f4c9a9c3f63ecac6c8e859f254c37feaff49"}}}}
{"actor":{"display_login":"abhinav"}}