{"action":"opened","number":73,"pull_request":{"url":"https://api.github.com/repos/mtth/avsc/pulls/73","id":91487406,"html_url":"https://github.com/mtth/avsc/pull/73","diff_url":"https://github.com/mtth/avsc/pull/73.diff","patch_url":"https://github.com/mtth/avsc/pull/73.patch","issue_url":"https://api.github.com/repos/mtth/avsc/issues/73","number":73,"state":"open","locked":false,"title":"record type backward compability with default","user":{"login":"bencebalogh","id":5901325,"avatar_url":"https://avatars.githubusercontent.com/u/5901325?v=3","gravatar_id":"","url":"https://api.github.com/users/bencebalogh","html_url":"https://github.com/bencebalogh","followers_url":"https://api.github.com/users/bencebalogh/followers","following_url":"https://api.github.com/users/bencebalogh/following{/other_user}","gists_url":"https://api.github.com/users/bencebalogh/gists{/gist_id}","starred_url":"https://api.github.com/users/bencebalogh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bencebalogh/subscriptions","organizations_url":"https://api.github.com/users/bencebalogh/orgs","repos_url":"https://api.github.com/users/bencebalogh/repos","events_url":"https://api.github.com/users/bencebalogh/events{/privacy}","received_events_url":"https://api.github.com/users/bencebalogh/received_events","type":"User","site_admin":false},"body":"The [avro specification about schema resolution](http://avro.apache.org/docs/1.8.1/spec.html#Schema+Resolution) says:\r\n> if the reader's record schema has a field that contains a default value, and writer's schema does not have a field with the same name, then the reader should use the default value from its field.\r\n\r\nMore about this [here](http://docs.confluent.io/1.0.1/avro.html) with examples.\r\n\r\nWith the current version if I follow the examples from [above](http://docs.confluent.io/1.0.1/avro.html) I get a truncated buffer when calling `fromBuffer`.\r\n\r\nExample with the current version:\r\n```\r\n'use strict';\r\n\r\nconst avro = require('avsc');\r\n\r\nconst schema1 = avro.parse({\r\n    \"namespace\": \"example.avro\",\r\n    \"type\": \"record\",\r\n    \"name\": \"user\",\r\n    \"fields\": [\r\n        {\r\n            \"name\": \"name\",\r\n            \"type\": \"string\"\r\n        },\r\n        {\r\n            \"name\": \"favorite_number\",\r\n            \"type\": \"int\"\r\n        }\r\n    ]\r\n});\r\nconst schema2 = avro.parse({\r\n    \"namespace\": \"example.avro\",\r\n    \"type\": \"record\",\r\n    \"name\": \"user\",\r\n    \"fields\": [\r\n        {\r\n            \"name\": \"name\",\r\n            \"type\": \"string\"\r\n        },\r\n        {\r\n            \"name\": \"favorite_number\",\r\n            \"type\": \"int\"\r\n        },\r\n        {\r\n            \"name\": \"favorite_color\",\r\n            \"type\": \"string\",\r\n            \"default\":  \"green\"\r\n        },\r\n        {\r\n            \"name\": \"happy\",\r\n            \"type\": \"boolean\",\r\n            \"default\": true\r\n        },\r\n        {\r\n            \"name\": \"age\",\r\n            \"type\": \"int\",\r\n            \"default\": 12\r\n        },\r\n        {\r\n            \"name\": \"data\",\r\n            \"type\": {\r\n                \"type\": \"map\",\r\n                \"values\": [\"long\", \"string\"]\r\n            },\r\n            \"default\": {\r\n                \"hah\": 11111\r\n            },\r\n        }\r\n    ]\r\n});\r\nconst buf = schema1.toBuffer(message);\r\n\r\nconst val1 = schema1.fromBuffer(buf);\r\nconsole.log(JSON.stringify(val1, 1, 2));\r\n\r\nconst val2 = schema2.fromBuffer(buf);\r\nconsole.log(JSON.stringify(val2, 1, 2));\r\n\r\n```\r\n\r\nExamples with the changes:\r\n```\r\n'use strict';\r\n\r\nconst avro = require('avsc');\r\n\r\nconst schema1 = avro.parse({\r\n    \"namespace\": \"example.avro\",\r\n    \"type\": \"record\",\r\n    \"name\": \"user\",\r\n    \"fields\": [\r\n        {\r\n            \"name\": \"name\",\r\n            \"type\": \"string\"\r\n        },\r\n        {\r\n            \"name\": \"favorite_number\",\r\n            \"type\": \"int\"\r\n        }\r\n    ]\r\n});\r\nconst schema2 = avro.parse({\r\n    \"namespace\": \"example.avro\",\r\n    \"type\": \"record\",\r\n    \"name\": \"user\",\r\n    \"fields\": [\r\n        {\r\n            \"name\": \"name\",\r\n            \"type\": \"string\"\r\n        },\r\n        {\r\n            \"name\": \"favorite_number\",\r\n            \"type\": \"int\"\r\n        },\r\n        {\r\n            \"name\": \"favorite_color\",\r\n            \"type\": \"string\",\r\n            \"default\":  \"green\"\r\n        },\r\n        {\r\n            \"name\": \"happy\",\r\n            \"type\": \"boolean\",\r\n            \"default\": true\r\n        },\r\n        {\r\n            \"name\": \"age\",\r\n            \"type\": \"int\",\r\n            \"default\": 12\r\n        },\r\n        {\r\n            \"name\": \"data\",\r\n            \"type\": {\r\n                \"type\": \"map\",\r\n                \"values\": [\"long\", \"string\"]\r\n            },\r\n            \"default\": {\r\n                \"hah\": 11111\r\n            },\r\n        }\r\n    ]\r\n});\r\nconst schema3 = avro.parse({\r\n    \"namespace\": \"example.avro\",\r\n    \"type\": \"record\",\r\n    \"name\": \"user\",\r\n    \"fields\": [\r\n        {\r\n            \"name\": \"name\",\r\n            \"type\": \"string\"\r\n        },\r\n        {\r\n            \"name\": \"favorite_number\",\r\n            \"type\": \"int\"\r\n        },\r\n        {\r\n            \"name\": \"favorite_color\",\r\n            \"type\": \"string\",\r\n            \"default\":  \"green\"\r\n        },\r\n        {\r\n            \"name\": \"happy\",\r\n            \"type\": \"boolean\"\r\n        }\r\n    ]\r\n});\r\n\r\nconst message = {\r\n    \"name\": \"Joe\",\r\n    \"favorite_number\": 1\r\n};\r\n\r\nconst buf = schema1.toBuffer(message);\r\n\r\nconst val1 = schema1.fromBuffer(buf);\r\nconsole.log(JSON.stringify(val1, 1, 2));\r\n\r\nconst val2 = schema2.fromBuffer(buf);\r\nconsole.log(JSON.stringify(val2, 1, 2));\r\n\r\ntry {\r\n    schema3.fromBuffer(buf);\r\n} catch(e) {\r\n    console.log('expect to throw');\r\n}\r\n```","created_at":"2016-10-29T12:11:04Z","updated_at":"2016-10-29T12:11:04Z","closed_at":null,"merged_at":null,"merge_commit_sha":null,"assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/mtth/avsc/pulls/73/commits","review_comments_url":"https://api.github.com/repos/mtth/avsc/pulls/73/comments","review_comment_url":"https://api.github.com/repos/mtth/avsc/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mtth/avsc/issues/73/comments","statuses_url":"https://api.github.com/repos/mtth/avsc/statuses/49f44877b4eea612a0f4c5a645e81e81544487d2","head":{"label":"bencebalogh:record-type-backward-compability","ref":"record-type-backward-compability","sha":"49f44877b4eea612a0f4c5a645e81e81544487d2","user":{"login":"bencebalogh","id":5901325,"avatar_url":"https://avatars.githubusercontent.com/u/5901325?v=3","gravatar_id":"","url":"https://api.github.com/users/bencebalogh","html_url":"https://github.com/bencebalogh","followers_url":"https://api.github.com/users/bencebalogh/followers","following_url":"https://api.github.com/users/bencebalogh/following{/other_user}","gists_url":"https://api.github.com/users/bencebalogh/gists{/gist_id}","starred_url":"https://api.github.com/users/bencebalogh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bencebalogh/subscriptions","organizations_url":"https://api.github.com/users/bencebalogh/orgs","repos_url":"https://api.github.com/users/bencebalogh/repos","events_url":"https://api.github.com/users/bencebalogh/events{/privacy}","received_events_url":"https://api.github.com/users/bencebalogh/received_events","type":"User","site_admin":false},"repo":{"id":72197394,"name":"avsc","full_name":"bencebalogh/avsc","owner":{"login":"bencebalogh","id":5901325,"avatar_url":"https://avatars.githubusercontent.com/u/5901325?v=3","gravatar_id":"","url":"https://api.github.com/users/bencebalogh","html_url":"https://github.com/bencebalogh","followers_url":"https://api.github.com/users/bencebalogh/followers","following_url":"https://api.github.com/users/bencebalogh/following{/other_user}","gists_url":"https://api.github.com/users/bencebalogh/gists{/gist_id}","starred_url":"https://api.github.com/users/bencebalogh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bencebalogh/subscriptions","organizations_url":"https://api.github.com/users/bencebalogh/orgs","repos_url":"https://api.github.com/users/bencebalogh/repos","events_url":"https://api.github.com/users/bencebalogh/events{/privacy}","received_events_url":"https://api.github.com/users/bencebalogh/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/bencebalogh/avsc","description":"Avro for JavaScript :zap:","fork":true,"url":"https://api.github.com/repos/bencebalogh/avsc","forks_url":"https://api.github.com/repos/bencebalogh/avsc/forks","keys_url":"https://api.github.com/repos/bencebalogh/avsc/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bencebalogh/avsc/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bencebalogh/avsc/teams","hooks_url":"https://api.github.com/repos/bencebalogh/avsc/hooks","issue_events_url":"https://api.github.com/repos/bencebalogh/avsc/issues/events{/number}","events_url":"https://api.github.com/repos/bencebalogh/avsc/events","assignees_url":"https://api.github.com/repos/bencebalogh/avsc/assignees{/user}","branches_url":"https://api.github.com/repos/bencebalogh/avsc/branches{/branch}","tags_url":"https://api.github.com/repos/bencebalogh/avsc/tags","blobs_url":"https://api.github.com/repos/bencebalogh/avsc/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bencebalogh/avsc/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bencebalogh/avsc/git/refs{/sha}","trees_url":"https://api.github.com/repos/bencebalogh/avsc/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bencebalogh/avsc/statuses/{sha}","languages_url":"https://api.github.com/repos/bencebalogh/avsc/languages","stargazers_url":"https://api.github.com/repos/bencebalogh/avsc/stargazers","contributors_url":"https://api.github.com/repos/bencebalogh/avsc/contributors","subscribers_url":"https://api.github.com/repos/bencebalogh/avsc/subscribers","subscription_url":"https://api.github.com/repos/bencebalogh/avsc/subscription","commits_url":"https://api.github.com/repos/bencebalogh/avsc/commits{/sha}","git_commits_url":"https://api.github.com/repos/bencebalogh/avsc/git/commits{/sha}","comments_url":"https://api.github.com/repos/bencebalogh/avsc/comments{/number}","issue_comment_url":"https://api.github.com/repos/bencebalogh/avsc/issues/comments{/number}","contents_url":"https://api.github.com/repos/bencebalogh/avsc/contents/{+path}","compare_url":"https://api.github.com/repos/bencebalogh/avsc/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bencebalogh/avsc/merges","archive_url":"https://api.github.com/repos/bencebalogh/avsc/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bencebalogh/avsc/downloads","issues_url":"https://api.github.com/repos/bencebalogh/avsc/issues{/number}","pulls_url":"https://api.github.com/repos/bencebalogh/avsc/pulls{/number}","milestones_url":"https://api.github.com/repos/bencebalogh/avsc/milestones{/number}","notifications_url":"https://api.github.com/repos/bencebalogh/avsc/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bencebalogh/avsc/labels{/name}","releases_url":"https://api.github.com/repos/bencebalogh/avsc/releases{/id}","deployments_url":"https://api.github.com/repos/bencebalogh/avsc/deployments","created_at":"2016-10-28T10:15:12Z","updated_at":"2016-10-28T10:15:14Z","pushed_at":"2016-10-29T12:03:24Z","git_url":"git://github.com/bencebalogh/avsc.git","ssh_url":"git@github.com:bencebalogh/avsc.git","clone_url":"https://github.com/bencebalogh/avsc.git","svn_url":"https://github.com/bencebalogh/avsc","homepage":"","size":7841,"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":"mtth:master","ref":"master","sha":"0e64630ffae56056cf7fccf3793cc889b2c3010b","user":{"login":"mtth","id":1216372,"avatar_url":"https://avatars.githubusercontent.com/u/1216372?v=3","gravatar_id":"","url":"https://api.github.com/users/mtth","html_url":"https://github.com/mtth","followers_url":"https://api.github.com/users/mtth/followers","following_url":"https://api.github.com/users/mtth/following{/other_user}","gists_url":"https://api.github.com/users/mtth/gists{/gist_id}","starred_url":"https://api.github.com/users/mtth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mtth/subscriptions","organizations_url":"https://api.github.com/users/mtth/orgs","repos_url":"https://api.github.com/users/mtth/repos","events_url":"https://api.github.com/users/mtth/events{/privacy}","received_events_url":"https://api.github.com/users/mtth/received_events","type":"User","site_admin":false},"repo":{"id":42375652,"name":"avsc","full_name":"mtth/avsc","owner":{"login":"mtth","id":1216372,"avatar_url":"https://avatars.githubusercontent.com/u/1216372?v=3","gravatar_id":"","url":"https://api.github.com/users/mtth","html_url":"https://github.com/mtth","followers_url":"https://api.github.com/users/mtth/followers","following_url":"https://api.github.com/users/mtth/following{/other_user}","gists_url":"https://api.github.com/users/mtth/gists{/gist_id}","starred_url":"https://api.github.com/users/mtth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mtth/subscriptions","organizations_url":"https://api.github.com/users/mtth/orgs","repos_url":"https://api.github.com/users/mtth/repos","events_url":"https://api.github.com/users/mtth/events{/privacy}","received_events_url":"https://api.github.com/users/mtth/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mtth/avsc","description":"Avro for JavaScript :zap:","fork":false,"url":"https://api.github.com/repos/mtth/avsc","forks_url":"https://api.github.com/repos/mtth/avsc/forks","keys_url":"https://api.github.com/repos/mtth/avsc/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mtth/avsc/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mtth/avsc/teams","hooks_url":"https://api.github.com/repos/mtth/avsc/hooks","issue_events_url":"https://api.github.com/repos/mtth/avsc/issues/events{/number}","events_url":"https://api.github.com/repos/mtth/avsc/events","assignees_url":"https://api.github.com/repos/mtth/avsc/assignees{/user}","branches_url":"https://api.github.com/repos/mtth/avsc/branches{/branch}","tags_url":"https://api.github.com/repos/mtth/avsc/tags","blobs_url":"https://api.github.com/repos/mtth/avsc/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mtth/avsc/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mtth/avsc/git/refs{/sha}","trees_url":"https://api.github.com/repos/mtth/avsc/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mtth/avsc/statuses/{sha}","languages_url":"https://api.github.com/repos/mtth/avsc/languages","stargazers_url":"https://api.github.com/repos/mtth/avsc/stargazers","contributors_url":"https://api.github.com/repos/mtth/avsc/contributors","subscribers_url":"https://api.github.com/repos/mtth/avsc/subscribers","subscription_url":"https://api.github.com/repos/mtth/avsc/subscription","commits_url":"https://api.github.com/repos/mtth/avsc/commits{/sha}","git_commits_url":"https://api.github.com/repos/mtth/avsc/git/commits{/sha}","comments_url":"https://api.github.com/repos/mtth/avsc/comments{/number}","issue_comment_url":"https://api.github.com/repos/mtth/avsc/issues/comments{/number}","contents_url":"https://api.github.com/repos/mtth/avsc/contents/{+path}","compare_url":"https://api.github.com/repos/mtth/avsc/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mtth/avsc/merges","archive_url":"https://api.github.com/repos/mtth/avsc/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mtth/avsc/downloads","issues_url":"https://api.github.com/repos/mtth/avsc/issues{/number}","pulls_url":"https://api.github.com/repos/mtth/avsc/pulls{/number}","milestones_url":"https://api.github.com/repos/mtth/avsc/milestones{/number}","notifications_url":"https://api.github.com/repos/mtth/avsc/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mtth/avsc/labels{/name}","releases_url":"https://api.github.com/repos/mtth/avsc/releases{/id}","deployments_url":"https://api.github.com/repos/mtth/avsc/deployments","created_at":"2015-09-12T22:37:23Z","updated_at":"2016-10-28T20:48:15Z","pushed_at":"2016-10-23T05:03:43Z","git_url":"git://github.com/mtth/avsc.git","ssh_url":"git@github.com:mtth/avsc.git","clone_url":"https://github.com/mtth/avsc.git","svn_url":"https://github.com/mtth/avsc","homepage":"","size":7841,"stargazers_count":292,"watchers_count":292,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":25,"mirror_url":null,"open_issues_count":1,"forks":25,"open_issues":1,"watchers":292,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mtth/avsc/pulls/73"},"html":{"href":"https://github.com/mtth/avsc/pull/73"},"issue":{"href":"https://api.github.com/repos/mtth/avsc/issues/73"},"comments":{"href":"https://api.github.com/repos/mtth/avsc/issues/73/comments"},"review_comments":{"href":"https://api.github.com/repos/mtth/avsc/pulls/73/comments"},"review_comment":{"href":"https://api.github.com/repos/mtth/avsc/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mtth/avsc/pulls/73/commits"},"statuses":{"href":"https://api.github.com/repos/mtth/avsc/statuses/49f44877b4eea612a0f4c5a645e81e81544487d2"}},"merged":false,"mergeable":null,"mergeable_state":"unknown","merged_by":null,"comments":0,"review_comments":0,"commits":1,"additions":124,"deletions":0,"changed_files":2}}
{"actor":{"display_login":"bencebalogh"}}