{"action":"created","comment":{"url":"https://api.github.com/repos/ruby-json-schema/json-schema/pulls/comments/24263083","id":24263083,"diff_hunk":"@@ -238,6 +242,46 @@ def validation_errors\n       @errors\n     end\n \n+    def resolve_nested_references(schema, schema_portion, list)\n+      case schema_portion\n+      when Array\n+        # for arrays resolve all items which have not been resolved yet\n+        schema_portion.each_with_index do |item, i|\n+          schema_portion[i] = resolve_nested_references(schema, item, list) unless list.include?(schema_portion[i])\n+        end\n+      when Hash\n+        if schema_portion[\"$ref\"]\n+          # for hashes with a reference, resolve their referenced schema and copy(!) the result into the currently handled portion\n+          _, ref_schema = JSON::Schema::RefAttribute.get_referenced_uri_and_schema(schema_portion, schema, self)\n+          resolved_portion = resolve(ref_schema, ref_schema.schema, list)\n+          schema_portion.clear\n+          resolved_portion.each { |key, value| schema_portion[key] = value }\n+        else\n+          # for hashes without a reference we also resolve recursively what has not been resolved yet\n+          schema_portion.each do |key, value|\n+            schema_portion[key] = resolve_nested_references(schema, value, list) unless list.include?(value)\n+          end\n+        end\n+      end\n+      schema_portion\n+    end\n+\n+    def resolve(schema, handle_schema_hash, list = [])\n+      # if we already dealt with the schema hash we have nothing left to do\n+      return handle_schema_hash if list.include?(handle_schema_hash)\n+      # remember the hash we are dealing with for the future\n+      list << handle_schema_hash\n+      # $ref is specified as 'SHOULD replace the current schema with the schema referenced by the value's URI' so we do exactly that\n+      if handle_schema_hash[\"$ref\"]\n+        _, ref_schema = JSON::Schema::RefAttribute.get_referenced_uri_and_schema(handle_schema_hash, schema, self)\n+        fail \"Could not find referenced schema #{handle_schema_hash[\"$ref\"]}\" unless ref_schema\n+        # translates to 'replace the current schema with the referenced one and resolve this instead'\n+        handle_schema_hash = resolve(ref_schema, ref_schema.schema, list)\n+      end\n+      # finally we must recursively walk through our schema and resolve nested schemas\n+      resolve_nested_references schema, handle_schema_hash, list","path":"lib/json-schema/validator.rb","position":52,"original_position":52,"commit_id":"5719c0c78d4fbc989f16a90f1bede4b7d4ab87d3","original_commit_id":"5719c0c78d4fbc989f16a90f1bede4b7d4ab87d3","user":{"login":"inglesp","id":28734,"avatar_url":"https://avatars.githubusercontent.com/u/28734?v=3","gravatar_id":"","url":"https://api.github.com/users/inglesp","html_url":"https://github.com/inglesp","followers_url":"https://api.github.com/users/inglesp/followers","following_url":"https://api.github.com/users/inglesp/following{/other_user}","gists_url":"https://api.github.com/users/inglesp/gists{/gist_id}","starred_url":"https://api.github.com/users/inglesp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/inglesp/subscriptions","organizations_url":"https://api.github.com/users/inglesp/orgs","repos_url":"https://api.github.com/users/inglesp/repos","events_url":"https://api.github.com/users/inglesp/events{/privacy}","received_events_url":"https://api.github.com/users/inglesp/received_events","type":"User","site_admin":false},"body":"Could you be consistent about calling functions with parentheses?","created_at":"2015-02-06T19:04:36Z","updated_at":"2015-02-06T19:04:36Z","html_url":"https://github.com/ruby-json-schema/json-schema/pull/222#discussion_r24263083","pull_request_url":"https://api.github.com/repos/ruby-json-schema/json-schema/pulls/222","_links":{"self":{"href":"https://api.github.com/repos/ruby-json-schema/json-schema/pulls/comments/24263083"},"html":{"href":"https://github.com/ruby-json-schema/json-schema/pull/222#discussion_r24263083"},"pull_request":{"href":"https://api.github.com/repos/ruby-json-schema/json-schema/pulls/222"}}},"pull_request":{"url":"https://api.github.com/repos/ruby-json-schema/json-schema/pulls/222","id":27968970,"html_url":"https://github.com/ruby-json-schema/json-schema/pull/222","diff_url":"https://github.com/ruby-json-schema/json-schema/pull/222.diff","patch_url":"https://github.com/ruby-json-schema/json-schema/pull/222.patch","issue_url":"https://api.github.com/repos/ruby-json-schema/json-schema/issues/222","number":222,"state":"open","locked":false,"title":"WIP: resolve refs in schemas in one extrapolated hash","user":{"login":"RST-J","id":4967885,"avatar_url":"https://avatars.githubusercontent.com/u/4967885?v=3","gravatar_id":"","url":"https://api.github.com/users/RST-J","html_url":"https://github.com/RST-J","followers_url":"https://api.github.com/users/RST-J/followers","following_url":"https://api.github.com/users/RST-J/following{/other_user}","gists_url":"https://api.github.com/users/RST-J/gists{/gist_id}","starred_url":"https://api.github.com/users/RST-J/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RST-J/subscriptions","organizations_url":"https://api.github.com/users/RST-J/orgs","repos_url":"https://api.github.com/users/RST-J/repos","events_url":"https://api.github.com/users/RST-J/events{/privacy}","received_events_url":"https://api.github.com/users/RST-J/received_events","type":"User","site_admin":false},"body":"This is a first shot at generating a fully resolved schema hash as requested in #32.\r\nI commented very verbosely so you can directly follow my ideas. Any comments, improvements et al?\r\n\r\nNotes:\r\n- So far this only works with $ref but can be easily extended for extends too\r\n- in the test ```test_linked_list_ref``` using the file path instead of the URL does not work (see comment)\r\n- pretty printing a cyclic hash or using it for validation kills kittens\r\n\r\nQuestions:\r\n1. Has someone an idea why using the file path in the test does not work?\r\n2. Is there anything missing to be draft4 compliant?\r\n","created_at":"2015-01-24T01:36:11Z","updated_at":"2015-02-06T19:04:36Z","closed_at":null,"merged_at":null,"merge_commit_sha":"cc11559b2067cef1b2e2b6fe7a69e69baf3dc66d","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ruby-json-schema/json-schema/pulls/222/commits","review_comments_url":"https://api.github.com/repos/ruby-json-schema/json-schema/pulls/222/comments","review_comment_url":"https://api.github.com/repos/ruby-json-schema/json-schema/pulls/comments/{number}","comments_url":"https://api.github.com/repos/ruby-json-schema/json-schema/issues/222/comments","statuses_url":"https://api.github.com/repos/ruby-json-schema/json-schema/statuses/5719c0c78d4fbc989f16a90f1bede4b7d4ab87d3","head":{"label":"RST-J:fully_resolve_schema","ref":"fully_resolve_schema","sha":"5719c0c78d4fbc989f16a90f1bede4b7d4ab87d3","user":{"login":"RST-J","id":4967885,"avatar_url":"https://avatars.githubusercontent.com/u/4967885?v=3","gravatar_id":"","url":"https://api.github.com/users/RST-J","html_url":"https://github.com/RST-J","followers_url":"https://api.github.com/users/RST-J/followers","following_url":"https://api.github.com/users/RST-J/following{/other_user}","gists_url":"https://api.github.com/users/RST-J/gists{/gist_id}","starred_url":"https://api.github.com/users/RST-J/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RST-J/subscriptions","organizations_url":"https://api.github.com/users/RST-J/orgs","repos_url":"https://api.github.com/users/RST-J/repos","events_url":"https://api.github.com/users/RST-J/events{/privacy}","received_events_url":"https://api.github.com/users/RST-J/received_events","type":"User","site_admin":false},"repo":{"id":24468689,"name":"json-schema","full_name":"RST-J/json-schema","owner":{"login":"RST-J","id":4967885,"avatar_url":"https://avatars.githubusercontent.com/u/4967885?v=3","gravatar_id":"","url":"https://api.github.com/users/RST-J","html_url":"https://github.com/RST-J","followers_url":"https://api.github.com/users/RST-J/followers","following_url":"https://api.github.com/users/RST-J/following{/other_user}","gists_url":"https://api.github.com/users/RST-J/gists{/gist_id}","starred_url":"https://api.github.com/users/RST-J/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RST-J/subscriptions","organizations_url":"https://api.github.com/users/RST-J/orgs","repos_url":"https://api.github.com/users/RST-J/repos","events_url":"https://api.github.com/users/RST-J/events{/privacy}","received_events_url":"https://api.github.com/users/RST-J/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/RST-J/json-schema","description":"Ruby JSON Schema Validator","fork":true,"url":"https://api.github.com/repos/RST-J/json-schema","forks_url":"https://api.github.com/repos/RST-J/json-schema/forks","keys_url":"https://api.github.com/repos/RST-J/json-schema/keys{/key_id}","collaborators_url":"https://api.github.com/repos/RST-J/json-schema/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/RST-J/json-schema/teams","hooks_url":"https://api.github.com/repos/RST-J/json-schema/hooks","issue_events_url":"https://api.github.com/repos/RST-J/json-schema/issues/events{/number}","events_url":"https://api.github.com/repos/RST-J/json-schema/events","assignees_url":"https://api.github.com/repos/RST-J/json-schema/assignees{/user}","branches_url":"https://api.github.com/repos/RST-J/json-schema/branches{/branch}","tags_url":"https://api.github.com/repos/RST-J/json-schema/tags","blobs_url":"https://api.github.com/repos/RST-J/json-schema/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/RST-J/json-schema/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/RST-J/json-schema/git/refs{/sha}","trees_url":"https://api.github.com/repos/RST-J/json-schema/git/trees{/sha}","statuses_url":"https://api.github.com/repos/RST-J/json-schema/statuses/{sha}","languages_url":"https://api.github.com/repos/RST-J/json-schema/languages","stargazers_url":"https://api.github.com/repos/RST-J/json-schema/stargazers","contributors_url":"https://api.github.com/repos/RST-J/json-schema/contributors","subscribers_url":"https://api.github.com/repos/RST-J/json-schema/subscribers","subscription_url":"https://api.github.com/repos/RST-J/json-schema/subscription","commits_url":"https://api.github.com/repos/RST-J/json-schema/commits{/sha}","git_commits_url":"https://api.github.com/repos/RST-J/json-schema/git/commits{/sha}","comments_url":"https://api.github.com/repos/RST-J/json-schema/comments{/number}","issue_comment_url":"https://api.github.com/repos/RST-J/json-schema/issues/comments/{number}","contents_url":"https://api.github.com/repos/RST-J/json-schema/contents/{+path}","compare_url":"https://api.github.com/repos/RST-J/json-schema/compare/{base}...{head}","merges_url":"https://api.github.com/repos/RST-J/json-schema/merges","archive_url":"https://api.github.com/repos/RST-J/json-schema/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/RST-J/json-schema/downloads","issues_url":"https://api.github.com/repos/RST-J/json-schema/issues{/number}","pulls_url":"https://api.github.com/repos/RST-J/json-schema/pulls{/number}","milestones_url":"https://api.github.com/repos/RST-J/json-schema/milestones{/number}","notifications_url":"https://api.github.com/repos/RST-J/json-schema/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/RST-J/json-schema/labels{/name}","releases_url":"https://api.github.com/repos/RST-J/json-schema/releases{/id}","created_at":"2014-09-25T17:47:41Z","updated_at":"2015-01-20T07:52:02Z","pushed_at":"2015-01-24T12:32:14Z","git_url":"git://github.com/RST-J/json-schema.git","ssh_url":"git@github.com:RST-J/json-schema.git","clone_url":"https://github.com/RST-J/json-schema.git","svn_url":"https://github.com/RST-J/json-schema","homepage":"","size":928,"stargazers_count":0,"watchers_count":0,"language":"Ruby","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":"ruby-json-schema:master","ref":"master","sha":"aded4d798a48545184dae7ae0a3bb41ec2794c88","user":{"login":"ruby-json-schema","id":9450367,"avatar_url":"https://avatars.githubusercontent.com/u/9450367?v=3","gravatar_id":"","url":"https://api.github.com/users/ruby-json-schema","html_url":"https://github.com/ruby-json-schema","followers_url":"https://api.github.com/users/ruby-json-schema/followers","following_url":"https://api.github.com/users/ruby-json-schema/following{/other_user}","gists_url":"https://api.github.com/users/ruby-json-schema/gists{/gist_id}","starred_url":"https://api.github.com/users/ruby-json-schema/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ruby-json-schema/subscriptions","organizations_url":"https://api.github.com/users/ruby-json-schema/orgs","repos_url":"https://api.github.com/users/ruby-json-schema/repos","events_url":"https://api.github.com/users/ruby-json-schema/events{/privacy}","received_events_url":"https://api.github.com/users/ruby-json-schema/received_events","type":"Organization","site_admin":false},"repo":{"id":1110217,"name":"json-schema","full_name":"ruby-json-schema/json-schema","owner":{"login":"ruby-json-schema","id":9450367,"avatar_url":"https://avatars.githubusercontent.com/u/9450367?v=3","gravatar_id":"","url":"https://api.github.com/users/ruby-json-schema","html_url":"https://github.com/ruby-json-schema","followers_url":"https://api.github.com/users/ruby-json-schema/followers","following_url":"https://api.github.com/users/ruby-json-schema/following{/other_user}","gists_url":"https://api.github.com/users/ruby-json-schema/gists{/gist_id}","starred_url":"https://api.github.com/users/ruby-json-schema/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ruby-json-schema/subscriptions","organizations_url":"https://api.github.com/users/ruby-json-schema/orgs","repos_url":"https://api.github.com/users/ruby-json-schema/repos","events_url":"https://api.github.com/users/ruby-json-schema/events{/privacy}","received_events_url":"https://api.github.com/users/ruby-json-schema/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ruby-json-schema/json-schema","description":"Ruby JSON Schema Validator","fork":false,"url":"https://api.github.com/repos/ruby-json-schema/json-schema","forks_url":"https://api.github.com/repos/ruby-json-schema/json-schema/forks","keys_url":"https://api.github.com/repos/ruby-json-schema/json-schema/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ruby-json-schema/json-schema/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ruby-json-schema/json-schema/teams","hooks_url":"https://api.github.com/repos/ruby-json-schema/json-schema/hooks","issue_events_url":"https://api.github.com/repos/ruby-json-schema/json-schema/issues/events{/number}","events_url":"https://api.github.com/repos/ruby-json-schema/json-schema/events","assignees_url":"https://api.github.com/repos/ruby-json-schema/json-schema/assignees{/user}","branches_url":"https://api.github.com/repos/ruby-json-schema/json-schema/branches{/branch}","tags_url":"https://api.github.com/repos/ruby-json-schema/json-schema/tags","blobs_url":"https://api.github.com/repos/ruby-json-schema/json-schema/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ruby-json-schema/json-schema/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ruby-json-schema/json-schema/git/refs{/sha}","trees_url":"https://api.github.com/repos/ruby-json-schema/json-schema/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ruby-json-schema/json-schema/statuses/{sha}","languages_url":"https://api.github.com/repos/ruby-json-schema/json-schema/languages","stargazers_url":"https://api.github.com/repos/ruby-json-schema/json-schema/stargazers","contributors_url":"https://api.github.com/repos/ruby-json-schema/json-schema/contributors","subscribers_url":"https://api.github.com/repos/ruby-json-schema/json-schema/subscribers","subscription_url":"https://api.github.com/repos/ruby-json-schema/json-schema/subscription","commits_url":"https://api.github.com/repos/ruby-json-schema/json-schema/commits{/sha}","git_commits_url":"https://api.github.com/repos/ruby-json-schema/json-schema/git/commits{/sha}","comments_url":"https://api.github.com/repos/ruby-json-schema/json-schema/comments{/number}","issue_comment_url":"https://api.github.com/repos/ruby-json-schema/json-schema/issues/comments/{number}","contents_url":"https://api.github.com/repos/ruby-json-schema/json-schema/contents/{+path}","compare_url":"https://api.github.com/repos/ruby-json-schema/json-schema/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ruby-json-schema/json-schema/merges","archive_url":"https://api.github.com/repos/ruby-json-schema/json-schema/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ruby-json-schema/json-schema/downloads","issues_url":"https://api.github.com/repos/ruby-json-schema/json-schema/issues{/number}","pulls_url":"https://api.github.com/repos/ruby-json-schema/json-schema/pulls{/number}","milestones_url":"https://api.github.com/repos/ruby-json-schema/json-schema/milestones{/number}","notifications_url":"https://api.github.com/repos/ruby-json-schema/json-schema/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ruby-json-schema/json-schema/labels{/name}","releases_url":"https://api.github.com/repos/ruby-json-schema/json-schema/releases{/id}","created_at":"2010-11-24T20:05:16Z","updated_at":"2015-02-06T03:33:21Z","pushed_at":"2015-01-28T08:22:45Z","git_url":"git://github.com/ruby-json-schema/json-schema.git","ssh_url":"git@github.com:ruby-json-schema/json-schema.git","clone_url":"https://github.com/ruby-json-schema/json-schema.git","svn_url":"https://github.com/ruby-json-schema/json-schema","homepage":"","size":1843,"stargazers_count":406,"watchers_count":406,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":102,"mirror_url":null,"open_issues_count":35,"forks":102,"open_issues":35,"watchers":406,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ruby-json-schema/json-schema/pulls/222"},"html":{"href":"https://github.com/ruby-json-schema/json-schema/pull/222"},"issue":{"href":"https://api.github.com/repos/ruby-json-schema/json-schema/issues/222"},"comments":{"href":"https://api.github.com/repos/ruby-json-schema/json-schema/issues/222/comments"},"review_comments":{"href":"https://api.github.com/repos/ruby-json-schema/json-schema/pulls/222/comments"},"review_comment":{"href":"https://api.github.com/repos/ruby-json-schema/json-schema/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/ruby-json-schema/json-schema/pulls/222/commits"},"statuses":{"href":"https://api.github.com/repos/ruby-json-schema/json-schema/statuses/5719c0c78d4fbc989f16a90f1bede4b7d4ab87d3"}}}}