{"action":"created","comment":{"url":"https://api.github.com/repos/GPII/gpii-json-schema/pulls/comments/72984604","id":72984604,"diff_hunk":"@@ -0,0 +1,111 @@\n+/*\n+\n+    A parser that resolves `$ref` references in JSON Schema definitions.  See the documentation for details:\n+\n+    https://github.com/the-t-in-rtf/gpii-json-schema/blob/master/docs/parser.md\n+\n+*/\n+/* eslint-env node */\n+\"use strict\";\n+var fluid = require(\"infusion\");\n+var gpii  = fluid.registerNamespace(\"gpii\");\n+\n+var fs   = require(\"fs\");\n+var path = require(\"path\");\n+\n+var $RefParser = require(\"json-schema-ref-parser\");\n+\n+fluid.registerNamespace(\"gpii.schema.parser\");\n+\n+/**\n+ *\n+ * @param that - The parser component itself\n+ *\n+ * Starts the process of dereferencing all schemas found in `options.schemaDirs`.  Wraps them in a sequence to ensure\n+ * that `onSchemasDereferenced` is fired once all of the schemas are dereferenced.\n+ */\n+gpii.schema.parser.loadSchemas = function (that) {\n+    var promises = [];\n+    fluid.each(fluid.makeArray(that.options.schemaDirs), function (schemaDir) {\n+        var resolvePathToDir = fluid.module.resolvePath(schemaDir);\n+        fluid.each(fs.readdirSync(resolvePathToDir), function (filename) {\n+            if (filename.match(/.json$/i)) {\n+                var fullPathToFile = path.resolve(resolvePathToDir, filename);\n+                promises.push(gpii.schema.parser.dereferenceSchema(that, fullPathToFile, filename));\n+            }\n+        });\n+    });\n+\n+    fluid.promise.sequence(promises).then(\n+        function () { that.events.onSchemasDereferenced.fire(that); },\n+        function (error) {\n+            fluid.fail(error.message || error);\n+        }\n+    );\n+};\n+\n+\n+/**\n+ * Dereference all `$ref` links for a single schema. See the documentation for details.\n+ *\n+ * https://github.com/the-t-in-rtf/gpii-json-schema/blob/master/docs/parser.md#gpiischemaparserdereferenceschemathat-schemapath-schemakey\n+ *\n+ * @param that - The parser component itself.\n+ * @param schemaPath {String} - The full path to the schema we are derferencing.\n+ * @param schemaKey {String} - The filename/id of the schema we are dereferencing.\n+ * @returns A `fluid.promise` that will be resolved once the parser has finished dereferencing the schema.\n+ *\n+ */\n+gpii.schema.parser.dereferenceSchema = function (that, schemaPath, schemaKey) {\n+    var promise = fluid.promise();\n+    var parser = new $RefParser(); // jshint ignore:line\n+\n+    parser.dereference(schemaPath, that.options.parserOptions, gpii.schema.parser.getParserCallback(that, schemaKey, promise));\n+    return promise;\n+};\n+\n+/**\n+ *\n+ * Wrap the normal callback used by the parser in a `fluid.promise`.\n+ *\n+ * @param that - The parser component itself.\n+ * @param schemaKey - The filename/id of the schema we are dereferencing.\n+ * @param promise - The promise the parser will either resolve or reject once it completes its work.\n+ * @returns A {Function} that can be passed directly to the parser as a callback.\n+ *\n+ */\n+gpii.schema.parser.getParserCallback = function (that, schemaKey, promise) {\n+    return function (error, schema) {\n+        if (error) {\n+            promise.reject(error);\n+        }\n+        else {\n+            // Our keys have periods in them, which the change applier will interpret as a deeper part of the path","path":"src/js/server/parser.js","position":83,"original_position":83,"commit_id":"e1a3bc506b3137c29fc9f05de2ff7cc7dd17f5a8","original_commit_id":"e1a3bc506b3137c29fc9f05de2ff7cc7dd17f5a8","user":{"login":"amb26","id":561418,"avatar_url":"https://avatars.githubusercontent.com/u/561418?v=3","gravatar_id":"","url":"https://api.github.com/users/amb26","html_url":"https://github.com/amb26","followers_url":"https://api.github.com/users/amb26/followers","following_url":"https://api.github.com/users/amb26/following{/other_user}","gists_url":"https://api.github.com/users/amb26/gists{/gist_id}","starred_url":"https://api.github.com/users/amb26/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amb26/subscriptions","organizations_url":"https://api.github.com/users/amb26/orgs","repos_url":"https://api.github.com/users/amb26/repos","events_url":"https://api.github.com/users/amb26/events{/privacy}","received_events_url":"https://api.github.com/users/amb26/received_events","type":"User","site_admin":false},"body":"There are a couple of ways round this - either i) supply the path as an array of segments rather than a string, or ii) apply escaping to the path so that . is escaped to \\. ","created_at":"2016-08-01T14:15:32Z","updated_at":"2016-08-01T14:15:32Z","html_url":"https://github.com/GPII/gpii-json-schema/pull/5#discussion_r72984604","pull_request_url":"https://api.github.com/repos/GPII/gpii-json-schema/pulls/5","_links":{"self":{"href":"https://api.github.com/repos/GPII/gpii-json-schema/pulls/comments/72984604"},"html":{"href":"https://github.com/GPII/gpii-json-schema/pull/5#discussion_r72984604"},"pull_request":{"href":"https://api.github.com/repos/GPII/gpii-json-schema/pulls/5"}}},"pull_request":{"url":"https://api.github.com/repos/GPII/gpii-json-schema/pulls/5","id":49562788,"html_url":"https://github.com/GPII/gpii-json-schema/pull/5","diff_url":"https://github.com/GPII/gpii-json-schema/pull/5.diff","patch_url":"https://github.com/GPII/gpii-json-schema/pull/5.patch","issue_url":"https://api.github.com/repos/GPII/gpii-json-schema/issues/5","number":5,"state":"open","locked":false,"title":"GPII-1336: update `schemaMiddleware` to work with more than just POST data...","user":{"login":"the-t-in-rtf","id":5765222,"avatar_url":"https://avatars.githubusercontent.com/u/5765222?v=3","gravatar_id":"","url":"https://api.github.com/users/the-t-in-rtf","html_url":"https://github.com/the-t-in-rtf","followers_url":"https://api.github.com/users/the-t-in-rtf/followers","following_url":"https://api.github.com/users/the-t-in-rtf/following{/other_user}","gists_url":"https://api.github.com/users/the-t-in-rtf/gists{/gist_id}","starred_url":"https://api.github.com/users/the-t-in-rtf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/the-t-in-rtf/subscriptions","organizations_url":"https://api.github.com/users/the-t-in-rtf/orgs","repos_url":"https://api.github.com/users/the-t-in-rtf/repos","events_url":"https://api.github.com/users/the-t-in-rtf/events{/privacy}","received_events_url":"https://api.github.com/users/the-t-in-rtf/received_events","type":"User","site_admin":false},"body":"See [GPII-1336](https://issues.gpii.net/browse/GPII-1336) for details.","created_at":"2015-11-03T14:40:00Z","updated_at":"2016-08-01T14:15:32Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d42b4f958becb4c2433526e7a49baa017889353b","assignee":{"login":"amb26","id":561418,"avatar_url":"https://avatars.githubusercontent.com/u/561418?v=3","gravatar_id":"","url":"https://api.github.com/users/amb26","html_url":"https://github.com/amb26","followers_url":"https://api.github.com/users/amb26/followers","following_url":"https://api.github.com/users/amb26/following{/other_user}","gists_url":"https://api.github.com/users/amb26/gists{/gist_id}","starred_url":"https://api.github.com/users/amb26/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amb26/subscriptions","organizations_url":"https://api.github.com/users/amb26/orgs","repos_url":"https://api.github.com/users/amb26/repos","events_url":"https://api.github.com/users/amb26/events{/privacy}","received_events_url":"https://api.github.com/users/amb26/received_events","type":"User","site_admin":false},"assignees":[{"login":"amb26","id":561418,"avatar_url":"https://avatars.githubusercontent.com/u/561418?v=3","gravatar_id":"","url":"https://api.github.com/users/amb26","html_url":"https://github.com/amb26","followers_url":"https://api.github.com/users/amb26/followers","following_url":"https://api.github.com/users/amb26/following{/other_user}","gists_url":"https://api.github.com/users/amb26/gists{/gist_id}","starred_url":"https://api.github.com/users/amb26/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amb26/subscriptions","organizations_url":"https://api.github.com/users/amb26/orgs","repos_url":"https://api.github.com/users/amb26/repos","events_url":"https://api.github.com/users/amb26/events{/privacy}","received_events_url":"https://api.github.com/users/amb26/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/GPII/gpii-json-schema/pulls/5/commits","review_comments_url":"https://api.github.com/repos/GPII/gpii-json-schema/pulls/5/comments","review_comment_url":"https://api.github.com/repos/GPII/gpii-json-schema/pulls/comments{/number}","comments_url":"https://api.github.com/repos/GPII/gpii-json-schema/issues/5/comments","statuses_url":"https://api.github.com/repos/GPII/gpii-json-schema/statuses/e1a3bc506b3137c29fc9f05de2ff7cc7dd17f5a8","head":{"label":"the-t-in-rtf:GPII-1336","ref":"GPII-1336","sha":"e1a3bc506b3137c29fc9f05de2ff7cc7dd17f5a8","user":{"login":"the-t-in-rtf","id":5765222,"avatar_url":"https://avatars.githubusercontent.com/u/5765222?v=3","gravatar_id":"","url":"https://api.github.com/users/the-t-in-rtf","html_url":"https://github.com/the-t-in-rtf","followers_url":"https://api.github.com/users/the-t-in-rtf/followers","following_url":"https://api.github.com/users/the-t-in-rtf/following{/other_user}","gists_url":"https://api.github.com/users/the-t-in-rtf/gists{/gist_id}","starred_url":"https://api.github.com/users/the-t-in-rtf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/the-t-in-rtf/subscriptions","organizations_url":"https://api.github.com/users/the-t-in-rtf/orgs","repos_url":"https://api.github.com/users/the-t-in-rtf/repos","events_url":"https://api.github.com/users/the-t-in-rtf/events{/privacy}","received_events_url":"https://api.github.com/users/the-t-in-rtf/received_events","type":"User","site_admin":false},"repo":{"id":41099035,"name":"gpii-json-schema","full_name":"the-t-in-rtf/gpii-json-schema","owner":{"login":"the-t-in-rtf","id":5765222,"avatar_url":"https://avatars.githubusercontent.com/u/5765222?v=3","gravatar_id":"","url":"https://api.github.com/users/the-t-in-rtf","html_url":"https://github.com/the-t-in-rtf","followers_url":"https://api.github.com/users/the-t-in-rtf/followers","following_url":"https://api.github.com/users/the-t-in-rtf/following{/other_user}","gists_url":"https://api.github.com/users/the-t-in-rtf/gists{/gist_id}","starred_url":"https://api.github.com/users/the-t-in-rtf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/the-t-in-rtf/subscriptions","organizations_url":"https://api.github.com/users/the-t-in-rtf/orgs","repos_url":"https://api.github.com/users/the-t-in-rtf/repos","events_url":"https://api.github.com/users/the-t-in-rtf/events{/privacy}","received_events_url":"https://api.github.com/users/the-t-in-rtf/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/the-t-in-rtf/gpii-json-schema","description":"","fork":true,"url":"https://api.github.com/repos/the-t-in-rtf/gpii-json-schema","forks_url":"https://api.github.com/repos/the-t-in-rtf/gpii-json-schema/forks","keys_url":"https://api.github.com/repos/the-t-in-rtf/gpii-json-schema/keys{/key_id}","collaborators_url":"https://api.github.com/repos/the-t-in-rtf/gpii-json-schema/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/the-t-in-rtf/gpii-json-schema/teams","hooks_url":"https://api.github.com/repos/the-t-in-rtf/gpii-json-schema/hooks","issue_events_url":"https://api.github.com/repos/the-t-in-rtf/gpii-json-schema/issues/events{/number}","events_url":"https://api.github.com/repos/the-t-in-rtf/gpii-json-schema/events","assignees_url":"https://api.github.com/repos/the-t-in-rtf/gpii-json-schema/assignees{/user}","branches_url":"https://api.github.com/repos/the-t-in-rtf/gpii-json-schema/branches{/branch}","tags_url":"https://api.github.com/repos/the-t-in-rtf/gpii-json-schema/tags","blobs_url":"https://api.github.com/repos/the-t-in-rtf/gpii-json-schema/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/the-t-in-rtf/gpii-json-schema/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/the-t-in-rtf/gpii-json-schema/git/refs{/sha}","trees_url":"https://api.github.com/repos/the-t-in-rtf/gpii-json-schema/git/trees{/sha}","statuses_url":"https://api.github.com/repos/the-t-in-rtf/gpii-json-schema/statuses/{sha}","languages_url":"https://api.github.com/repos/the-t-in-rtf/gpii-json-schema/languages","stargazers_url":"https://api.github.com/repos/the-t-in-rtf/gpii-json-schema/stargazers","contributors_url":"https://api.github.com/repos/the-t-in-rtf/gpii-json-schema/contributors","subscribers_url":"https://api.github.com/repos/the-t-in-rtf/gpii-json-schema/subscribers","subscription_url":"https://api.github.com/repos/the-t-in-rtf/gpii-json-schema/subscription","commits_url":"https://api.github.com/repos/the-t-in-rtf/gpii-json-schema/commits{/sha}","git_commits_url":"https://api.github.com/repos/the-t-in-rtf/gpii-json-schema/git/commits{/sha}","comments_url":"https://api.github.com/repos/the-t-in-rtf/gpii-json-schema/comments{/number}","issue_comment_url":"https://api.github.com/repos/the-t-in-rtf/gpii-json-schema/issues/comments{/number}","contents_url":"https://api.github.com/repos/the-t-in-rtf/gpii-json-schema/contents/{+path}","compare_url":"https://api.github.com/repos/the-t-in-rtf/gpii-json-schema/compare/{base}...{head}","merges_url":"https://api.github.com/repos/the-t-in-rtf/gpii-json-schema/merges","archive_url":"https://api.github.com/repos/the-t-in-rtf/gpii-json-schema/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/the-t-in-rtf/gpii-json-schema/downloads","issues_url":"https://api.github.com/repos/the-t-in-rtf/gpii-json-schema/issues{/number}","pulls_url":"https://api.github.com/repos/the-t-in-rtf/gpii-json-schema/pulls{/number}","milestones_url":"https://api.github.com/repos/the-t-in-rtf/gpii-json-schema/milestones{/number}","notifications_url":"https://api.github.com/repos/the-t-in-rtf/gpii-json-schema/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/the-t-in-rtf/gpii-json-schema/labels{/name}","releases_url":"https://api.github.com/repos/the-t-in-rtf/gpii-json-schema/releases{/id}","deployments_url":"https://api.github.com/repos/the-t-in-rtf/gpii-json-schema/deployments","created_at":"2015-08-20T14:05:14Z","updated_at":"2015-08-19T15:43:40Z","pushed_at":"2016-06-27T12:47:26Z","git_url":"git://github.com/the-t-in-rtf/gpii-json-schema.git","ssh_url":"git@github.com:the-t-in-rtf/gpii-json-schema.git","clone_url":"https://github.com/the-t-in-rtf/gpii-json-schema.git","svn_url":"https://github.com/the-t-in-rtf/gpii-json-schema","homepage":null,"size":331,"stargazers_count":0,"watchers_count":0,"language":null,"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":"GPII:master","ref":"master","sha":"299c1f91d49ce9fd6ab1c20d1987be3c388e447a","user":{"login":"GPII","id":1343050,"avatar_url":"https://avatars.githubusercontent.com/u/1343050?v=3","gravatar_id":"","url":"https://api.github.com/users/GPII","html_url":"https://github.com/GPII","followers_url":"https://api.github.com/users/GPII/followers","following_url":"https://api.github.com/users/GPII/following{/other_user}","gists_url":"https://api.github.com/users/GPII/gists{/gist_id}","starred_url":"https://api.github.com/users/GPII/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GPII/subscriptions","organizations_url":"https://api.github.com/users/GPII/orgs","repos_url":"https://api.github.com/users/GPII/repos","events_url":"https://api.github.com/users/GPII/events{/privacy}","received_events_url":"https://api.github.com/users/GPII/received_events","type":"Organization","site_admin":false},"repo":{"id":41043555,"name":"gpii-json-schema","full_name":"GPII/gpii-json-schema","owner":{"login":"GPII","id":1343050,"avatar_url":"https://avatars.githubusercontent.com/u/1343050?v=3","gravatar_id":"","url":"https://api.github.com/users/GPII","html_url":"https://github.com/GPII","followers_url":"https://api.github.com/users/GPII/followers","following_url":"https://api.github.com/users/GPII/following{/other_user}","gists_url":"https://api.github.com/users/GPII/gists{/gist_id}","starred_url":"https://api.github.com/users/GPII/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GPII/subscriptions","organizations_url":"https://api.github.com/users/GPII/orgs","repos_url":"https://api.github.com/users/GPII/repos","events_url":"https://api.github.com/users/GPII/events{/privacy}","received_events_url":"https://api.github.com/users/GPII/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/GPII/gpii-json-schema","description":"","fork":false,"url":"https://api.github.com/repos/GPII/gpii-json-schema","forks_url":"https://api.github.com/repos/GPII/gpii-json-schema/forks","keys_url":"https://api.github.com/repos/GPII/gpii-json-schema/keys{/key_id}","collaborators_url":"https://api.github.com/repos/GPII/gpii-json-schema/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/GPII/gpii-json-schema/teams","hooks_url":"https://api.github.com/repos/GPII/gpii-json-schema/hooks","issue_events_url":"https://api.github.com/repos/GPII/gpii-json-schema/issues/events{/number}","events_url":"https://api.github.com/repos/GPII/gpii-json-schema/events","assignees_url":"https://api.github.com/repos/GPII/gpii-json-schema/assignees{/user}","branches_url":"https://api.github.com/repos/GPII/gpii-json-schema/branches{/branch}","tags_url":"https://api.github.com/repos/GPII/gpii-json-schema/tags","blobs_url":"https://api.github.com/repos/GPII/gpii-json-schema/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/GPII/gpii-json-schema/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/GPII/gpii-json-schema/git/refs{/sha}","trees_url":"https://api.github.com/repos/GPII/gpii-json-schema/git/trees{/sha}","statuses_url":"https://api.github.com/repos/GPII/gpii-json-schema/statuses/{sha}","languages_url":"https://api.github.com/repos/GPII/gpii-json-schema/languages","stargazers_url":"https://api.github.com/repos/GPII/gpii-json-schema/stargazers","contributors_url":"https://api.github.com/repos/GPII/gpii-json-schema/contributors","subscribers_url":"https://api.github.com/repos/GPII/gpii-json-schema/subscribers","subscription_url":"https://api.github.com/repos/GPII/gpii-json-schema/subscription","commits_url":"https://api.github.com/repos/GPII/gpii-json-schema/commits{/sha}","git_commits_url":"https://api.github.com/repos/GPII/gpii-json-schema/git/commits{/sha}","comments_url":"https://api.github.com/repos/GPII/gpii-json-schema/comments{/number}","issue_comment_url":"https://api.github.com/repos/GPII/gpii-json-schema/issues/comments{/number}","contents_url":"https://api.github.com/repos/GPII/gpii-json-schema/contents/{+path}","compare_url":"https://api.github.com/repos/GPII/gpii-json-schema/compare/{base}...{head}","merges_url":"https://api.github.com/repos/GPII/gpii-json-schema/merges","archive_url":"https://api.github.com/repos/GPII/gpii-json-schema/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/GPII/gpii-json-schema/downloads","issues_url":"https://api.github.com/repos/GPII/gpii-json-schema/issues{/number}","pulls_url":"https://api.github.com/repos/GPII/gpii-json-schema/pulls{/number}","milestones_url":"https://api.github.com/repos/GPII/gpii-json-schema/milestones{/number}","notifications_url":"https://api.github.com/repos/GPII/gpii-json-schema/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/GPII/gpii-json-schema/labels{/name}","releases_url":"https://api.github.com/repos/GPII/gpii-json-schema/releases{/id}","deployments_url":"https://api.github.com/repos/GPII/gpii-json-schema/deployments","created_at":"2015-08-19T15:43:40Z","updated_at":"2015-08-19T15:43:40Z","pushed_at":"2016-06-27T12:47:27Z","git_url":"git://github.com/GPII/gpii-json-schema.git","ssh_url":"git@github.com:GPII/gpii-json-schema.git","clone_url":"https://github.com/GPII/gpii-json-schema.git","svn_url":"https://github.com/GPII/gpii-json-schema","homepage":null,"size":309,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":1,"forks":1,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/GPII/gpii-json-schema/pulls/5"},"html":{"href":"https://github.com/GPII/gpii-json-schema/pull/5"},"issue":{"href":"https://api.github.com/repos/GPII/gpii-json-schema/issues/5"},"comments":{"href":"https://api.github.com/repos/GPII/gpii-json-schema/issues/5/comments"},"review_comments":{"href":"https://api.github.com/repos/GPII/gpii-json-schema/pulls/5/comments"},"review_comment":{"href":"https://api.github.com/repos/GPII/gpii-json-schema/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/GPII/gpii-json-schema/pulls/5/commits"},"statuses":{"href":"https://api.github.com/repos/GPII/gpii-json-schema/statuses/e1a3bc506b3137c29fc9f05de2ff7cc7dd17f5a8"}}}}
{"actor":{"display_login":"amb26"}}