Repository: stoplightio/spectral
Pull request #1532 (2021-03-02 15:55:20)

chore(deps-dev): bump patch-package from 6.2.2 to 6.4.4
Bumps [patch-package](https://github.com/ds300/patch-package) from 6.2.2 to 6.4.4.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a href="https://github.com/ds300/patch-package/releases">patch-package's releases</a>.</em></p>
<blockquote>
<h2>v6.4.4</h2>
<ul>
<li>refine --create-issue template</li>
</ul>
<p><a href="https://github.com/ds300/patch-package/compare/v6.4.3...v6.4.4">https://github.com/ds300/patch-package/compare/v6.4.3...v6.4.4</a></p>
<h2>v6.4.3</h2>
<ul>
<li>Ensure real path is used when copying package contents. Potentially adds pnpm support (contribution from <a href="https://github.com/milahu"><code>@​milahu</code></a> in <a href="https://github-redirect.dependabot.com/ds300/patch-package/issues/252">#252</a></li>
</ul>
<p><a href="https://github.com/ds300/patch-package/compare/v6.4.2...v6.4.3">https://github.com/ds300/patch-package/compare/v6.4.2...v6.4.3</a></p>
<h2>v6.4.2</h2>
<ul>
<li>add package version to create-issue template</li>
</ul>
<p><a href="https://github.com/ds300/patch-package/compare/v6.4.1...v6.4.2">https://github.com/ds300/patch-package/compare/v6.4.1...v6.4.2</a></p>
<h2>v6.4.1</h2>
<ul>
<li>Add backlink to patch-package repo to collect public usage of --create-issue</li>
</ul>
<p><a href="https://github.com/ds300/patch-package/compare/v6.4.0...v6.4.1">https://github.com/ds300/patch-package/compare/v6.4.0...v6.4.1</a></p>
<h2>v6.4.0</h2>
<ul>
<li>add create-issue feature</li>
</ul>
<p><a href="https://github.com/ds300/patch-package/compare/v6.3.1...v6.4.0">https://github.com/ds300/patch-package/compare/v6.3.1...v6.4.0</a></p>
<h2>v6.3.1</h2>
<ul>
<li>Fix another createPatch bug involving .git folder hygiene (contribution from <a href="https://github.com/gomain"><code>@​gomain</code></a> in <a href="https://github-redirect.dependabot.com/ds300/patch-package/issues/258">#258</a>)</li>
</ul>
<p><a href="https://github.com/ds300/patch-package/compare/v6.3.0...v6.3.1">https://github.com/ds300/patch-package/compare/v6.3.0...v6.3.1</a></p>
<h2>v6.3.0</h2>
<ul>
<li>Add --error-on-fail cli option</li>
<li>Collate errors and warnings to avoid exiting early (with help from <a href="https://github.com/akwodkiewicz"><code>@​akwodkiewicz</code></a> in <a href="https://github-redirect.dependabot.com/ds300/patch-package/issues/217">#217</a>)</li>
<li>Fix .dev.patch suffix bug (with help from <a href="https://github.com/pdcastro"><code>@​pdcastro</code></a> in <a href="https://github-redirect.dependabot.com/ds300/patch-package/issues/224">#224</a>)</li>
<li>Support build metadata in package.json version strings (with help from <a href="https://github.com/snowystinger"><code>@​snowystinger</code></a> in <a href="https://github-redirect.dependabot.com/ds300/patch-package/issues/213">#213</a>)</li>
<li>Change 'no patch files found' message from red to blue (contribution from <a href="https://github.com/dmhalejr"><code>@​dmhalejr</code></a> in <a href="https://github-redirect.dependabot.com/ds300/patch-package/issues/211">#211</a>)</li>
<li>Fix environment variable propogation for spawned tasks (contribution from <a href="https://github.com/chpio"><code>@​chpio</code></a> in <a href="https://github-redirect.dependabot.com/ds300/patch-package/issues/223">#223</a>)</li>
<li>Add --patch-dir option to readme (contribution from <a href="https://github.com/mikehardy"><code>@​mikehardy</code></a> in <a href="https://github-redirect.dependabot.com/ds300/patch-package/issues/225">#225</a>)</li>
<li>Fix createPatch bug involving .git folder hygiene (contribution from <a href="https://github.com/haroenv"><code>@​haroenv</code></a> in <a href="https://github-redirect.dependabot.com/ds300/patch-package/issues/231">#231</a>
<a href="https://github.com/ds300/patch-package/compare/v6.2.2...v6.3.0">https://github.com/ds300/patch-package/compare/v6.2.2...v6.3.0</a></li>
</ul>
</blockquote>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a href="https://github.com/ds300/patch-package/blob/master/CHANGELOG.md">patch-package's changelog</a>.</em></p>
<blockquote>
<h2>6.4.4</h2>
<ul>
<li>Refine --create-issue template</li>
</ul>
<h2>6.4.3</h2>
<ul>
<li>Ensure real path is used when copying package contents. Potentially adds pnpm support (contribution from <a href="https://github.com/milahu"><code>@​milahu</code></a> in <a href="https://github-redirect.dependabot.com/ds300/patch-package/issues/252">#252</a>)</li>
</ul>
<h2>6.4.2</h2>
<ul>
<li>Add package version to --create-issue template</li>
</ul>
<h2>6.4.1</h2>
<ul>
<li>Add backlink to patch-package repo to collect public usage of --create-issue</li>
</ul>
<h2>6.4.0</h2>
<ul>
<li>Add --create-issue option</li>
</ul>
<h2>6.3.1</h2>
<ul>
<li>Fix another createPatch bug involving .git folder hygiene (contribution from <a href="https://github.com/gomain"><code>@​gomain</code></a> in <a href="https://github-redirect.dependabot.com/ds300/patch-package/issues/258">#258</a>)</li>
</ul>
<h2>6.3.0</h2>
<ul>
<li>Add --error-on-fail cli option</li>
<li>Collate errors and warnings to avoid exiting early (with help from <a href="https://github.com/akwodkiewicz"><code>@​akwodkiewicz</code></a> in <a href="https://github-redirect.dependabot.com/ds300/patch-package/issues/217">#217</a>)</li>
<li>Fix .dev.patch suffix bug (with help from <a href="https://github.com/pdcastro"><code>@​pdcastro</code></a> in <a href="https://github-redirect.dependabot.com/ds300/patch-package/issues/224">#224</a>)</li>
<li>Support build metadata in package.json version strings (with help from <a href="https://github.com/snowystinger"><code>@​snowystinger</code></a> in <a href="https://github-redirect.dependabot.com/ds300/patch-package/issues/213">#213</a>)</li>
<li>Change 'no patch files found' message from red to blue (contribution from <a href="https://github.com/dmhalejr"><code>@​dmhalejr</code></a> in <a href="https://github-redirect.dependabot.com/ds300/patch-package/issues/211">#211</a>)</li>
<li>Fix environment variable propogation for spawned tasks (contribution from <a href="https://github.com/chpio"><code>@​chpio</code></a> in <a href="https://github-redirect.dependabot.com/ds300/patch-package/issues/223">#223</a>)</li>
<li>Add --patch-dir option to readme (contribution from <a href="https://github.com/mikehardy"><code>@​mikehardy</code></a> in <a href="https://github-redirect.dependabot.com/ds300/patch-package/issues/225">#225</a>)</li>
<li>Fix createPatch bug involving .git folder hygiene (contribution from <a href="https://github.com/haroenv"><code>@​haroenv</code></a> in <a href="https://github-redirect.dependabot.com/ds300/patch-package/issues/231">#231</a>)</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="https://github.com/ds300/patch-package/commit/9d1e46d72ab12a3e16944e40ff6eee055b695bf7"><code>9d1e46d</code></a> v6.4.4</li>
<li><a href="https://github.com/ds300/patch-package/commit/ca4ed73b67dedd72868d9abef3a8a5f098b15938"><code>ca4ed73</code></a> refine --create-issue template</li>
<li><a href="https://github.com/ds300/patch-package/commit/c6238f685326f48cfc60be127d5b8286ac5cb3c8"><code>c6238f6</code></a> Merge pull request <a href="https://github-redirect.dependabot.com/ds300/patch-package/issues/256">#256</a> from gomain/fix-yarn-workspace-test</li>
<li><a href="https://github.com/ds300/patch-package/commit/e9b95a359459244a97de75a97d53a1ca63324d97"><code>e9b95a3</code></a> v6.4.3</li>
<li><a href="https://github.com/ds300/patch-package/commit/7516ca6b262df9711fcdc56573242a0b84642f5d"><code>7516ca6</code></a> fix version numbers in changelog</li>
<li><a href="https://github.com/ds300/patch-package/commit/2da490a24e7bc1915722649fa716b3ad9f728088"><code>2da490a</code></a> Update changelog</li>
<li><a href="https://github.com/ds300/patch-package/commit/3c0883a440749315ae7e757a8a36d829bc9a9c52"><code>3c0883a</code></a> Merge pull request <a href="https://github-redirect.dependabot.com/ds300/patch-package/issues/252">#252</a> from milahu/patch-1</li>
<li><a href="https://github.com/ds300/patch-package/commit/bb9009d3c486c442cc58aae80b01a201fc0d02cb"><code>bb9009d</code></a> v6.4.2</li>
<li><a href="https://github.com/ds300/patch-package/commit/275c52f50de332dad18303cd4d83c54997e3b490"><code>275c52f</code></a> update changelog</li>
<li><a href="https://github.com/ds300/patch-package/commit/e7a04a5b1655b3e39809d9e19ac419ff7548af4b"><code>e7a04a5</code></a> add package version to create-issue template</li>
<li>Additional commits viewable in <a href="https://github.com/ds300/patch-package/compare/v6.2.2...v6.4.4">compare view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=patch-package&package-manager=npm_and_yarn&previous-version=6.2.2&new-version=6.4.4)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)


</details>


Patch:
diff --git a/package.json b/package.json
index 42c0ac46..e8764855 100644
--- a/package.json
+++ b/package.json
@@ -129,7 +129,7 @@
     "lint-staged": "^10.5.4",
     "nock": "~12.0.2",
     "node-html-parser": "^2.0.1",
-    "patch-package": "^6.2.2",
+    "patch-package": "^6.4.4",
     "pkg": "^4.4.9",
     "prettier": "^2.2.1",
     "recast": "^0.20.4",
diff --git a/src/documentInventory.ts b/src/documentInventory.ts
index 31eae63a..c9c35b7a 100644
--- a/src/documentInventory.ts
+++ b/src/documentInventory.ts
@@ -109,12 +109,21 @@ export class DocumentInventory {
         if ($ref === null) return null;
 
         const scopedPath = [...safePointerToPath($ref), ...newPath];
-        let resolvedDoc;
+        let resolvedDoc = this.document;
 
         if (isLocalRef($ref)) {
           resolvedDoc = source === this.document.source ? this.document : this.referencedDocuments[source];
         } else {
-          const extractedSource = extractSourceFromRef($ref)!;
+          const extractedSource = extractSourceFromRef($ref);
+
+          if (extractedSource === null) {
+            return {
+              document: resolvedDoc,
+              path: getClosestJsonPath(resolvedDoc.data, path),
+              missingPropertyPath: path,
+            };
+          }
+
           source = isAbsoluteRef(extractedSource) ? extractedSource : resolve(source, '..', extractedSource);
 
           resolvedDoc = source === this.document.source ? this.document : this.referencedDocuments[source];
diff --git a/yarn.lock b/yarn.lock
index 4ec00d2a..9e4d8dbd 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -4347,6 +4347,11 @@ is-descriptor@^1.0.0, is-descriptor@^1.0.2:
     is-data-descriptor "^1.0.0"
     kind-of "^6.0.2"
 
+is-docker@^2.0.0:
+  version "2.1.1"
+  resolved "https://registry.yarnpkg.com/is-docker/-/is-docker-2.1.1.tgz#4125a88e44e450d384e09047ede71adc2d144156"
+  integrity sha512-ZOoqiXfEwtGknTiuDEy8pN2CfE3TxMHprvNer1mXiqwkOT77Rw3YVrUQ52EqAOU3QAWDQ+bQdx7HJzrv7LS2Hw==
+
 is-dotdir@^0.1.0:
   version "0.1.0"
   resolved "https://registry.yarnpkg.com/is-dotdir/-/is-dotdir-0.1.0.tgz#da1e5464f59fc3a83c1d822b5ace091b45fe6b31"
@@ -6050,6 +6055,14 @@ onetime@^5.1.0:
   dependencies:
     mimic-fn "^2.1.0"
 
+open@^7.4.2:
+  version "7.4.2"
+  resolved "https://registry.yarnpkg.com/open/-/open-7.4.2.tgz#b8147e26dcf3e426316c730089fd71edd29c2321"
+  integrity sha512-MVHddDVweXZF3awtlAS+6pgKLlm/JgxZ90+/NBurBoQctVOOB/zDdVjcyPzQ+0laDGbsWgrRkflI65sQeOgT9Q==
+  dependencies:
+    is-docker "^2.0.0"
+    is-wsl "^2.1.1"
+
 optionator@^0.8.1, optionator@^0.8.3:
   version "0.8.3"
   resolved "https://registry.yarnpkg.com/optionator/-/optionator-0.8.3.tgz#84fa1d036fe9d3c7e21d99884b601167ec8fb495"
@@ -6236,10 +6249,10 @@ pascalcase@^0.1.1:
   resolved "https://registry.yarnpkg.com/pascalcase/-/pascalcase-0.1.1.tgz#b363e55e8006ca6fe21784d2db22bd15d7917f14"
   integrity sha1-s2PlXoAGym/iF4TS2yK9FdeRfxQ=
 
-patch-package@^6.2.2:
-  version "6.2.2"
-  resolved "https://registry.yarnpkg.com/patch-package/-/patch-package-6.2.2.tgz#71d170d650c65c26556f0d0fbbb48d92b6cc5f39"
-  integrity sha512-YqScVYkVcClUY0v8fF0kWOjDYopzIM8e3bj/RU1DPeEF14+dCGm6UeOYm4jvCyxqIEQ5/eJzmbWfDWnUleFNMg==
+patch-package@^6.4.4:
+  version "6.4.4"
+  resolved "https://registry.yarnpkg.com/patch-package/-/patch-package-6.4.4.tgz#f29bb9316f46858c8d84d206e5477720fc991ff0"
+  integrity sha512-U8F7DIcQsdnLNvFa/WbQ4EmFeiR/rCs2XLnIspIYa+amf+6LNZULsi8JcpW5jHVhg4JlOqGlFLYoqbNWSivDrw==
   dependencies:
     "@yarnpkg/lockfile" "^1.1.0"
     chalk "^2.4.2"
@@ -6249,6 +6262,7 @@ patch-package@^6.2.2:
     is-ci "^2.0.0"
     klaw-sync "^6.0.0"
     minimist "^1.2.0"
+    open "^7.4.2"
     rimraf "^2.6.3"
     semver "^5.6.0"
     slash "^2.0.0"


Test patch:
diff --git a/src/__tests__/__fixtures__/document-with-external-refs.json b/src/__tests__/__fixtures__/document-with-external-refs.json
new file mode 100644
index 00000000..c91588f1
--- /dev/null
+++ b/src/__tests__/__fixtures__/document-with-external-refs.json
@@ -0,0 +1,8 @@
+{
+  "todo": {
+    "$ref": "./models/todo-full.v1.json"
+  },
+  "empty": {
+    "$ref": ""
+  }
+}
diff --git a/src/__tests__/__fixtures__/document-with-external-refs.oas2.json b/src/__tests__/__fixtures__/document-with-external-refs.oas2.json
deleted file mode 100644
index a7ccd729..00000000
--- a/src/__tests__/__fixtures__/document-with-external-refs.oas2.json
+++ /dev/null
@@ -1,37 +0,0 @@
-{
-  "swagger": "2.0",
-  "info": {
-    "title": "To-dos",
-    "version": "1.0",
-    "description": "This OpenAPI v2 (Swagger) file represents a real API that lives at http://todos.stoplight.io.\n\nIt exposes functionality to manage to-do lists."
-  },
-  "host": "todos.stoplight.io",
-  "schemes": ["http"],
-  "paths": {
-    "/todos/{todoId}": {
-      "get": {
-        "operationId": "GET_todo",
-        "summary": "Get Todo",
-        "tags": ["Todos"],
-        "responses": {
-          "200": {
-            "description": "",
-            "schema": {
-              "$ref": "./models/todo-full.v1.json"
-            },
-            "examples": {
-              "application/json": {
-                "id": 1,
-                "name": "get food",
-                "completed": false,
-                "completed_at": "1955-04-23T13:22:52.685Z",
-                "created_at": "1994-11-05T03:26:51.471Z",
-                "updated_at": "1989-07-29T11:30:06.701Z"
-              }
-            }
-          }
-        }
-      }
-    }
-  }
-}
diff --git a/src/__tests__/spectral.jest.test.ts b/src/__tests__/spectral.jest.test.ts
index ffb8e8d0..14764b8b 100644
--- a/src/__tests__/spectral.jest.test.ts
+++ b/src/__tests__/spectral.jest.test.ts
@@ -5,7 +5,6 @@ import * as nock from 'nock';
 import * as path from 'path';
 
 import { Document } from '../document';
-import { isOpenApiv2 } from '../formats';
 import { pattern } from '../functions/pattern';
 import * as Parsers from '../parsers';
 import { httpAndFileResolver } from '../resolvers/http-and-file';
@@ -96,95 +95,58 @@ describe('Spectral', () => {
     );
   });
 
-  // todo: depends on spectral:oas
   test('should report issues for correct files with correct ranges and paths', async () => {
-    const documentUri = normalize(path.join(__dirname, './__fixtures__/document-with-external-refs.oas2.json'));
+    const documentUri = normalize(path.join(__dirname, './__fixtures__/document-with-external-refs.json'));
     const spectral = new Spectral({ resolver: httpAndFileResolver });
-    await spectral.loadRuleset('spectral:oas');
-    spectral.registerFormat('oas2', isOpenApiv2);
+    spectral.setRules({
+      'requires-type': {
+        given: ['$..allOf', '$.empty'],
+        then: {
+          field: 'type',
+          function: 'truthy',
+        },
+      },
+    });
     const document = new Document(fs.readFileSync(documentUri, 'utf8'), Parsers.Json, documentUri);
 
     const results = await spectral.run(document);
 
-    expect(results).toEqual(
-      expect.arrayContaining([
-        expect.objectContaining({
-          code: 'oas2-schema',
-          path: ['paths', '/todos/{todoId}', 'get', 'responses', '200', 'description'],
-          range: {
-            end: {
-              character: 29,
-              line: 17,
-            },
-            start: {
-              character: 27,
-              line: 17,
-            },
-          },
-          source: documentUri,
-        }),
-        expect.objectContaining({
-          code: 'oas2-schema',
-          path: [],
-          range: {
-            end: {
-              character: 1,
-              line: 37,
-            },
-            start: {
-              character: 0,
-              line: 0,
-            },
+    expect(results).toEqual([
+      {
+        code: 'requires-type',
+        message: '`empty.type` property is not truthy',
+        path: ['empty'],
+        range: {
+          end: {
+            character: 3,
+            line: 6,
           },
-          source: expect.stringContaining('__fixtures__/models/todo-full.v1.json'),
-        }),
-        expect.objectContaining({
-          code: 'path-params',
-          path: ['paths', '/todos/{todoId}', 'get'],
-          range: {
-            end: {
-              character: 7,
-              line: 33,
-            },
-            start: {
-              character: 13,
-              line: 11,
-            },
+          start: {
+            character: 11,
+            line: 4,
           },
-          source: documentUri,
-        }),
-        expect.objectContaining({
-          code: 'info-contact',
-          path: ['info'],
-          range: {
-            end: {
-              character: 3,
-              line: 6,
-            },
-            start: {
-              character: 10,
-              line: 2,
-            },
+        },
+        severity: DiagnosticSeverity.Warning,
+        source: documentUri,
+      },
+      {
+        code: 'requires-type',
+        message: '`allOf.type` property is not truthy',
+        path: ['allOf'],
+        range: {
+          end: {
+            character: 3,
+            line: 33,
           },
-          source: documentUri,
-        }),
-        expect.objectContaining({
-          code: 'operation-description',
-          path: ['paths', '/todos/{todoId}', 'get'],
-          range: {
-            end: {
-              character: 7,
-              line: 33,
-            },
-            start: {
-              character: 13,
-              line: 11,
-            },
+          start: {
+            character: 11,
+            line: 3,
           },
-          source: documentUri,
-        }),
-      ]),
-    );
+        },
+        severity: DiagnosticSeverity.Warning,
+        source: expect.stringContaining('__fixtures__/models/todo-full.v1.json'),
+      },
+    ]);
   });
 
   test('properly decorates results with metadata pertaining to the document being linted', async () => {