{"action":"created","comment":{"url":"https://api.github.com/repos/dasch/avro_turf/pulls/comments/26199993","id":26199993,"diff_hunk":"@@ -43,11 +45,34 @@ def decode(encoded_data, schema_name: nil, namespace: @namespace)\n     schema = schema_name && resolve_schema(schema_name, namespace)\n     reader = Avro::IO::DatumReader.new(nil, schema)\n     dr = Avro::DataFile::Reader.new(io, reader)\n+\n+    # If no reader schema is specified, we'll try to find one matching the name\n+    # of the writer's schema.\n+    if schema_name.nil?\n+      schema = load_readers_schema(reader.writers_schema)\n+      reader.readers_schema = schema if schema\n+    end\n+\n     dr.first\n   end\n \n   private\n \n+  # Returns the reader schema matching the writer's schema if one is locally\n+  # available, or nil if there's no matching reader schema.\n+  def load_readers_schema(writers_schema)\n+    return nil unless writers_schema.respond_to?(:fullname)\n+\n+    schema_name = writers_schema.fullname\n+\n+    begin\n+      resolve_schema(schema_name)\n+    rescue SchemaNotFoundError\n+      @logger.warn \"Could not find schema `#{schema_name}' locally; using writer's schema instead\"","path":"lib/avro_turf.rb","position":null,"original_position":48,"commit_id":"1492138f99525de9622039348f7c87a021e2be3b","original_commit_id":"8eff9febcb3036934fdc01583e5b56f795630f5b","user":{"login":"dasch","id":6351,"avatar_url":"https://avatars.githubusercontent.com/u/6351?v=3","gravatar_id":"","url":"https://api.github.com/users/dasch","html_url":"https://github.com/dasch","followers_url":"https://api.github.com/users/dasch/followers","following_url":"https://api.github.com/users/dasch/following{/other_user}","gists_url":"https://api.github.com/users/dasch/gists{/gist_id}","starred_url":"https://api.github.com/users/dasch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dasch/subscriptions","organizations_url":"https://api.github.com/users/dasch/orgs","repos_url":"https://api.github.com/users/dasch/repos","events_url":"https://api.github.com/users/dasch/events{/privacy}","received_events_url":"https://api.github.com/users/dasch/received_events","type":"User","site_admin":false},"body":"I'll have a look.","created_at":"2015-03-11T10:01:10Z","updated_at":"2015-03-11T10:01:10Z","html_url":"https://github.com/dasch/avro_turf/pull/3#discussion_r26199993","pull_request_url":"https://api.github.com/repos/dasch/avro_turf/pulls/3","_links":{"self":{"href":"https://api.github.com/repos/dasch/avro_turf/pulls/comments/26199993"},"html":{"href":"https://github.com/dasch/avro_turf/pull/3#discussion_r26199993"},"pull_request":{"href":"https://api.github.com/repos/dasch/avro_turf/pulls/3"}}},"pull_request":{"url":"https://api.github.com/repos/dasch/avro_turf/pulls/3","id":30645103,"html_url":"https://github.com/dasch/avro_turf/pull/3","diff_url":"https://github.com/dasch/avro_turf/pull/3.diff","patch_url":"https://github.com/dasch/avro_turf/pull/3.patch","issue_url":"https://api.github.com/repos/dasch/avro_turf/issues/3","number":3,"state":"open","locked":false,"title":"Automatically use a matching reader schema when decoding","user":{"login":"dasch","id":6351,"avatar_url":"https://avatars.githubusercontent.com/u/6351?v=3","gravatar_id":"","url":"https://api.github.com/users/dasch","html_url":"https://github.com/dasch","followers_url":"https://api.github.com/users/dasch/followers","following_url":"https://api.github.com/users/dasch/following{/other_user}","gists_url":"https://api.github.com/users/dasch/gists{/gist_id}","starred_url":"https://api.github.com/users/dasch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dasch/subscriptions","organizations_url":"https://api.github.com/users/dasch/orgs","repos_url":"https://api.github.com/users/dasch/repos","events_url":"https://api.github.com/users/dasch/events{/privacy}","received_events_url":"https://api.github.com/users/dasch/received_events","type":"User","site_admin":false},"body":"When decoding Avro data, the reader can specify which local schema should be used. This PR adds the ability to omit that while still using the local schema.\r\n\r\nThis works by extracting the name of the writer's schema from the data and loading the corresponding schema from disk. This means that you merely need to have `account_service.account.avsc` in your schemas dir in order to use that schema when decoding Avro data!\r\n\r\nI'm not sure if it's too magical, but it offers some benefits:\r\n\r\n1. Kragle clients don't need to pass in the name of the reader schema that should be used using e.g. HTTP headers.\r\n2. A Rack middleware could automatically decode any incoming request, without prior knowledge of what schema a given endpoint is using. This will make Rails controllers and Sinatra routes a lot simpler – they _just_ need to handle the already de-serialized data, akin to how JSON works now.","created_at":"2015-03-06T13:40:47Z","updated_at":"2015-03-11T10:01:10Z","closed_at":null,"merged_at":null,"merge_commit_sha":"831b8beeb619faf5ce6680e73f52212de0c32484","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/dasch/avro_turf/pulls/3/commits","review_comments_url":"https://api.github.com/repos/dasch/avro_turf/pulls/3/comments","review_comment_url":"https://api.github.com/repos/dasch/avro_turf/pulls/comments{/number}","comments_url":"https://api.github.com/repos/dasch/avro_turf/issues/3/comments","statuses_url":"https://api.github.com/repos/dasch/avro_turf/statuses/1492138f99525de9622039348f7c87a021e2be3b","head":{"label":"dasch:dasch/auto-look-up-reader-schema","ref":"dasch/auto-look-up-reader-schema","sha":"1492138f99525de9622039348f7c87a021e2be3b","user":{"login":"dasch","id":6351,"avatar_url":"https://avatars.githubusercontent.com/u/6351?v=3","gravatar_id":"","url":"https://api.github.com/users/dasch","html_url":"https://github.com/dasch","followers_url":"https://api.github.com/users/dasch/followers","following_url":"https://api.github.com/users/dasch/following{/other_user}","gists_url":"https://api.github.com/users/dasch/gists{/gist_id}","starred_url":"https://api.github.com/users/dasch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dasch/subscriptions","organizations_url":"https://api.github.com/users/dasch/orgs","repos_url":"https://api.github.com/users/dasch/repos","events_url":"https://api.github.com/users/dasch/events{/privacy}","received_events_url":"https://api.github.com/users/dasch/received_events","type":"User","site_admin":false},"repo":{"id":31656719,"name":"avro_turf","full_name":"dasch/avro_turf","owner":{"login":"dasch","id":6351,"avatar_url":"https://avatars.githubusercontent.com/u/6351?v=3","gravatar_id":"","url":"https://api.github.com/users/dasch","html_url":"https://github.com/dasch","followers_url":"https://api.github.com/users/dasch/followers","following_url":"https://api.github.com/users/dasch/following{/other_user}","gists_url":"https://api.github.com/users/dasch/gists{/gist_id}","starred_url":"https://api.github.com/users/dasch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dasch/subscriptions","organizations_url":"https://api.github.com/users/dasch/orgs","repos_url":"https://api.github.com/users/dasch/repos","events_url":"https://api.github.com/users/dasch/events{/privacy}","received_events_url":"https://api.github.com/users/dasch/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/dasch/avro_turf","description":"A library that makes it easier to use the Avro serialization format from Ruby.","fork":false,"url":"https://api.github.com/repos/dasch/avro_turf","forks_url":"https://api.github.com/repos/dasch/avro_turf/forks","keys_url":"https://api.github.com/repos/dasch/avro_turf/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dasch/avro_turf/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dasch/avro_turf/teams","hooks_url":"https://api.github.com/repos/dasch/avro_turf/hooks","issue_events_url":"https://api.github.com/repos/dasch/avro_turf/issues/events{/number}","events_url":"https://api.github.com/repos/dasch/avro_turf/events","assignees_url":"https://api.github.com/repos/dasch/avro_turf/assignees{/user}","branches_url":"https://api.github.com/repos/dasch/avro_turf/branches{/branch}","tags_url":"https://api.github.com/repos/dasch/avro_turf/tags","blobs_url":"https://api.github.com/repos/dasch/avro_turf/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dasch/avro_turf/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dasch/avro_turf/git/refs{/sha}","trees_url":"https://api.github.com/repos/dasch/avro_turf/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dasch/avro_turf/statuses/{sha}","languages_url":"https://api.github.com/repos/dasch/avro_turf/languages","stargazers_url":"https://api.github.com/repos/dasch/avro_turf/stargazers","contributors_url":"https://api.github.com/repos/dasch/avro_turf/contributors","subscribers_url":"https://api.github.com/repos/dasch/avro_turf/subscribers","subscription_url":"https://api.github.com/repos/dasch/avro_turf/subscription","commits_url":"https://api.github.com/repos/dasch/avro_turf/commits{/sha}","git_commits_url":"https://api.github.com/repos/dasch/avro_turf/git/commits{/sha}","comments_url":"https://api.github.com/repos/dasch/avro_turf/comments{/number}","issue_comment_url":"https://api.github.com/repos/dasch/avro_turf/issues/comments{/number}","contents_url":"https://api.github.com/repos/dasch/avro_turf/contents/{+path}","compare_url":"https://api.github.com/repos/dasch/avro_turf/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dasch/avro_turf/merges","archive_url":"https://api.github.com/repos/dasch/avro_turf/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dasch/avro_turf/downloads","issues_url":"https://api.github.com/repos/dasch/avro_turf/issues{/number}","pulls_url":"https://api.github.com/repos/dasch/avro_turf/pulls{/number}","milestones_url":"https://api.github.com/repos/dasch/avro_turf/milestones{/number}","notifications_url":"https://api.github.com/repos/dasch/avro_turf/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dasch/avro_turf/labels{/name}","releases_url":"https://api.github.com/repos/dasch/avro_turf/releases{/id}","created_at":"2015-03-04T12:48:38Z","updated_at":"2015-03-10T15:20:12Z","pushed_at":"2015-03-10T15:39:12Z","git_url":"git://github.com/dasch/avro_turf.git","ssh_url":"git@github.com:dasch/avro_turf.git","clone_url":"https://github.com/dasch/avro_turf.git","svn_url":"https://github.com/dasch/avro_turf","homepage":null,"size":0,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":0,"default_branch":"master"}},"base":{"label":"dasch:master","ref":"master","sha":"3c4277701b094fc84f8d98f480b6fe911aa813fb","user":{"login":"dasch","id":6351,"avatar_url":"https://avatars.githubusercontent.com/u/6351?v=3","gravatar_id":"","url":"https://api.github.com/users/dasch","html_url":"https://github.com/dasch","followers_url":"https://api.github.com/users/dasch/followers","following_url":"https://api.github.com/users/dasch/following{/other_user}","gists_url":"https://api.github.com/users/dasch/gists{/gist_id}","starred_url":"https://api.github.com/users/dasch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dasch/subscriptions","organizations_url":"https://api.github.com/users/dasch/orgs","repos_url":"https://api.github.com/users/dasch/repos","events_url":"https://api.github.com/users/dasch/events{/privacy}","received_events_url":"https://api.github.com/users/dasch/received_events","type":"User","site_admin":false},"repo":{"id":31656719,"name":"avro_turf","full_name":"dasch/avro_turf","owner":{"login":"dasch","id":6351,"avatar_url":"https://avatars.githubusercontent.com/u/6351?v=3","gravatar_id":"","url":"https://api.github.com/users/dasch","html_url":"https://github.com/dasch","followers_url":"https://api.github.com/users/dasch/followers","following_url":"https://api.github.com/users/dasch/following{/other_user}","gists_url":"https://api.github.com/users/dasch/gists{/gist_id}","starred_url":"https://api.github.com/users/dasch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dasch/subscriptions","organizations_url":"https://api.github.com/users/dasch/orgs","repos_url":"https://api.github.com/users/dasch/repos","events_url":"https://api.github.com/users/dasch/events{/privacy}","received_events_url":"https://api.github.com/users/dasch/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/dasch/avro_turf","description":"A library that makes it easier to use the Avro serialization format from Ruby.","fork":false,"url":"https://api.github.com/repos/dasch/avro_turf","forks_url":"https://api.github.com/repos/dasch/avro_turf/forks","keys_url":"https://api.github.com/repos/dasch/avro_turf/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dasch/avro_turf/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dasch/avro_turf/teams","hooks_url":"https://api.github.com/repos/dasch/avro_turf/hooks","issue_events_url":"https://api.github.com/repos/dasch/avro_turf/issues/events{/number}","events_url":"https://api.github.com/repos/dasch/avro_turf/events","assignees_url":"https://api.github.com/repos/dasch/avro_turf/assignees{/user}","branches_url":"https://api.github.com/repos/dasch/avro_turf/branches{/branch}","tags_url":"https://api.github.com/repos/dasch/avro_turf/tags","blobs_url":"https://api.github.com/repos/dasch/avro_turf/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dasch/avro_turf/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dasch/avro_turf/git/refs{/sha}","trees_url":"https://api.github.com/repos/dasch/avro_turf/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dasch/avro_turf/statuses/{sha}","languages_url":"https://api.github.com/repos/dasch/avro_turf/languages","stargazers_url":"https://api.github.com/repos/dasch/avro_turf/stargazers","contributors_url":"https://api.github.com/repos/dasch/avro_turf/contributors","subscribers_url":"https://api.github.com/repos/dasch/avro_turf/subscribers","subscription_url":"https://api.github.com/repos/dasch/avro_turf/subscription","commits_url":"https://api.github.com/repos/dasch/avro_turf/commits{/sha}","git_commits_url":"https://api.github.com/repos/dasch/avro_turf/git/commits{/sha}","comments_url":"https://api.github.com/repos/dasch/avro_turf/comments{/number}","issue_comment_url":"https://api.github.com/repos/dasch/avro_turf/issues/comments{/number}","contents_url":"https://api.github.com/repos/dasch/avro_turf/contents/{+path}","compare_url":"https://api.github.com/repos/dasch/avro_turf/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dasch/avro_turf/merges","archive_url":"https://api.github.com/repos/dasch/avro_turf/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dasch/avro_turf/downloads","issues_url":"https://api.github.com/repos/dasch/avro_turf/issues{/number}","pulls_url":"https://api.github.com/repos/dasch/avro_turf/pulls{/number}","milestones_url":"https://api.github.com/repos/dasch/avro_turf/milestones{/number}","notifications_url":"https://api.github.com/repos/dasch/avro_turf/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dasch/avro_turf/labels{/name}","releases_url":"https://api.github.com/repos/dasch/avro_turf/releases{/id}","created_at":"2015-03-04T12:48:38Z","updated_at":"2015-03-10T15:20:12Z","pushed_at":"2015-03-10T15:39:12Z","git_url":"git://github.com/dasch/avro_turf.git","ssh_url":"git@github.com:dasch/avro_turf.git","clone_url":"https://github.com/dasch/avro_turf.git","svn_url":"https://github.com/dasch/avro_turf","homepage":null,"size":0,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dasch/avro_turf/pulls/3"},"html":{"href":"https://github.com/dasch/avro_turf/pull/3"},"issue":{"href":"https://api.github.com/repos/dasch/avro_turf/issues/3"},"comments":{"href":"https://api.github.com/repos/dasch/avro_turf/issues/3/comments"},"review_comments":{"href":"https://api.github.com/repos/dasch/avro_turf/pulls/3/comments"},"review_comment":{"href":"https://api.github.com/repos/dasch/avro_turf/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/dasch/avro_turf/pulls/3/commits"},"statuses":{"href":"https://api.github.com/repos/dasch/avro_turf/statuses/1492138f99525de9622039348f7c87a021e2be3b"}}}}