forked from APIDevTools/json-schema-ref-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmissing-pointers.spec.js
85 lines (80 loc) · 3.08 KB
/
missing-pointers.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
"use strict";
const chai = require("chai");
const chaiSubset = require("chai-subset");
chai.use(chaiSubset);
const { expect } = chai;
const $RefParser = require("../../../lib");
const { JSONParserErrorGroup, MissingPointerError } = require("../../../lib/util/errors");
const helper = require("../../utils/helper");
const path = require("../../utils/path");
describe("Schema with missing pointers", () => {
it("should throw an error for missing pointer", async () => {
try {
await $RefParser.dereference({ foo: { $ref: "#/baz" }});
helper.shouldNotGetCalled();
}
catch (err) {
expect(err).to.be.an.instanceOf(MissingPointerError);
expect(err.message).to.contain("Token \"baz\" does not exist.");
}
});
it("should throw an error for missing pointer in external file", async () => {
try {
await $RefParser.dereference({ foo: { $ref: path.abs("specs/missing-pointers/external-from-internal.yaml") }});
helper.shouldNotGetCalled();
}
catch (err) {
expect(err).to.be.an.instanceOf(MissingPointerError);
expect(err.message).to.contain("Token \"external\" does not exist.");
}
});
context("when continueOnError is true", () => {
it("should throw a grouped error for missing pointer", async () => {
const parser = new $RefParser();
try {
await parser.dereference({ foo: { $ref: "#/baz" }}, { continueOnError: true });
helper.shouldNotGetCalled();
}
catch (err) {
expect(err).to.be.instanceof(JSONParserErrorGroup);
expect(err.files).to.equal(parser);
expect(err.files.$refs._root$Ref.value).to.deep.equal({ foo: null });
expect(err.message).to.have.string("1 error occurred while reading '");
expect(err.errors).to.containSubset([
{
name: MissingPointerError.name,
message: "Token \"baz\" does not exist.",
path: ["foo"],
// source: message => message.endsWith("/test/") || message.startsWith("http://localhost"),
}
]);
}
});
it("should throw an error for missing pointer in external file", async () => {
const parser = new $RefParser();
try {
await parser.dereference({ foo: { $ref: path.abs("specs/missing-pointers/external-from-internal.yaml") }}, { continueOnError: true });
helper.shouldNotGetCalled();
}
catch (err) {
expect(err).to.be.instanceof(JSONParserErrorGroup);
expect(err.files).to.equal(parser);
expect(err.files.$refs._root$Ref.value).to.deep.equal({
foo: {
internal1: null,
internal2: null,
}
});
expect(err.message).to.have.string("1 error occurred while reading '");
expect(err.errors).to.containSubset([
{
name: MissingPointerError.name,
message: "Token \"external\" does not exist.",
path: ["internal2"],
source: message => message.endsWith("missing-pointers/external-from-internal.yaml") || message.startsWith("http://localhost"),
}
]);
}
});
});
});