@apidevtools/json-schema-ref-parser 9.0.2 → 9.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/lib/bundle.js +1 -1
- package/lib/dereference.js +77 -34
- package/lib/index.d.ts +108 -107
- package/lib/index.js +1 -0
- package/lib/parsers/json.js +1 -1
- package/lib/parsers/yaml.js +1 -1
- package/lib/pointer.js +11 -3
- package/lib/ref.js +2 -2
- package/lib/refs.js +2 -2
- package/lib/resolve-external.js +1 -1
- package/package.json +13 -13
package/README.md
CHANGED
|
@@ -129,7 +129,7 @@ Full API documentation is available [right here](https://apitools.dev/json-schem
|
|
|
129
129
|
|
|
130
130
|
Contributing
|
|
131
131
|
--------------------------
|
|
132
|
-
I welcome any contributions, enhancements, and bug-fixes. [
|
|
132
|
+
I welcome any contributions, enhancements, and bug-fixes. [Open an issue](https://github.com/APIDevTools/json-schema-ref-parser/issues) on GitHub and [submit a pull request](https://github.com/APIDevTools/json-schema-ref-parser/pulls).
|
|
133
133
|
|
|
134
134
|
#### Building/Testing
|
|
135
135
|
To build/test the project locally on your computer:
|
package/lib/bundle.js
CHANGED
|
@@ -39,7 +39,7 @@ function bundle (parser, options) {
|
|
|
39
39
|
function crawl (parent, key, path, pathFromRoot, indirections, inventory, $refs, options) {
|
|
40
40
|
let obj = key === null ? parent : parent[key];
|
|
41
41
|
|
|
42
|
-
if (obj && typeof obj === "object") {
|
|
42
|
+
if (obj && typeof obj === "object" && !ArrayBuffer.isView(obj)) {
|
|
43
43
|
if ($Ref.isAllowed$Ref(obj)) {
|
|
44
44
|
inventory$Ref(parent, key, path, pathFromRoot, indirections, inventory, $refs, options);
|
|
45
45
|
}
|
package/lib/dereference.js
CHANGED
|
@@ -16,7 +16,7 @@ module.exports = dereference;
|
|
|
16
16
|
*/
|
|
17
17
|
function dereference (parser, options) {
|
|
18
18
|
// console.log('Dereferencing $ref pointers in %s', parser.$refs._root$Ref.path);
|
|
19
|
-
let dereferenced = crawl(parser.schema, parser.$refs._root$Ref.path, "#", [], parser.$refs, options);
|
|
19
|
+
let dereferenced = crawl(parser.schema, parser.$refs._root$Ref.path, "#", [], [], {}, parser.$refs, options);
|
|
20
20
|
parser.$refs.circular = dereferenced.circular;
|
|
21
21
|
parser.schema = dereferenced.value;
|
|
22
22
|
}
|
|
@@ -28,54 +28,65 @@ function dereference (parser, options) {
|
|
|
28
28
|
* @param {string} path - The full path of `obj`, possibly with a JSON Pointer in the hash
|
|
29
29
|
* @param {string} pathFromRoot - The path of `obj` from the schema root
|
|
30
30
|
* @param {object[]} parents - An array of the parent objects that have already been dereferenced
|
|
31
|
+
* @param {object[]} processedObjects - An array of all the objects that have already been processed
|
|
32
|
+
* @param {object} dereferencedCache - An map of all the dereferenced objects
|
|
31
33
|
* @param {$Refs} $refs
|
|
32
34
|
* @param {$RefParserOptions} options
|
|
33
35
|
* @returns {{value: object, circular: boolean}}
|
|
34
36
|
*/
|
|
35
|
-
function crawl (obj, path, pathFromRoot, parents, $refs, options) {
|
|
37
|
+
function crawl (obj, path, pathFromRoot, parents, processedObjects, dereferencedCache, $refs, options) {
|
|
36
38
|
let dereferenced;
|
|
37
39
|
let result = {
|
|
38
40
|
value: obj,
|
|
39
41
|
circular: false
|
|
40
42
|
};
|
|
41
43
|
|
|
42
|
-
if (
|
|
43
|
-
|
|
44
|
+
if (options.dereference.circular === "ignore" || processedObjects.indexOf(obj) === -1) {
|
|
45
|
+
if (obj && typeof obj === "object" && !ArrayBuffer.isView(obj)) {
|
|
46
|
+
parents.push(obj);
|
|
47
|
+
processedObjects.push(obj);
|
|
44
48
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
circular = dereferenced.circular;
|
|
60
|
-
obj[key] = dereferenced.value;
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
if (parents.indexOf(value) === -1) {
|
|
64
|
-
dereferenced = crawl(value, keyPath, keyPathFromRoot, parents, $refs, options);
|
|
49
|
+
if ($Ref.isAllowed$Ref(obj, options)) {
|
|
50
|
+
dereferenced = dereference$Ref(obj, path, pathFromRoot, parents, processedObjects, dereferencedCache, $refs, options);
|
|
51
|
+
result.circular = dereferenced.circular;
|
|
52
|
+
result.value = dereferenced.value;
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
for (let key of Object.keys(obj)) {
|
|
56
|
+
let keyPath = Pointer.join(path, key);
|
|
57
|
+
let keyPathFromRoot = Pointer.join(pathFromRoot, key);
|
|
58
|
+
let value = obj[key];
|
|
59
|
+
let circular = false;
|
|
60
|
+
|
|
61
|
+
if ($Ref.isAllowed$Ref(value, options)) {
|
|
62
|
+
dereferenced = dereference$Ref(value, keyPath, keyPathFromRoot, parents, processedObjects, dereferencedCache, $refs, options);
|
|
65
63
|
circular = dereferenced.circular;
|
|
66
|
-
|
|
64
|
+
// Avoid pointless mutations; breaks frozen objects to no profit
|
|
65
|
+
if (obj[key] !== dereferenced.value) {
|
|
66
|
+
obj[key] = dereferenced.value;
|
|
67
|
+
}
|
|
67
68
|
}
|
|
68
69
|
else {
|
|
69
|
-
|
|
70
|
+
if (parents.indexOf(value) === -1) {
|
|
71
|
+
dereferenced = crawl(value, keyPath, keyPathFromRoot, parents, processedObjects, dereferencedCache, $refs, options);
|
|
72
|
+
circular = dereferenced.circular;
|
|
73
|
+
// Avoid pointless mutations; breaks frozen objects to no profit
|
|
74
|
+
if (obj[key] !== dereferenced.value) {
|
|
75
|
+
obj[key] = dereferenced.value;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
circular = foundCircularReference(keyPath, $refs, options);
|
|
80
|
+
}
|
|
70
81
|
}
|
|
71
|
-
}
|
|
72
82
|
|
|
73
|
-
|
|
74
|
-
|
|
83
|
+
// Set the "isCircular" flag if this or any other property is circular
|
|
84
|
+
result.circular = result.circular || circular;
|
|
85
|
+
}
|
|
75
86
|
}
|
|
76
|
-
}
|
|
77
87
|
|
|
78
|
-
|
|
88
|
+
parents.pop();
|
|
89
|
+
}
|
|
79
90
|
}
|
|
80
91
|
|
|
81
92
|
return result;
|
|
@@ -88,14 +99,38 @@ function crawl (obj, path, pathFromRoot, parents, $refs, options) {
|
|
|
88
99
|
* @param {string} path - The full path of `$ref`, possibly with a JSON Pointer in the hash
|
|
89
100
|
* @param {string} pathFromRoot - The path of `$ref` from the schema root
|
|
90
101
|
* @param {object[]} parents - An array of the parent objects that have already been dereferenced
|
|
102
|
+
* @param {object[]} processedObjects - An array of all the objects that have already been dereferenced
|
|
103
|
+
* @param {object} dereferencedCache - An map of all the dereferenced objects
|
|
91
104
|
* @param {$Refs} $refs
|
|
92
105
|
* @param {$RefParserOptions} options
|
|
93
106
|
* @returns {{value: object, circular: boolean}}
|
|
94
107
|
*/
|
|
95
|
-
function dereference$Ref ($ref, path, pathFromRoot, parents, $refs, options) {
|
|
108
|
+
function dereference$Ref ($ref, path, pathFromRoot, parents, processedObjects, dereferencedCache, $refs, options) {
|
|
96
109
|
// console.log('Dereferencing $ref pointer "%s" at %s', $ref.$ref, path);
|
|
97
110
|
|
|
98
111
|
let $refPath = url.resolve(path, $ref.$ref);
|
|
112
|
+
|
|
113
|
+
if (dereferencedCache[$refPath]) {
|
|
114
|
+
const cache = dereferencedCache[$refPath];
|
|
115
|
+
|
|
116
|
+
const refKeys = Object.keys($ref);
|
|
117
|
+
if (refKeys.length > 1) {
|
|
118
|
+
const extraKeys = {};
|
|
119
|
+
for (let key of refKeys) {
|
|
120
|
+
if (key !== "$ref" && !(key in cache.value)) {
|
|
121
|
+
extraKeys[key] = $ref[key];
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return {
|
|
125
|
+
circular: cache.circular,
|
|
126
|
+
value: Object.assign({}, cache.value, extraKeys),
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return cache;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
|
|
99
134
|
let pointer = $refs._resolve($refPath, path, options);
|
|
100
135
|
|
|
101
136
|
if (pointer === null) {
|
|
@@ -116,7 +151,7 @@ function dereference$Ref ($ref, path, pathFromRoot, parents, $refs, options) {
|
|
|
116
151
|
// Crawl the dereferenced value (unless it's circular)
|
|
117
152
|
if (!circular) {
|
|
118
153
|
// Determine if the dereferenced value is circular
|
|
119
|
-
let dereferenced = crawl(dereferencedValue, pointer.path, pathFromRoot, parents, $refs, options);
|
|
154
|
+
let dereferenced = crawl(dereferencedValue, pointer.path, pathFromRoot, parents, processedObjects, dereferencedCache, $refs, options);
|
|
120
155
|
circular = dereferenced.circular;
|
|
121
156
|
dereferencedValue = dereferenced.value;
|
|
122
157
|
}
|
|
@@ -132,10 +167,18 @@ function dereference$Ref ($ref, path, pathFromRoot, parents, $refs, options) {
|
|
|
132
167
|
dereferencedValue.$ref = pathFromRoot;
|
|
133
168
|
}
|
|
134
169
|
|
|
135
|
-
|
|
170
|
+
|
|
171
|
+
const dereferencedObject = {
|
|
136
172
|
circular,
|
|
137
173
|
value: dereferencedValue
|
|
138
174
|
};
|
|
175
|
+
|
|
176
|
+
// only cache if no extra properties than $ref
|
|
177
|
+
if (Object.keys($ref).length === 1) {
|
|
178
|
+
dereferencedCache[$refPath] = dereferencedObject;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return dereferencedObject;
|
|
139
182
|
}
|
|
140
183
|
|
|
141
184
|
/**
|
package/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { JSONSchema4, JSONSchema4Type, JSONSchema6, JSONSchema6Type } from
|
|
1
|
+
import { JSONSchema4, JSONSchema4Type, JSONSchema6, JSONSchema6Type } from "json-schema";
|
|
2
2
|
|
|
3
|
-
export = $RefParser
|
|
3
|
+
export = $RefParser;
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* This is the default export of JSON Schema $Ref Parser. You can creates instances of this class using new $RefParser(), or you can just call its static methods.
|
|
@@ -14,7 +14,7 @@ declare class $RefParser {
|
|
|
14
14
|
*
|
|
15
15
|
* See https://apitools.dev/json-schema-ref-parser/docs/ref-parser.html#schema
|
|
16
16
|
*/
|
|
17
|
-
schema: $RefParser.JSONSchema
|
|
17
|
+
public schema: $RefParser.JSONSchema;
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* The $refs property is a `$Refs` object, which lets you access all of the externally-referenced files in the schema, as well as easily get and set specific values in the schema using JSON pointers.
|
|
@@ -23,7 +23,7 @@ declare class $RefParser {
|
|
|
23
23
|
*
|
|
24
24
|
* See https://apitools.dev/json-schema-ref-parser/docs/ref-parser.html#refs
|
|
25
25
|
*/
|
|
26
|
-
$refs: $RefParser.$Refs
|
|
26
|
+
public $refs: $RefParser.$Refs;
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
29
|
* Dereferences all `$ref` pointers in the JSON Schema, replacing each reference with its resolved value. This results in a schema object that does not contain any `$ref` pointers. Instead, it's a normal JavaScript object tree that can easily be crawled and used just like any other JavaScript object. This is great for programmatic usage, especially when using tools that don't understand JSON references.
|
|
@@ -36,12 +36,12 @@ declare class $RefParser {
|
|
|
36
36
|
* @param options (optional)
|
|
37
37
|
* @param callback (optional) A callback that will receive the dereferenced schema object
|
|
38
38
|
*/
|
|
39
|
-
dereference(schema: string | $RefParser.JSONSchema, callback: $RefParser.SchemaCallback): void;
|
|
40
|
-
dereference(schema: string | $RefParser.JSONSchema, options: $RefParser.Options, callback: $RefParser.SchemaCallback): void;
|
|
41
|
-
dereference(baseUrl: string, schema: string | $RefParser.JSONSchema, options: $RefParser.Options, callback: $RefParser.SchemaCallback): void;
|
|
42
|
-
dereference(schema: string | $RefParser.JSONSchema): Promise<$RefParser.JSONSchema>;
|
|
43
|
-
dereference(schema: string | $RefParser.JSONSchema, options: $RefParser.Options): Promise<$RefParser.JSONSchema>;
|
|
44
|
-
dereference(baseUrl: string, schema: string | $RefParser.JSONSchema, options: $RefParser.Options): Promise<$RefParser.JSONSchema>;
|
|
39
|
+
public dereference(schema: string | $RefParser.JSONSchema, callback: $RefParser.SchemaCallback): void;
|
|
40
|
+
public dereference(schema: string | $RefParser.JSONSchema, options: $RefParser.Options, callback: $RefParser.SchemaCallback): void;
|
|
41
|
+
public dereference(baseUrl: string, schema: string | $RefParser.JSONSchema, options: $RefParser.Options, callback: $RefParser.SchemaCallback): void;
|
|
42
|
+
public dereference(schema: string | $RefParser.JSONSchema): Promise<$RefParser.JSONSchema>;
|
|
43
|
+
public dereference(schema: string | $RefParser.JSONSchema, options: $RefParser.Options): Promise<$RefParser.JSONSchema>;
|
|
44
|
+
public dereference(baseUrl: string, schema: string | $RefParser.JSONSchema, options: $RefParser.Options): Promise<$RefParser.JSONSchema>;
|
|
45
45
|
|
|
46
46
|
/**
|
|
47
47
|
* Dereferences all `$ref` pointers in the JSON Schema, replacing each reference with its resolved value. This results in a schema object that does not contain any `$ref` pointers. Instead, it's a normal JavaScript object tree that can easily be crawled and used just like any other JavaScript object. This is great for programmatic usage, especially when using tools that don't understand JSON references.
|
|
@@ -54,12 +54,12 @@ declare class $RefParser {
|
|
|
54
54
|
* @param options (optional)
|
|
55
55
|
* @param callback (optional) A callback that will receive the dereferenced schema object
|
|
56
56
|
*/
|
|
57
|
-
static dereference(schema: string | $RefParser.JSONSchema, callback: $RefParser.SchemaCallback): void;
|
|
58
|
-
static dereference(schema: string | $RefParser.JSONSchema, options: $RefParser.Options, callback: $RefParser.SchemaCallback): void;
|
|
59
|
-
static dereference(baseUrl: string, schema: string | $RefParser.JSONSchema, options: $RefParser.Options, callback: $RefParser.SchemaCallback): void;
|
|
60
|
-
static dereference(schema: string | $RefParser.JSONSchema): Promise<$RefParser.JSONSchema>;
|
|
61
|
-
static dereference(schema: string | $RefParser.JSONSchema, options: $RefParser.Options): Promise<$RefParser.JSONSchema>;
|
|
62
|
-
static dereference(baseUrl: string, schema: string | $RefParser.JSONSchema, options: $RefParser.Options): Promise<$RefParser.JSONSchema>;
|
|
57
|
+
public static dereference(schema: string | $RefParser.JSONSchema, callback: $RefParser.SchemaCallback): void;
|
|
58
|
+
public static dereference(schema: string | $RefParser.JSONSchema, options: $RefParser.Options, callback: $RefParser.SchemaCallback): void;
|
|
59
|
+
public static dereference(baseUrl: string, schema: string | $RefParser.JSONSchema, options: $RefParser.Options, callback: $RefParser.SchemaCallback): void;
|
|
60
|
+
public static dereference(schema: string | $RefParser.JSONSchema): Promise<$RefParser.JSONSchema>;
|
|
61
|
+
public static dereference(schema: string | $RefParser.JSONSchema, options: $RefParser.Options): Promise<$RefParser.JSONSchema>;
|
|
62
|
+
public static dereference(baseUrl: string, schema: string | $RefParser.JSONSchema, options: $RefParser.Options): Promise<$RefParser.JSONSchema>;
|
|
63
63
|
|
|
64
64
|
/**
|
|
65
65
|
* Bundles all referenced files/URLs into a single schema that only has internal `$ref` pointers. This lets you split-up your schema however you want while you're building it, but easily combine all those files together when it's time to package or distribute the schema to other people. The resulting schema size will be small, since it will still contain internal JSON references rather than being fully-dereferenced.
|
|
@@ -72,12 +72,12 @@ declare class $RefParser {
|
|
|
72
72
|
* @param options (optional)
|
|
73
73
|
* @param callback (optional) A callback that will receive the bundled schema object
|
|
74
74
|
*/
|
|
75
|
-
bundle(schema: string | $RefParser.JSONSchema, callback: $RefParser.SchemaCallback): void;
|
|
76
|
-
bundle(schema: string | $RefParser.JSONSchema, options: $RefParser.Options, callback: $RefParser.SchemaCallback): void;
|
|
77
|
-
bundle(baseUrl: string, schema: string | $RefParser.JSONSchema, options: $RefParser.Options, callback: $RefParser.SchemaCallback): void;
|
|
78
|
-
bundle(schema: string | $RefParser.JSONSchema): Promise<$RefParser.JSONSchema>;
|
|
79
|
-
bundle(schema: string | $RefParser.JSONSchema, options: $RefParser.Options): Promise<$RefParser.JSONSchema>;
|
|
80
|
-
bundle(baseUrl: string, schema: string | $RefParser.JSONSchema, options: $RefParser.Options): Promise<$RefParser.JSONSchema>;
|
|
75
|
+
public bundle(schema: string | $RefParser.JSONSchema, callback: $RefParser.SchemaCallback): void;
|
|
76
|
+
public bundle(schema: string | $RefParser.JSONSchema, options: $RefParser.Options, callback: $RefParser.SchemaCallback): void;
|
|
77
|
+
public bundle(baseUrl: string, schema: string | $RefParser.JSONSchema, options: $RefParser.Options, callback: $RefParser.SchemaCallback): void;
|
|
78
|
+
public bundle(schema: string | $RefParser.JSONSchema): Promise<$RefParser.JSONSchema>;
|
|
79
|
+
public bundle(schema: string | $RefParser.JSONSchema, options: $RefParser.Options): Promise<$RefParser.JSONSchema>;
|
|
80
|
+
public bundle(baseUrl: string, schema: string | $RefParser.JSONSchema, options: $RefParser.Options): Promise<$RefParser.JSONSchema>;
|
|
81
81
|
|
|
82
82
|
/**
|
|
83
83
|
* Bundles all referenced files/URLs into a single schema that only has internal `$ref` pointers. This lets you split-up your schema however you want while you're building it, but easily combine all those files together when it's time to package or distribute the schema to other people. The resulting schema size will be small, since it will still contain internal JSON references rather than being fully-dereferenced.
|
|
@@ -90,12 +90,12 @@ declare class $RefParser {
|
|
|
90
90
|
* @param options (optional)
|
|
91
91
|
* @param callback (optional) A callback that will receive the bundled schema object
|
|
92
92
|
*/
|
|
93
|
-
static bundle(schema: string | $RefParser.JSONSchema, callback: $RefParser.SchemaCallback): void;
|
|
94
|
-
static bundle(schema: string | $RefParser.JSONSchema, options: $RefParser.Options, callback: $RefParser.SchemaCallback): void;
|
|
95
|
-
static bundle(baseUrl: string, schema: string | $RefParser.JSONSchema, options: $RefParser.Options, callback: $RefParser.SchemaCallback): void;
|
|
96
|
-
static bundle(schema: string | $RefParser.JSONSchema): Promise<$RefParser.JSONSchema>;
|
|
97
|
-
static bundle(schema: string | $RefParser.JSONSchema, options: $RefParser.Options): Promise<$RefParser.JSONSchema>;
|
|
98
|
-
static bundle(baseUrl: string, schema: string | $RefParser.JSONSchema, options: $RefParser.Options): Promise<$RefParser.JSONSchema>;
|
|
93
|
+
public static bundle(schema: string | $RefParser.JSONSchema, callback: $RefParser.SchemaCallback): void;
|
|
94
|
+
public static bundle(schema: string | $RefParser.JSONSchema, options: $RefParser.Options, callback: $RefParser.SchemaCallback): void;
|
|
95
|
+
public static bundle(baseUrl: string, schema: string | $RefParser.JSONSchema, options: $RefParser.Options, callback: $RefParser.SchemaCallback): void;
|
|
96
|
+
public static bundle(schema: string | $RefParser.JSONSchema): Promise<$RefParser.JSONSchema>;
|
|
97
|
+
public static bundle(schema: string | $RefParser.JSONSchema, options: $RefParser.Options): Promise<$RefParser.JSONSchema>;
|
|
98
|
+
public static bundle(baseUrl: string, schema: string | $RefParser.JSONSchema, options: $RefParser.Options): Promise<$RefParser.JSONSchema>;
|
|
99
99
|
|
|
100
100
|
/**
|
|
101
101
|
* *This method is used internally by other methods, such as `bundle` and `dereference`. You probably won't need to call this method yourself.*
|
|
@@ -108,12 +108,12 @@ declare class $RefParser {
|
|
|
108
108
|
* @param options (optional)
|
|
109
109
|
* @param callback (optional) A callback that will receive the parsed schema object, or an error
|
|
110
110
|
*/
|
|
111
|
-
parse(schema: string | $RefParser.JSONSchema, callback: $RefParser.SchemaCallback): void;
|
|
112
|
-
parse(schema: string | $RefParser.JSONSchema, options: $RefParser.Options, callback: $RefParser.SchemaCallback): void;
|
|
113
|
-
parse(baseUrl: string, schema: string | $RefParser.JSONSchema, options: $RefParser.Options, callback: $RefParser.SchemaCallback): void;
|
|
114
|
-
parse(schema: string | $RefParser.JSONSchema): Promise<$RefParser.JSONSchema>;
|
|
115
|
-
parse(schema: string | $RefParser.JSONSchema, options: $RefParser.Options): Promise<$RefParser.JSONSchema>;
|
|
116
|
-
parse(baseUrl: string, schema: string | $RefParser.JSONSchema, options: $RefParser.Options): Promise<$RefParser.JSONSchema>;
|
|
111
|
+
public parse(schema: string | $RefParser.JSONSchema, callback: $RefParser.SchemaCallback): void;
|
|
112
|
+
public parse(schema: string | $RefParser.JSONSchema, options: $RefParser.Options, callback: $RefParser.SchemaCallback): void;
|
|
113
|
+
public parse(baseUrl: string, schema: string | $RefParser.JSONSchema, options: $RefParser.Options, callback: $RefParser.SchemaCallback): void;
|
|
114
|
+
public parse(schema: string | $RefParser.JSONSchema): Promise<$RefParser.JSONSchema>;
|
|
115
|
+
public parse(schema: string | $RefParser.JSONSchema, options: $RefParser.Options): Promise<$RefParser.JSONSchema>;
|
|
116
|
+
public parse(baseUrl: string, schema: string | $RefParser.JSONSchema, options: $RefParser.Options): Promise<$RefParser.JSONSchema>;
|
|
117
117
|
|
|
118
118
|
/**
|
|
119
119
|
* *This method is used internally by other methods, such as `bundle` and `dereference`. You probably won't need to call this method yourself.*
|
|
@@ -126,12 +126,12 @@ declare class $RefParser {
|
|
|
126
126
|
* @param options (optional)
|
|
127
127
|
* @param callback (optional) A callback that will receive the parsed schema object, or an error
|
|
128
128
|
*/
|
|
129
|
-
static parse(schema: string | $RefParser.JSONSchema, callback: $RefParser.SchemaCallback): void;
|
|
130
|
-
static parse(schema: string | $RefParser.JSONSchema, options: $RefParser.Options, callback: $RefParser.SchemaCallback): void;
|
|
131
|
-
static parse(baseUrl: string, schema: string | $RefParser.JSONSchema, options: $RefParser.Options, callback: $RefParser.SchemaCallback): void;
|
|
132
|
-
static parse(schema: string | $RefParser.JSONSchema): Promise<$RefParser.JSONSchema>;
|
|
133
|
-
static parse(schema: string | $RefParser.JSONSchema, options: $RefParser.Options): Promise<$RefParser.JSONSchema>;
|
|
134
|
-
static parse(baseUrl: string, schema: string | $RefParser.JSONSchema, options: $RefParser.Options): Promise<$RefParser.JSONSchema>;
|
|
129
|
+
public static parse(schema: string | $RefParser.JSONSchema, callback: $RefParser.SchemaCallback): void;
|
|
130
|
+
public static parse(schema: string | $RefParser.JSONSchema, options: $RefParser.Options, callback: $RefParser.SchemaCallback): void;
|
|
131
|
+
public static parse(baseUrl: string, schema: string | $RefParser.JSONSchema, options: $RefParser.Options, callback: $RefParser.SchemaCallback): void;
|
|
132
|
+
public static parse(schema: string | $RefParser.JSONSchema): Promise<$RefParser.JSONSchema>;
|
|
133
|
+
public static parse(schema: string | $RefParser.JSONSchema, options: $RefParser.Options): Promise<$RefParser.JSONSchema>;
|
|
134
|
+
public static parse(baseUrl: string, schema: string | $RefParser.JSONSchema, options: $RefParser.Options): Promise<$RefParser.JSONSchema>;
|
|
135
135
|
|
|
136
136
|
/**
|
|
137
137
|
* *This method is used internally by other methods, such as `bundle` and `dereference`. You probably won't need to call this method yourself.*
|
|
@@ -144,12 +144,12 @@ declare class $RefParser {
|
|
|
144
144
|
* @param options (optional)
|
|
145
145
|
* @param callback (optional) A callback that will receive a `$Refs` object
|
|
146
146
|
*/
|
|
147
|
-
resolve(schema: string | $RefParser.JSONSchema, callback: $RefParser.$RefsCallback): void;
|
|
148
|
-
resolve(schema: string | $RefParser.JSONSchema, options: $RefParser.Options, callback: $RefParser.$RefsCallback): void;
|
|
149
|
-
resolve(baseUrl: string, schema: string | $RefParser.JSONSchema, options: $RefParser.Options, callback: $RefParser.$RefsCallback): void;
|
|
150
|
-
resolve(schema: string | $RefParser.JSONSchema): Promise<$RefParser.$Refs>;
|
|
151
|
-
resolve(schema: string | $RefParser.JSONSchema, options: $RefParser.Options): Promise<$RefParser.$Refs>;
|
|
152
|
-
resolve(baseUrl: string, schema: string | $RefParser.JSONSchema, options: $RefParser.Options): Promise<$RefParser.$Refs>;
|
|
147
|
+
public resolve(schema: string | $RefParser.JSONSchema, callback: $RefParser.$RefsCallback): void;
|
|
148
|
+
public resolve(schema: string | $RefParser.JSONSchema, options: $RefParser.Options, callback: $RefParser.$RefsCallback): void;
|
|
149
|
+
public resolve(baseUrl: string, schema: string | $RefParser.JSONSchema, options: $RefParser.Options, callback: $RefParser.$RefsCallback): void;
|
|
150
|
+
public resolve(schema: string | $RefParser.JSONSchema): Promise<$RefParser.$Refs>;
|
|
151
|
+
public resolve(schema: string | $RefParser.JSONSchema, options: $RefParser.Options): Promise<$RefParser.$Refs>;
|
|
152
|
+
public resolve(baseUrl: string, schema: string | $RefParser.JSONSchema, options: $RefParser.Options): Promise<$RefParser.$Refs>;
|
|
153
153
|
|
|
154
154
|
/**
|
|
155
155
|
* *This method is used internally by other methods, such as `bundle` and `dereference`. You probably won't need to call this method yourself.*
|
|
@@ -162,14 +162,15 @@ declare class $RefParser {
|
|
|
162
162
|
* @param options (optional)
|
|
163
163
|
* @param callback (optional) A callback that will receive a `$Refs` object
|
|
164
164
|
*/
|
|
165
|
-
static resolve(schema: string | $RefParser.JSONSchema, callback: $RefParser.$RefsCallback): void;
|
|
166
|
-
static resolve(schema: string | $RefParser.JSONSchema, options: $RefParser.Options, callback: $RefParser.$RefsCallback): void;
|
|
167
|
-
static resolve(baseUrl: string, schema: string | $RefParser.JSONSchema, options: $RefParser.Options, callback: $RefParser.$RefsCallback): void;
|
|
168
|
-
static resolve(schema: string | $RefParser.JSONSchema): Promise<$RefParser.$Refs>;
|
|
169
|
-
static resolve(schema: string | $RefParser.JSONSchema, options: $RefParser.Options): Promise<$RefParser.$Refs>;
|
|
170
|
-
static resolve(baseUrl: string, schema: string | $RefParser.JSONSchema, options: $RefParser.Options): Promise<$RefParser.$Refs>;
|
|
165
|
+
public static resolve(schema: string | $RefParser.JSONSchema, callback: $RefParser.$RefsCallback): void;
|
|
166
|
+
public static resolve(schema: string | $RefParser.JSONSchema, options: $RefParser.Options, callback: $RefParser.$RefsCallback): void;
|
|
167
|
+
public static resolve(baseUrl: string, schema: string | $RefParser.JSONSchema, options: $RefParser.Options, callback: $RefParser.$RefsCallback): void;
|
|
168
|
+
public static resolve(schema: string | $RefParser.JSONSchema): Promise<$RefParser.$Refs>;
|
|
169
|
+
public static resolve(schema: string | $RefParser.JSONSchema, options: $RefParser.Options): Promise<$RefParser.$Refs>;
|
|
170
|
+
public static resolve(baseUrl: string, schema: string | $RefParser.JSONSchema, options: $RefParser.Options): Promise<$RefParser.$Refs>;
|
|
171
171
|
}
|
|
172
172
|
|
|
173
|
+
// eslint-disable-next-line no-redeclare
|
|
173
174
|
declare namespace $RefParser {
|
|
174
175
|
|
|
175
176
|
export type JSONSchema = JSONSchema4 | JSONSchema6;
|
|
@@ -179,7 +180,7 @@ declare namespace $RefParser {
|
|
|
179
180
|
/**
|
|
180
181
|
* See https://apitools.dev/json-schema-ref-parser/docs/options.html
|
|
181
182
|
*/
|
|
182
|
-
export
|
|
183
|
+
export interface Options {
|
|
183
184
|
|
|
184
185
|
/**
|
|
185
186
|
* The `parse` options determine how different types of files will be parsed.
|
|
@@ -187,11 +188,11 @@ declare namespace $RefParser {
|
|
|
187
188
|
* JSON Schema `$Ref` Parser comes with built-in JSON, YAML, plain-text, and binary parsers, any of which you can configure or disable. You can also add your own custom parsers if you want.
|
|
188
189
|
*/
|
|
189
190
|
parse?: {
|
|
190
|
-
json?: ParserOptions | boolean
|
|
191
|
-
yaml?: ParserOptions | boolean
|
|
192
|
-
text?: (ParserOptions & { encoding?: string }) | boolean
|
|
193
|
-
[key: string]: ParserOptions | boolean | undefined
|
|
194
|
-
}
|
|
191
|
+
json?: ParserOptions | boolean;
|
|
192
|
+
yaml?: ParserOptions | boolean;
|
|
193
|
+
text?: (ParserOptions & { encoding?: string }) | boolean;
|
|
194
|
+
[key: string]: ParserOptions | boolean | undefined;
|
|
195
|
+
};
|
|
195
196
|
|
|
196
197
|
/**
|
|
197
198
|
* The `resolve` options control how JSON Schema $Ref Parser will resolve file paths and URLs, and how those files will be read/downloaded.
|
|
@@ -203,12 +204,12 @@ declare namespace $RefParser {
|
|
|
203
204
|
/**
|
|
204
205
|
* Determines whether external $ref pointers will be resolved. If this option is disabled, then external `$ref` pointers will simply be ignored.
|
|
205
206
|
*/
|
|
206
|
-
external?: boolean
|
|
207
|
-
file?: Partial<ResolverOptions> | boolean
|
|
208
|
-
http?: HTTPResolverOptions | boolean
|
|
207
|
+
external?: boolean;
|
|
208
|
+
file?: Partial<ResolverOptions> | boolean;
|
|
209
|
+
http?: HTTPResolverOptions | boolean;
|
|
209
210
|
} & {
|
|
210
|
-
[key: string]: Partial<ResolverOptions
|
|
211
|
-
}
|
|
211
|
+
[key: string]: Partial<ResolverOptions>;
|
|
212
|
+
};
|
|
212
213
|
|
|
213
214
|
/**
|
|
214
215
|
* By default, JSON Schema $Ref Parser throws the first error it encounters. Setting `continueOnError` to `true`
|
|
@@ -229,8 +230,8 @@ declare namespace $RefParser {
|
|
|
229
230
|
*
|
|
230
231
|
* If set to `"ignore"`, then circular references will simply be ignored. No error will be thrown, but the `$Refs.circular` property will still be set to `true`.
|
|
231
232
|
*/
|
|
232
|
-
circular?: boolean |
|
|
233
|
-
}
|
|
233
|
+
circular?: boolean | "ignore";
|
|
234
|
+
};
|
|
234
235
|
}
|
|
235
236
|
|
|
236
237
|
export interface HTTPResolverOptions extends Partial<ResolverOptions> {
|
|
@@ -238,22 +239,22 @@ declare namespace $RefParser {
|
|
|
238
239
|
/**
|
|
239
240
|
* You can specify any HTTP headers that should be sent when downloading files. For example, some servers may require you to set the `Accept` or `Referrer` header.
|
|
240
241
|
*/
|
|
241
|
-
headers?: object
|
|
242
|
+
headers?: object;
|
|
242
243
|
|
|
243
244
|
/**
|
|
244
245
|
* The amount of time (in milliseconds) to wait for a response from the server when downloading files. The default is 5 seconds.
|
|
245
246
|
*/
|
|
246
|
-
timeout?: number
|
|
247
|
+
timeout?: number;
|
|
247
248
|
|
|
248
249
|
/**
|
|
249
250
|
* The maximum number of HTTP redirects to follow per file. The default is 5. To disable automatic following of redirects, set this to zero.
|
|
250
251
|
*/
|
|
251
|
-
redirects?: number
|
|
252
|
+
redirects?: number;
|
|
252
253
|
|
|
253
254
|
/**
|
|
254
255
|
* Set this to `true` if you're downloading files from a CORS-enabled server that requires authentication
|
|
255
256
|
*/
|
|
256
|
-
withCredentials?: boolean
|
|
257
|
+
withCredentials?: boolean;
|
|
257
258
|
}
|
|
258
259
|
|
|
259
260
|
/**
|
|
@@ -268,12 +269,12 @@ declare namespace $RefParser {
|
|
|
268
269
|
*
|
|
269
270
|
* The order property and canRead property are related to each other. For each file that JSON Schema $Ref Parser needs to resolve, it first determines which resolvers can read that file by checking their canRead property. If only one resolver matches a file, then only that one resolver is called, regardless of its order. If multiple resolvers match a file, then those resolvers are tried in order until one of them successfully reads the file. Once a resolver successfully reads the file, the rest of the resolvers are skipped.
|
|
270
271
|
*/
|
|
271
|
-
order?: number
|
|
272
|
+
order?: number;
|
|
272
273
|
|
|
273
274
|
/**
|
|
274
275
|
* The `canRead` property tells JSON Schema `$Ref` Parser what kind of files your resolver can read. In this example, we've simply specified a regular expression that matches "mogodb://" URLs, but we could have used a simple boolean, or even a function with custom logic to determine which files to resolve. Here are examples of each approach:
|
|
275
276
|
*/
|
|
276
|
-
canRead: boolean | RegExp | string | string[] | ((file: FileInfo) => boolean)
|
|
277
|
+
canRead: boolean | RegExp | string | string[] | ((file: FileInfo) => boolean);
|
|
277
278
|
|
|
278
279
|
/**
|
|
279
280
|
* This is where the real work of a resolver happens. The `read` method accepts the same file info object as the `canRead` function, but rather than returning a boolean value, the `read` method should return the contents of the file. The file contents should be returned in as raw a form as possible, such as a string or a byte array. Any further parsing or processing should be done by parsers.
|
|
@@ -283,7 +284,7 @@ declare namespace $RefParser {
|
|
|
283
284
|
read(
|
|
284
285
|
file: FileInfo,
|
|
285
286
|
callback?: (error: Error | null, data: string | null) => any
|
|
286
|
-
): string | Buffer | Promise<string | Buffer
|
|
287
|
+
): string | Buffer | Promise<string | Buffer>;
|
|
287
288
|
}
|
|
288
289
|
|
|
289
290
|
export interface ParserOptions {
|
|
@@ -293,21 +294,21 @@ declare namespace $RefParser {
|
|
|
293
294
|
*
|
|
294
295
|
* You can change the order in which parsers run, which is useful if you know that most of your referenced files will be a certain type, or if you add your own custom parser that you want to run first.
|
|
295
296
|
*/
|
|
296
|
-
order?: number
|
|
297
|
+
order?: number;
|
|
297
298
|
|
|
298
299
|
/**
|
|
299
300
|
* All of the built-in parsers allow empty files by default. The JSON and YAML parsers will parse empty files as `undefined`. The text parser will parse empty files as an empty string. The binary parser will parse empty files as an empty byte array.
|
|
300
301
|
*
|
|
301
302
|
* You can set `allowEmpty: false` on any parser, which will cause an error to be thrown if a file empty.
|
|
302
303
|
*/
|
|
303
|
-
allowEmpty?: boolean
|
|
304
|
+
allowEmpty?: boolean;
|
|
304
305
|
|
|
305
306
|
/**
|
|
306
307
|
* Determines which parsers will be used for which files.
|
|
307
308
|
*
|
|
308
309
|
* A regular expression can be used to match files by their full path. A string (or array of strings) can be used to match files by their file extension. Or a function can be used to perform more complex matching logic. See the custom parser docs for details.
|
|
309
310
|
*/
|
|
310
|
-
canParse?: boolean | RegExp | string | string[] | ((file: FileInfo) => boolean)
|
|
311
|
+
canParse?: boolean | RegExp | string | string[] | ((file: FileInfo) => boolean);
|
|
311
312
|
|
|
312
313
|
/**
|
|
313
314
|
* This is where the real work of a parser happens. The `parse` method accepts the same file info object as the `canParse` function, but rather than returning a boolean value, the `parse` method should return a JavaScript representation of the file contents. For our CSV parser, that is a two-dimensional array of lines and values. For your parser, it might be an object, a string, a custom class, or anything else.
|
|
@@ -317,7 +318,7 @@ declare namespace $RefParser {
|
|
|
317
318
|
parse(
|
|
318
319
|
file: FileInfo,
|
|
319
320
|
callback?: (error: Error | null, data: string | null) => any
|
|
320
|
-
): unknown | Promise<unknown
|
|
321
|
+
): unknown | Promise<unknown>;
|
|
321
322
|
}
|
|
322
323
|
|
|
323
324
|
/**
|
|
@@ -332,17 +333,17 @@ declare namespace $RefParser {
|
|
|
332
333
|
/**
|
|
333
334
|
* The full URL of the file. This could be any type of URL, including "http://", "https://", "file://", "ftp://", "mongodb://", or even a local filesystem path (when running in Node.js).
|
|
334
335
|
*/
|
|
335
|
-
url: string
|
|
336
|
+
url: string;
|
|
336
337
|
|
|
337
338
|
/**
|
|
338
339
|
* The lowercase file extension, such as ".json", ".yaml", ".txt", etc.
|
|
339
340
|
*/
|
|
340
|
-
extension: string
|
|
341
|
+
extension: string;
|
|
341
342
|
|
|
342
343
|
/**
|
|
343
344
|
* The raw file contents, in whatever form they were returned by the resolver that read the file.
|
|
344
345
|
*/
|
|
345
|
-
data: string | Buffer
|
|
346
|
+
data: string | Buffer;
|
|
346
347
|
}
|
|
347
348
|
|
|
348
349
|
/**
|
|
@@ -358,7 +359,7 @@ declare namespace $RefParser {
|
|
|
358
359
|
*
|
|
359
360
|
* See https://apitools.dev/json-schema-ref-parser/docs/refs.html#circular
|
|
360
361
|
*/
|
|
361
|
-
circular: boolean
|
|
362
|
+
public circular: boolean;
|
|
362
363
|
|
|
363
364
|
/**
|
|
364
365
|
* Returns the paths/URLs of all the files in your schema (including the main schema file).
|
|
@@ -367,7 +368,7 @@ declare namespace $RefParser {
|
|
|
367
368
|
*
|
|
368
369
|
* @param types (optional) Optionally only return certain types of paths ("file", "http", etc.)
|
|
369
370
|
*/
|
|
370
|
-
paths(...types: string[]): string[]
|
|
371
|
+
public paths(...types: string[]): string[]
|
|
371
372
|
|
|
372
373
|
/**
|
|
373
374
|
* Returns a map of paths/URLs and their correspond values.
|
|
@@ -376,7 +377,7 @@ declare namespace $RefParser {
|
|
|
376
377
|
*
|
|
377
378
|
* @param types (optional) Optionally only return values from certain locations ("file", "http", etc.)
|
|
378
379
|
*/
|
|
379
|
-
values(...types: string[]): { [url: string]: $RefParser.JSONSchema }
|
|
380
|
+
public values(...types: string[]): { [url: string]: $RefParser.JSONSchema }
|
|
380
381
|
|
|
381
382
|
/**
|
|
382
383
|
* Returns `true` if the given path exists in the schema; otherwise, returns `false`
|
|
@@ -385,7 +386,7 @@ declare namespace $RefParser {
|
|
|
385
386
|
*
|
|
386
387
|
* @param $ref The JSON Reference path, optionally with a JSON Pointer in the hash
|
|
387
388
|
*/
|
|
388
|
-
exists($ref: string): boolean
|
|
389
|
+
public exists($ref: string): boolean
|
|
389
390
|
|
|
390
391
|
/**
|
|
391
392
|
* Gets the value at the given path in the schema. Throws an error if the path does not exist.
|
|
@@ -394,7 +395,7 @@ declare namespace $RefParser {
|
|
|
394
395
|
*
|
|
395
396
|
* @param $ref The JSON Reference path, optionally with a JSON Pointer in the hash
|
|
396
397
|
*/
|
|
397
|
-
get($ref: string): JSONSchema4Type | JSONSchema6Type
|
|
398
|
+
public get($ref: string): JSONSchema4Type | JSONSchema6Type
|
|
398
399
|
|
|
399
400
|
/**
|
|
400
401
|
* Sets the value at the given path in the schema. If the property, or any of its parents, don't exist, they will be created.
|
|
@@ -402,18 +403,18 @@ declare namespace $RefParser {
|
|
|
402
403
|
* @param $ref The JSON Reference path, optionally with a JSON Pointer in the hash
|
|
403
404
|
* @param value The value to assign. Can be anything (object, string, number, etc.)
|
|
404
405
|
*/
|
|
405
|
-
set($ref: string, value: JSONSchema4Type | JSONSchema6Type): void
|
|
406
|
+
public set($ref: string, value: JSONSchema4Type | JSONSchema6Type): void
|
|
406
407
|
}
|
|
407
408
|
|
|
408
409
|
export type JSONParserErrorType = "EUNKNOWN" | "EPARSER" | "EUNMATCHEDPARSER" | "ERESOLVER" | "EUNMATCHEDRESOLVER" | "EMISSINGPOINTER" | "EINVALIDPOINTER";
|
|
409
410
|
|
|
410
411
|
export class JSONParserError extends Error {
|
|
411
|
-
readonly name: string;
|
|
412
|
-
readonly message: string;
|
|
413
|
-
readonly source: string;
|
|
414
|
-
readonly path: Array<string | number>;
|
|
415
|
-
readonly errors: string;
|
|
416
|
-
readonly code: JSONParserErrorType;
|
|
412
|
+
public readonly name: string;
|
|
413
|
+
public readonly message: string;
|
|
414
|
+
public readonly source: string;
|
|
415
|
+
public readonly path: Array<string | number>;
|
|
416
|
+
public readonly errors: string;
|
|
417
|
+
public readonly code: JSONParserErrorType;
|
|
417
418
|
}
|
|
418
419
|
|
|
419
420
|
export class JSONParserErrorGroup extends Error {
|
|
@@ -422,44 +423,44 @@ declare namespace $RefParser {
|
|
|
422
423
|
*
|
|
423
424
|
* See https://github.com/APIDevTools/json-schema-ref-parser/blob/master/docs/ref-parser.md#errors
|
|
424
425
|
*/
|
|
425
|
-
readonly errors: Array<$RefParser.JSONParserError | $RefParser.InvalidPointerError | $RefParser.ResolverError | $RefParser.ParserError | $RefParser.MissingPointerError | $RefParser.UnmatchedParserError | $RefParser.UnmatchedResolverError>;
|
|
426
|
+
public readonly errors: Array<$RefParser.JSONParserError | $RefParser.InvalidPointerError | $RefParser.ResolverError | $RefParser.ParserError | $RefParser.MissingPointerError | $RefParser.UnmatchedParserError | $RefParser.UnmatchedResolverError>;
|
|
426
427
|
|
|
427
428
|
/**
|
|
428
429
|
* The fields property is a `$RefParser` instance
|
|
429
430
|
*
|
|
430
431
|
* See https://apitools.dev/json-schema-ref-parser/docs/ref-parser.html
|
|
431
432
|
*/
|
|
432
|
-
readonly files: $RefParser;
|
|
433
|
+
public readonly files: $RefParser;
|
|
433
434
|
|
|
434
435
|
/**
|
|
435
436
|
* User friendly message containing the total amount of errors, as well as the absolute path to the source document
|
|
436
437
|
*/
|
|
437
|
-
readonly message: string;
|
|
438
|
+
public readonly message: string;
|
|
438
439
|
}
|
|
439
440
|
|
|
440
441
|
export class ParserError extends JSONParserError {
|
|
441
|
-
readonly name = "ParserError";
|
|
442
|
-
readonly code = "EPARSER";
|
|
442
|
+
public readonly name = "ParserError";
|
|
443
|
+
public readonly code = "EPARSER";
|
|
443
444
|
}
|
|
444
445
|
export class UnmatchedParserError extends JSONParserError {
|
|
445
|
-
readonly name = "UnmatchedParserError";
|
|
446
|
-
readonly code ="EUNMATCHEDPARSER";
|
|
446
|
+
public readonly name = "UnmatchedParserError";
|
|
447
|
+
public readonly code ="EUNMATCHEDPARSER";
|
|
447
448
|
}
|
|
448
449
|
export class ResolverError extends JSONParserError {
|
|
449
|
-
readonly name = "ResolverError";
|
|
450
|
-
readonly code ="ERESOLVER";
|
|
451
|
-
readonly ioErrorCode?: string;
|
|
450
|
+
public readonly name = "ResolverError";
|
|
451
|
+
public readonly code ="ERESOLVER";
|
|
452
|
+
public readonly ioErrorCode?: string;
|
|
452
453
|
}
|
|
453
454
|
export class UnmatchedResolverError extends JSONParserError {
|
|
454
|
-
readonly name = "UnmatchedResolverError";
|
|
455
|
-
readonly code ="EUNMATCHEDRESOLVER";
|
|
455
|
+
public readonly name = "UnmatchedResolverError";
|
|
456
|
+
public readonly code ="EUNMATCHEDRESOLVER";
|
|
456
457
|
}
|
|
457
458
|
export class MissingPointerError extends JSONParserError {
|
|
458
|
-
readonly name = "MissingPointerError";
|
|
459
|
-
readonly code ="EMISSINGPOINTER";
|
|
459
|
+
public readonly name = "MissingPointerError";
|
|
460
|
+
public readonly code ="EMISSINGPOINTER";
|
|
460
461
|
}
|
|
461
462
|
export class InvalidPointerError extends JSONParserError {
|
|
462
|
-
readonly name = "InvalidPointerError";
|
|
463
|
-
readonly code ="EINVALIDPOINTER";
|
|
463
|
+
public readonly name = "InvalidPointerError";
|
|
464
|
+
public readonly code ="EINVALIDPOINTER";
|
|
464
465
|
}
|
|
465
466
|
}
|
package/lib/index.js
CHANGED
package/lib/parsers/json.js
CHANGED
|
@@ -36,7 +36,7 @@ module.exports = {
|
|
|
36
36
|
* @param {*} file.data - The file contents. This will be whatever data type was returned by the resolver
|
|
37
37
|
* @returns {Promise}
|
|
38
38
|
*/
|
|
39
|
-
async parse (file) {
|
|
39
|
+
async parse (file) { // eslint-disable-line require-await
|
|
40
40
|
let data = file.data;
|
|
41
41
|
if (Buffer.isBuffer(data)) {
|
|
42
42
|
data = data.toString();
|
package/lib/parsers/yaml.js
CHANGED
|
@@ -37,7 +37,7 @@ module.exports = {
|
|
|
37
37
|
* @param {*} file.data - The file contents. This will be whatever data type was returned by the resolver
|
|
38
38
|
* @returns {Promise}
|
|
39
39
|
*/
|
|
40
|
-
async parse (file) {
|
|
40
|
+
async parse (file) { // eslint-disable-line require-await
|
|
41
41
|
let data = file.data;
|
|
42
42
|
if (Buffer.isBuffer(data)) {
|
|
43
43
|
data = data.toString();
|
package/lib/pointer.js
CHANGED
|
@@ -64,6 +64,7 @@ function Pointer ($ref, path, friendlyPath) {
|
|
|
64
64
|
*
|
|
65
65
|
* @param {*} obj - The object that will be crawled
|
|
66
66
|
* @param {$RefParserOptions} options
|
|
67
|
+
* @param {string} pathFromRoot - the path of place that initiated resolving
|
|
67
68
|
*
|
|
68
69
|
* @returns {Pointer}
|
|
69
70
|
* Returns a JSON pointer whose {@link Pointer#value} is the resolved value.
|
|
@@ -71,7 +72,7 @@ function Pointer ($ref, path, friendlyPath) {
|
|
|
71
72
|
* the {@link Pointer#$ref} and {@link Pointer#path} will reflect the resolution path
|
|
72
73
|
* of the resolved value.
|
|
73
74
|
*/
|
|
74
|
-
Pointer.prototype.resolve = function (obj, options) {
|
|
75
|
+
Pointer.prototype.resolve = function (obj, options, pathFromRoot) {
|
|
75
76
|
let tokens = Pointer.parse(this.path, this.originalPath);
|
|
76
77
|
|
|
77
78
|
// Crawl the object, one token at a time
|
|
@@ -83,6 +84,10 @@ Pointer.prototype.resolve = function (obj, options) {
|
|
|
83
84
|
this.path = Pointer.join(this.path, tokens.slice(i));
|
|
84
85
|
}
|
|
85
86
|
|
|
87
|
+
if (typeof this.value === "object" && this.value !== null && "$ref" in this.value) {
|
|
88
|
+
return this;
|
|
89
|
+
}
|
|
90
|
+
|
|
86
91
|
let token = tokens[i];
|
|
87
92
|
if (this.value[token] === undefined || this.value[token] === null) {
|
|
88
93
|
this.value = null;
|
|
@@ -94,7 +99,10 @@ Pointer.prototype.resolve = function (obj, options) {
|
|
|
94
99
|
}
|
|
95
100
|
|
|
96
101
|
// Resolve the final value
|
|
97
|
-
|
|
102
|
+
if (!this.value || this.value.$ref && url.resolve(this.path, this.value.$ref) !== pathFromRoot) {
|
|
103
|
+
resolveIf$Ref(this, options);
|
|
104
|
+
}
|
|
105
|
+
|
|
98
106
|
return this;
|
|
99
107
|
};
|
|
100
108
|
|
|
@@ -226,7 +234,7 @@ function resolveIf$Ref (pointer, options) {
|
|
|
226
234
|
pointer.circular = true;
|
|
227
235
|
}
|
|
228
236
|
else {
|
|
229
|
-
let resolved = pointer.$ref.$refs._resolve($refPath,
|
|
237
|
+
let resolved = pointer.$ref.$refs._resolve($refPath, pointer.path, options);
|
|
230
238
|
pointer.indirections += resolved.indirections + 1;
|
|
231
239
|
|
|
232
240
|
if ($Ref.isExtended$Ref(pointer.value)) {
|
package/lib/ref.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
module.exports = $Ref;
|
|
4
4
|
|
|
5
5
|
const Pointer = require("./pointer");
|
|
6
|
-
const {
|
|
6
|
+
const { InvalidPointerError, isHandledError, normalizeError } = require("./util/errors");
|
|
7
7
|
const { safePointerToPath, stripHash, getHash } = require("./util/url");
|
|
8
8
|
|
|
9
9
|
/**
|
|
@@ -112,7 +112,7 @@ $Ref.prototype.get = function (path, options) {
|
|
|
112
112
|
$Ref.prototype.resolve = function (path, options, friendlyPath, pathFromRoot) {
|
|
113
113
|
let pointer = new Pointer(this, path, friendlyPath);
|
|
114
114
|
try {
|
|
115
|
-
return pointer.resolve(this.value, options);
|
|
115
|
+
return pointer.resolve(this.value, options, pathFromRoot);
|
|
116
116
|
}
|
|
117
117
|
catch (err) {
|
|
118
118
|
if (!options || !options.continueOnError || !isHandledError(err)) {
|
package/lib/refs.js
CHANGED
|
@@ -41,7 +41,7 @@ function $Refs () {
|
|
|
41
41
|
* @param {...string|string[]} [types] - Only return paths of the given types ("file", "http", etc.)
|
|
42
42
|
* @returns {string[]}
|
|
43
43
|
*/
|
|
44
|
-
$Refs.prototype.paths = function (types) {
|
|
44
|
+
$Refs.prototype.paths = function (types) { // eslint-disable-line no-unused-vars
|
|
45
45
|
let paths = getPaths(this._$refs, arguments);
|
|
46
46
|
return paths.map((path) => {
|
|
47
47
|
return path.decoded;
|
|
@@ -54,7 +54,7 @@ $Refs.prototype.paths = function (types) {
|
|
|
54
54
|
* @param {...string|string[]} [types] - Only return references of the given types ("file", "http", etc.)
|
|
55
55
|
* @returns {object}
|
|
56
56
|
*/
|
|
57
|
-
$Refs.prototype.values = function (types) {
|
|
57
|
+
$Refs.prototype.values = function (types) { // eslint-disable-line no-unused-vars
|
|
58
58
|
let $refs = this._$refs;
|
|
59
59
|
let paths = getPaths($refs, arguments);
|
|
60
60
|
return paths.reduce((obj, path) => {
|
package/lib/resolve-external.js
CHANGED
|
@@ -54,7 +54,7 @@ function resolveExternal (parser, options) {
|
|
|
54
54
|
function crawl (obj, path, $refs, options) {
|
|
55
55
|
let promises = [];
|
|
56
56
|
|
|
57
|
-
if (obj && typeof obj === "object") {
|
|
57
|
+
if (obj && typeof obj === "object" && !ArrayBuffer.isView(obj)) {
|
|
58
58
|
if ($Ref.isExternal$Ref(obj)) {
|
|
59
59
|
promises.push(resolve$Ref(obj, path, $refs, options));
|
|
60
60
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apidevtools/json-schema-ref-parser",
|
|
3
|
-
"version": "9.0.
|
|
3
|
+
"version": "9.0.7",
|
|
4
4
|
"description": "Parse, Resolve, and Dereference JSON Schema $ref pointers",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"json",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"test": "npm run test:node && npm run test:typescript && npm run test:browser && npm run lint",
|
|
43
43
|
"test:node": "mocha",
|
|
44
44
|
"test:browser": "karma start --single-run",
|
|
45
|
-
"test:typescript": "tsc --noEmit --strict --lib esnext test/specs/typescript-definition.spec.ts",
|
|
45
|
+
"test:typescript": "tsc --noEmit --strict --lib esnext,dom test/specs/typescript-definition.spec.ts",
|
|
46
46
|
"coverage": "npm run coverage:node && npm run coverage:browser",
|
|
47
47
|
"coverage:node": "nyc node_modules/mocha/bin/mocha",
|
|
48
48
|
"coverage:browser": "npm run test:browser -- --coverage",
|
|
@@ -51,26 +51,26 @@
|
|
|
51
51
|
"release": "npm run upgrade && npm run clean && npm test && npm run bump"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@babel/polyfill": "^7.
|
|
55
|
-
"@jsdevtools/eslint-config
|
|
56
|
-
"@jsdevtools/host-environment": "^2.
|
|
57
|
-
"@jsdevtools/karma-config": "^3.1.
|
|
58
|
-
"@jsdevtools/version-bump-prompt": "^6.0
|
|
59
|
-
"@types/json-schema": "^7.0.
|
|
60
|
-
"@types/node": "^14.
|
|
54
|
+
"@babel/polyfill": "^7.12.1",
|
|
55
|
+
"@jsdevtools/eslint-config": "^1.0.7",
|
|
56
|
+
"@jsdevtools/host-environment": "^2.1.2",
|
|
57
|
+
"@jsdevtools/karma-config": "^3.1.7",
|
|
58
|
+
"@jsdevtools/version-bump-prompt": "^6.1.0",
|
|
59
|
+
"@types/json-schema": "^7.0.6",
|
|
60
|
+
"@types/node": "^14.14.21",
|
|
61
61
|
"chai": "^4.2.0",
|
|
62
62
|
"chai-subset": "^1.6.0",
|
|
63
|
-
"eslint": "^7.
|
|
63
|
+
"eslint": "^7.18.0",
|
|
64
64
|
"karma": "^5.0.2",
|
|
65
65
|
"karma-cli": "^2.0.0",
|
|
66
|
-
"mocha": "^8.
|
|
66
|
+
"mocha": "^8.2.1",
|
|
67
67
|
"npm-check": "^5.9.0",
|
|
68
68
|
"nyc": "^15.0.1",
|
|
69
69
|
"shx": "^0.3.2",
|
|
70
|
-
"typescript": "^
|
|
70
|
+
"typescript": "^4.0.5"
|
|
71
71
|
},
|
|
72
72
|
"dependencies": {
|
|
73
|
-
"@jsdevtools/ono": "^7.1.
|
|
73
|
+
"@jsdevtools/ono": "^7.1.3",
|
|
74
74
|
"call-me-maybe": "^1.0.1",
|
|
75
75
|
"js-yaml": "^3.13.1"
|
|
76
76
|
}
|