@apidevtools/json-schema-ref-parser 11.4.1 → 11.5.0
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/dist/lib/bundle.d.ts +5 -2
- package/dist/lib/bundle.js +4 -4
- package/dist/lib/dereference.d.ts +4 -1
- package/dist/lib/dereference.js +6 -7
- package/dist/lib/index.d.ts +54 -95
- package/dist/lib/index.js +0 -13
- package/dist/lib/normalize-args.d.ts +7 -7
- package/dist/lib/normalize-args.js +7 -2
- package/dist/lib/options.d.ts +47 -46
- package/dist/lib/parse.d.ts +3 -2
- package/dist/lib/parse.js +3 -2
- package/dist/lib/pointer.d.ts +6 -5
- package/dist/lib/ref.d.ts +9 -8
- package/dist/lib/ref.js +1 -1
- package/dist/lib/refs.d.ts +14 -14
- package/dist/lib/refs.js +1 -1
- package/dist/lib/resolve-external.d.ts +4 -3
- package/dist/lib/resolve-external.js +4 -4
- package/dist/lib/resolvers/file.d.ts +2 -2
- package/dist/lib/resolvers/http.d.ts +2 -2
- package/dist/lib/types/index.d.ts +5 -5
- package/dist/lib/util/errors.d.ts +6 -4
- package/dist/lib/util/plugins.d.ts +4 -5
- package/lib/bundle.ts +23 -19
- package/lib/dereference.ts +21 -17
- package/lib/index.ts +165 -157
- package/lib/normalize-args.ts +15 -10
- package/lib/options.ts +52 -50
- package/lib/parse.ts +22 -10
- package/lib/pointer.ts +6 -5
- package/lib/ref.ts +12 -11
- package/lib/refs.ts +13 -13
- package/lib/resolve-external.ts +21 -14
- package/lib/resolvers/file.ts +2 -2
- package/lib/resolvers/http.ts +8 -4
- package/lib/types/index.ts +5 -5
- package/lib/util/errors.ts +14 -6
- package/lib/util/plugins.ts +14 -15
- package/package.json +1 -1
package/dist/lib/bundle.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import type $RefParser from "./index";
|
|
2
|
+
import type { ParserOptions } from "./index";
|
|
3
|
+
import type { JSONSchema } from "./index";
|
|
2
4
|
/**
|
|
3
5
|
* Bundles all external JSON references into the main JSON schema, thus resulting in a schema that
|
|
4
6
|
* only has *internal* references, not any *external* references.
|
|
@@ -7,4 +9,5 @@ export default bundle;
|
|
|
7
9
|
* @param parser
|
|
8
10
|
* @param options
|
|
9
11
|
*/
|
|
10
|
-
declare function bundle(parser:
|
|
12
|
+
declare function bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(parser: $RefParser<S, O>, options: O): void;
|
|
13
|
+
export default bundle;
|
package/dist/lib/bundle.js
CHANGED
|
@@ -29,7 +29,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
29
29
|
const ref_js_1 = __importDefault(require("./ref.js"));
|
|
30
30
|
const pointer_js_1 = __importDefault(require("./pointer.js"));
|
|
31
31
|
const url = __importStar(require("./util/url.js"));
|
|
32
|
-
exports.default = bundle;
|
|
33
32
|
/**
|
|
34
33
|
* Bundles all external JSON references into the main JSON schema, thus resulting in a schema that
|
|
35
34
|
* only has *internal* references, not any *external* references.
|
|
@@ -53,6 +52,7 @@ function bundle(parser, options) {
|
|
|
53
52
|
* @param key - The property key of `parent` to be crawled
|
|
54
53
|
* @param path - The full path of the property being crawled, possibly with a JSON Pointer in the hash
|
|
55
54
|
* @param pathFromRoot - The path of the property being crawled, from the schema root
|
|
55
|
+
* @param indirections
|
|
56
56
|
* @param inventory - An array of already-inventoried $ref pointers
|
|
57
57
|
* @param $refs
|
|
58
58
|
* @param options
|
|
@@ -251,9 +251,8 @@ function remap(inventory) {
|
|
|
251
251
|
* TODO
|
|
252
252
|
*/
|
|
253
253
|
function findInInventory(inventory, $refParent, $refKey) {
|
|
254
|
-
for (
|
|
255
|
-
|
|
256
|
-
if (existingEntry.parent === $refParent && existingEntry.key === $refKey) {
|
|
254
|
+
for (const existingEntry of inventory) {
|
|
255
|
+
if (existingEntry && existingEntry.parent === $refParent && existingEntry.key === $refKey) {
|
|
257
256
|
return existingEntry;
|
|
258
257
|
}
|
|
259
258
|
}
|
|
@@ -262,3 +261,4 @@ function removeFromInventory(inventory, entry) {
|
|
|
262
261
|
const index = inventory.indexOf(entry);
|
|
263
262
|
inventory.splice(index, 1);
|
|
264
263
|
}
|
|
264
|
+
exports.default = bundle;
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import type { ParserOptions } from "./options.js";
|
|
2
|
+
import type { JSONSchema } from "./types";
|
|
3
|
+
import type $RefParser from "./index";
|
|
1
4
|
export default dereference;
|
|
2
5
|
/**
|
|
3
6
|
* Crawls the JSON schema, finds all JSON references, and dereferences them.
|
|
@@ -6,4 +9,4 @@ export default dereference;
|
|
|
6
9
|
* @param parser
|
|
7
10
|
* @param options
|
|
8
11
|
*/
|
|
9
|
-
declare function dereference(parser:
|
|
12
|
+
declare function dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(parser: $RefParser<S, O>, options: O): void;
|
package/dist/lib/dereference.js
CHANGED
|
@@ -63,8 +63,9 @@ function crawl(obj, path, pathFromRoot, parents, processedObjects, dereferencedC
|
|
|
63
63
|
value: obj,
|
|
64
64
|
circular: false,
|
|
65
65
|
};
|
|
66
|
-
const
|
|
67
|
-
|
|
66
|
+
const derefOptions = (options.dereference || {});
|
|
67
|
+
const isExcludedPath = derefOptions.excludedPathMatcher || (() => false);
|
|
68
|
+
if (derefOptions?.circular === "ignore" || !processedObjects.has(obj)) {
|
|
68
69
|
if (obj && typeof obj === "object" && !ArrayBuffer.isView(obj) && !isExcludedPath(pathFromRoot)) {
|
|
69
70
|
parents.add(obj);
|
|
70
71
|
processedObjects.add(obj);
|
|
@@ -88,9 +89,7 @@ function crawl(obj, path, pathFromRoot, parents, processedObjects, dereferencedC
|
|
|
88
89
|
// Avoid pointless mutations; breaks frozen objects to no profit
|
|
89
90
|
if (obj[key] !== dereferenced.value) {
|
|
90
91
|
obj[key] = dereferenced.value;
|
|
91
|
-
|
|
92
|
-
options.dereference.onDereference(value.$ref, obj[key], obj, key);
|
|
93
|
-
}
|
|
92
|
+
derefOptions?.onDereference?.(value.$ref, obj[key], obj, key);
|
|
94
93
|
}
|
|
95
94
|
}
|
|
96
95
|
else {
|
|
@@ -130,7 +129,7 @@ function crawl(obj, path, pathFromRoot, parents, processedObjects, dereferencedC
|
|
|
130
129
|
*/
|
|
131
130
|
function dereference$Ref($ref, path, pathFromRoot, parents, processedObjects, dereferencedCache, $refs, options) {
|
|
132
131
|
const isExternalRef = ref_js_1.default.isExternal$Ref($ref);
|
|
133
|
-
const shouldResolveOnCwd = isExternalRef && options?.dereference
|
|
132
|
+
const shouldResolveOnCwd = isExternalRef && options?.dereference?.externalReferenceResolution === "root";
|
|
134
133
|
const $refPath = url.resolve(shouldResolveOnCwd ? url.cwd() : path, $ref.$ref);
|
|
135
134
|
const cache = dereferencedCache.get($refPath);
|
|
136
135
|
if (cache) {
|
|
@@ -170,7 +169,7 @@ function dereference$Ref($ref, path, pathFromRoot, parents, processedObjects, de
|
|
|
170
169
|
circular = dereferenced.circular;
|
|
171
170
|
dereferencedValue = dereferenced.value;
|
|
172
171
|
}
|
|
173
|
-
if (circular && !directCircular && options.dereference
|
|
172
|
+
if (circular && !directCircular && options.dereference?.circular === "ignore") {
|
|
174
173
|
// The user has chosen to "ignore" circular references, so don't change the value
|
|
175
174
|
dereferencedValue = $ref;
|
|
176
175
|
}
|
package/dist/lib/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import $Refs from "./refs.js";
|
|
2
2
|
import { JSONParserError, InvalidPointerError, MissingPointerError, ResolverError, ParserError, UnmatchedParserError, UnmatchedResolverError, isHandledError, JSONParserErrorGroup } from "./util/errors.js";
|
|
3
3
|
import type { ParserOptions } from "./options.js";
|
|
4
|
-
import type { $RefsCallback, JSONSchema, SchemaCallback } from "./types/index.js";
|
|
4
|
+
import type { $RefsCallback, JSONSchema, SchemaCallback, FileInfo, Plugin, ResolverOptions, HTTPResolverOptions } from "./types/index.js";
|
|
5
5
|
export type RefParserSchema = string | JSONSchema;
|
|
6
6
|
/**
|
|
7
7
|
* This class parses a JSON schema, builds a map of its JSON references and their resolved values,
|
|
@@ -9,21 +9,21 @@ export type RefParserSchema = string | JSONSchema;
|
|
|
9
9
|
*
|
|
10
10
|
* @class
|
|
11
11
|
*/
|
|
12
|
-
export declare class $RefParser {
|
|
12
|
+
export declare class $RefParser<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions> {
|
|
13
13
|
/**
|
|
14
14
|
* The parsed (and possibly dereferenced) JSON schema object
|
|
15
15
|
*
|
|
16
16
|
* @type {object}
|
|
17
17
|
* @readonly
|
|
18
18
|
*/
|
|
19
|
-
schema:
|
|
19
|
+
schema: S | null;
|
|
20
20
|
/**
|
|
21
21
|
* The resolved JSON references
|
|
22
22
|
*
|
|
23
23
|
* @type {$Refs}
|
|
24
24
|
* @readonly
|
|
25
25
|
*/
|
|
26
|
-
$refs: $Refs
|
|
26
|
+
$refs: $Refs<S>;
|
|
27
27
|
/**
|
|
28
28
|
* Parses the given JSON schema.
|
|
29
29
|
* This method does not resolve any JSON references.
|
|
@@ -35,18 +35,18 @@ export declare class $RefParser {
|
|
|
35
35
|
* @param [callback] - An error-first callback. The second parameter is the parsed JSON schema object.
|
|
36
36
|
* @returns - The returned promise resolves with the parsed JSON schema object.
|
|
37
37
|
*/
|
|
38
|
-
parse(schema:
|
|
39
|
-
parse(schema:
|
|
40
|
-
parse(schema:
|
|
41
|
-
parse(schema:
|
|
42
|
-
parse(baseUrl: string, schema:
|
|
43
|
-
parse(baseUrl: string, schema:
|
|
44
|
-
static parse(schema:
|
|
45
|
-
static parse(schema:
|
|
46
|
-
static parse(schema:
|
|
47
|
-
static parse(schema:
|
|
48
|
-
static parse(baseUrl: string, schema:
|
|
49
|
-
static parse(baseUrl: string, schema:
|
|
38
|
+
parse(schema: S | string): Promise<S>;
|
|
39
|
+
parse(schema: S | string, callback: SchemaCallback<S>): Promise<void>;
|
|
40
|
+
parse(schema: S | string, options: O): Promise<S>;
|
|
41
|
+
parse(schema: S | string, options: O, callback: SchemaCallback<S>): Promise<void>;
|
|
42
|
+
parse(baseUrl: string, schema: S | string, options: O): Promise<S>;
|
|
43
|
+
parse(baseUrl: string, schema: S | string, options: O, callback: SchemaCallback<S>): Promise<void>;
|
|
44
|
+
static parse<S extends JSONSchema = JSONSchema>(schema: S | string): Promise<S>;
|
|
45
|
+
static parse<S extends JSONSchema = JSONSchema>(schema: S | string, callback: SchemaCallback<S>): Promise<void>;
|
|
46
|
+
static parse<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(schema: S | string, options: O): Promise<S>;
|
|
47
|
+
static parse<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(schema: S | string, options: O, callback: SchemaCallback<S>): Promise<void>;
|
|
48
|
+
static parse<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(baseUrl: string, schema: S | string, options: O): Promise<S>;
|
|
49
|
+
static parse<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(baseUrl: string, schema: S | string, options: O, callback: SchemaCallback<S>): Promise<void>;
|
|
50
50
|
/**
|
|
51
51
|
* *This method is used internally by other methods, such as `bundle` and `dereference`. You probably won't need to call this method yourself.*
|
|
52
52
|
*
|
|
@@ -58,12 +58,12 @@ export declare class $RefParser {
|
|
|
58
58
|
* @param options (optional)
|
|
59
59
|
* @param callback (optional) A callback that will receive a `$Refs` object
|
|
60
60
|
*/
|
|
61
|
-
resolve(schema:
|
|
62
|
-
resolve(schema:
|
|
63
|
-
resolve(schema:
|
|
64
|
-
resolve(schema:
|
|
65
|
-
resolve(baseUrl: string, schema:
|
|
66
|
-
resolve(baseUrl: string, schema:
|
|
61
|
+
resolve(schema: S | string): Promise<$Refs<S>>;
|
|
62
|
+
resolve(schema: S | string, callback: $RefsCallback<S>): Promise<void>;
|
|
63
|
+
resolve(schema: S | string, options: O): Promise<$Refs<S>>;
|
|
64
|
+
resolve(schema: S | string, options: O, callback: $RefsCallback<S>): Promise<void>;
|
|
65
|
+
resolve(baseUrl: string, schema: S | string, options: O): Promise<$Refs<S>>;
|
|
66
|
+
resolve(baseUrl: string, schema: S | string, options: O, callback: $RefsCallback<S>): Promise<void>;
|
|
67
67
|
/**
|
|
68
68
|
* *This method is used internally by other methods, such as `bundle` and `dereference`. You probably won't need to call this method yourself.*
|
|
69
69
|
*
|
|
@@ -75,23 +75,12 @@ export declare class $RefParser {
|
|
|
75
75
|
* @param options (optional)
|
|
76
76
|
* @param callback (optional) A callback that will receive a `$Refs` object
|
|
77
77
|
*/
|
|
78
|
-
static resolve(schema:
|
|
79
|
-
static resolve(schema:
|
|
80
|
-
static resolve(schema:
|
|
81
|
-
static resolve(schema:
|
|
82
|
-
static resolve(baseUrl: string, schema:
|
|
83
|
-
static resolve(baseUrl: string, schema:
|
|
84
|
-
/**
|
|
85
|
-
* Parses the given JSON schema, resolves any JSON references, and bundles all external references
|
|
86
|
-
* into the main JSON schema. This produces a JSON schema that only has *internal* references,
|
|
87
|
-
* not any *external* references.
|
|
88
|
-
*
|
|
89
|
-
* @param [path] - The file path or URL of the JSON schema
|
|
90
|
-
* @param [schema] - A JSON schema object. This object will be used instead of reading from `path`.
|
|
91
|
-
* @param [options] - Options that determine how the schema is parsed, resolved, and dereferenced
|
|
92
|
-
* @param [callback] - An error-first callback. The second parameter is the bundled JSON schema object
|
|
93
|
-
* @returns - The returned promise resolves with the bundled JSON schema object.
|
|
94
|
-
*/
|
|
78
|
+
static resolve<S extends JSONSchema = JSONSchema>(schema: S | string): Promise<$Refs<S>>;
|
|
79
|
+
static resolve<S extends JSONSchema = JSONSchema>(schema: S | string, callback: $RefsCallback<S>): Promise<void>;
|
|
80
|
+
static resolve<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(schema: S | string, options: O): Promise<$Refs<S>>;
|
|
81
|
+
static resolve<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(schema: S | string, options: O, callback: $RefsCallback<S>): Promise<void>;
|
|
82
|
+
static resolve<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(baseUrl: string, schema: S | string, options: O): Promise<$Refs<S>>;
|
|
83
|
+
static resolve<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(baseUrl: string, schema: S | string, options: O, callback: $RefsCallback<S>): Promise<void>;
|
|
95
84
|
/**
|
|
96
85
|
* 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.
|
|
97
86
|
*
|
|
@@ -103,23 +92,12 @@ export declare class $RefParser {
|
|
|
103
92
|
* @param options (optional)
|
|
104
93
|
* @param callback (optional) A callback that will receive the bundled schema object
|
|
105
94
|
*/
|
|
106
|
-
static bundle(schema:
|
|
107
|
-
static bundle(schema:
|
|
108
|
-
static bundle(schema:
|
|
109
|
-
static bundle(schema:
|
|
110
|
-
static bundle(baseUrl: string, schema:
|
|
111
|
-
static bundle(baseUrl: string, schema:
|
|
112
|
-
/**
|
|
113
|
-
* Parses the given JSON schema, resolves any JSON references, and bundles all external references
|
|
114
|
-
* into the main JSON schema. This produces a JSON schema that only has *internal* references,
|
|
115
|
-
* not any *external* references.
|
|
116
|
-
*
|
|
117
|
-
* @param [path] - The file path or URL of the JSON schema
|
|
118
|
-
* @param [schema] - A JSON schema object. This object will be used instead of reading from `path`.
|
|
119
|
-
* @param [options] - Options that determine how the schema is parsed, resolved, and dereferenced
|
|
120
|
-
* @param [callback] - An error-first callback. The second parameter is the bundled JSON schema object
|
|
121
|
-
* @returns - The returned promise resolves with the bundled JSON schema object.
|
|
122
|
-
*/
|
|
95
|
+
static bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(schema: S | string): Promise<S>;
|
|
96
|
+
static bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(schema: S | string, callback: SchemaCallback<S>): Promise<void>;
|
|
97
|
+
static bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(schema: S | string, options: O): Promise<S>;
|
|
98
|
+
static bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(schema: S | string, options: O, callback: SchemaCallback<S>): Promise<void>;
|
|
99
|
+
static bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(baseUrl: string, schema: S | string, options: O): Promise<S>;
|
|
100
|
+
static bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(baseUrl: string, schema: S | string, options: O, callback: SchemaCallback<S>): Promise<S>;
|
|
123
101
|
/**
|
|
124
102
|
* 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.
|
|
125
103
|
*
|
|
@@ -131,22 +109,12 @@ export declare class $RefParser {
|
|
|
131
109
|
* @param options (optional)
|
|
132
110
|
* @param callback (optional) A callback that will receive the bundled schema object
|
|
133
111
|
*/
|
|
134
|
-
bundle(schema:
|
|
135
|
-
bundle(schema:
|
|
136
|
-
bundle(schema:
|
|
137
|
-
bundle(schema:
|
|
138
|
-
bundle(baseUrl: string, schema:
|
|
139
|
-
bundle(baseUrl: string, schema:
|
|
140
|
-
/**
|
|
141
|
-
* Parses the given JSON schema, resolves any JSON references, and dereferences the JSON schema.
|
|
142
|
-
* That is, all JSON references are replaced with their resolved values.
|
|
143
|
-
*
|
|
144
|
-
* @param [path] - The file path or URL of the JSON schema
|
|
145
|
-
* @param [schema] - A JSON schema object. This object will be used instead of reading from `path`.
|
|
146
|
-
* @param [options] - Options that determine how the schema is parsed, resolved, and dereferenced
|
|
147
|
-
* @param [callback] - An error-first callback. The second parameter is the dereferenced JSON schema object
|
|
148
|
-
* @returns - The returned promise resolves with the dereferenced JSON schema object.
|
|
149
|
-
*/
|
|
112
|
+
bundle(schema: S | string): Promise<S>;
|
|
113
|
+
bundle(schema: S | string, callback: SchemaCallback<S>): Promise<void>;
|
|
114
|
+
bundle(schema: S | string, options: O): Promise<S>;
|
|
115
|
+
bundle(schema: S | string, options: O, callback: SchemaCallback<S>): Promise<void>;
|
|
116
|
+
bundle(baseUrl: string, schema: S | string, options: O): Promise<S>;
|
|
117
|
+
bundle(baseUrl: string, schema: S | string, options: O, callback: SchemaCallback<S>): Promise<void>;
|
|
150
118
|
/**
|
|
151
119
|
* 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.
|
|
152
120
|
*
|
|
@@ -158,22 +126,12 @@ export declare class $RefParser {
|
|
|
158
126
|
* @param options (optional)
|
|
159
127
|
* @param callback (optional) A callback that will receive the dereferenced schema object
|
|
160
128
|
*/
|
|
161
|
-
static dereference(schema:
|
|
162
|
-
static dereference(schema:
|
|
163
|
-
static dereference(schema:
|
|
164
|
-
static dereference(schema:
|
|
165
|
-
static dereference(baseUrl: string, schema:
|
|
166
|
-
static dereference(baseUrl: string, schema:
|
|
167
|
-
/**
|
|
168
|
-
* Parses the given JSON schema, resolves any JSON references, and dereferences the JSON schema.
|
|
169
|
-
* That is, all JSON references are replaced with their resolved values.
|
|
170
|
-
*
|
|
171
|
-
* @param [path] - The file path or URL of the JSON schema
|
|
172
|
-
* @param [schema] - A JSON schema object. This object will be used instead of reading from `path`.
|
|
173
|
-
* @param [options] - Options that determine how the schema is parsed, resolved, and dereferenced
|
|
174
|
-
* @param [callback] - An error-first callback. The second parameter is the dereferenced JSON schema object
|
|
175
|
-
* @returns - The returned promise resolves with the dereferenced JSON schema object.
|
|
176
|
-
*/
|
|
129
|
+
static dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(schema: S | string): Promise<S>;
|
|
130
|
+
static dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(schema: S | string, callback: SchemaCallback<S>): Promise<void>;
|
|
131
|
+
static dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(schema: S | string, options: O): Promise<S>;
|
|
132
|
+
static dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(schema: S | string, options: O, callback: SchemaCallback<S>): Promise<void>;
|
|
133
|
+
static dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(baseUrl: string, schema: S | string, options: O): Promise<S>;
|
|
134
|
+
static dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(baseUrl: string, schema: S | string, options: O, callback: SchemaCallback<S>): Promise<void>;
|
|
177
135
|
/**
|
|
178
136
|
* 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.
|
|
179
137
|
*
|
|
@@ -181,20 +139,21 @@ export declare class $RefParser {
|
|
|
181
139
|
*
|
|
182
140
|
* See https://apitools.dev/json-schema-ref-parser/docs/ref-parser.html#dereferenceschema-options-callback
|
|
183
141
|
*
|
|
142
|
+
* @param baseUrl
|
|
184
143
|
* @param schema A JSON Schema object, or the file path or URL of a JSON Schema file. See the `parse` method for more info.
|
|
185
144
|
* @param options (optional)
|
|
186
145
|
* @param callback (optional) A callback that will receive the dereferenced schema object
|
|
187
146
|
*/
|
|
188
|
-
dereference(baseUrl: string, schema:
|
|
189
|
-
dereference(schema:
|
|
190
|
-
dereference(schema:
|
|
191
|
-
dereference(baseUrl: string, schema:
|
|
192
|
-
dereference(schema:
|
|
193
|
-
dereference(schema:
|
|
147
|
+
dereference(baseUrl: string, schema: S | string, options: O, callback: SchemaCallback<S>): Promise<void>;
|
|
148
|
+
dereference(schema: S | string, options: O, callback: SchemaCallback<S>): Promise<void>;
|
|
149
|
+
dereference(schema: S | string, callback: SchemaCallback<S>): Promise<void>;
|
|
150
|
+
dereference(baseUrl: string, schema: S | string, options: O): Promise<S>;
|
|
151
|
+
dereference(schema: S | string, options: O): Promise<S>;
|
|
152
|
+
dereference(schema: S | string): Promise<S>;
|
|
194
153
|
}
|
|
195
154
|
export default $RefParser;
|
|
196
155
|
export declare const parse: typeof $RefParser.parse;
|
|
197
156
|
export declare const resolve: typeof $RefParser.resolve;
|
|
198
157
|
export declare const bundle: typeof $RefParser.bundle;
|
|
199
158
|
export declare const dereference: typeof $RefParser.dereference;
|
|
200
|
-
export { UnmatchedResolverError, JSONParserError, JSONSchema, InvalidPointerError, MissingPointerError, ResolverError, ParserError, UnmatchedParserError, ParserOptions, $RefsCallback, isHandledError, JSONParserErrorGroup, SchemaCallback, };
|
|
159
|
+
export { UnmatchedResolverError, JSONParserError, JSONSchema, InvalidPointerError, MissingPointerError, ResolverError, ParserError, UnmatchedParserError, ParserOptions, $RefsCallback, isHandledError, JSONParserErrorGroup, SchemaCallback, FileInfo, Plugin, ResolverOptions, HTTPResolverOptions, };
|
package/dist/lib/index.js
CHANGED
|
@@ -139,19 +139,6 @@ class $RefParser {
|
|
|
139
139
|
const parser = new $RefParser();
|
|
140
140
|
return parser.parse.apply(parser, arguments);
|
|
141
141
|
}
|
|
142
|
-
/**
|
|
143
|
-
* Parses the given JSON schema and resolves any JSON references, including references in
|
|
144
|
-
* externally-referenced files.
|
|
145
|
-
*
|
|
146
|
-
* @param [path] - The file path or URL of the JSON schema
|
|
147
|
-
* @param [schema] - A JSON schema object. This object will be used instead of reading from `path`.
|
|
148
|
-
* @param [options] - Options that determine how the schema is parsed and resolved
|
|
149
|
-
* @param [callback]
|
|
150
|
-
* - An error-first callback. The second parameter is a {@link $Refs} object containing the resolved JSON references
|
|
151
|
-
*
|
|
152
|
-
* @returns
|
|
153
|
-
* The returned promise resolves with a {@link $Refs} object containing the resolved JSON references
|
|
154
|
-
*/
|
|
155
142
|
async resolve() {
|
|
156
143
|
const args = (0, normalize_args_js_1.default)(arguments);
|
|
157
144
|
try {
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
+
import type { Options, ParserOptions } from "./options.js";
|
|
1
2
|
import type { JSONSchema, SchemaCallback } from "./types";
|
|
2
|
-
|
|
3
|
-
export default normalizeArgs;
|
|
4
|
-
export interface NormalizedArguments {
|
|
3
|
+
export interface NormalizedArguments<S, O> {
|
|
5
4
|
path: string;
|
|
6
|
-
schema:
|
|
7
|
-
options:
|
|
8
|
-
callback: SchemaCallback
|
|
5
|
+
schema: S;
|
|
6
|
+
options: O & Options;
|
|
7
|
+
callback: SchemaCallback<S>;
|
|
9
8
|
}
|
|
10
9
|
/**
|
|
11
10
|
* Normalizes the given arguments, accounting for optional args.
|
|
12
11
|
*/
|
|
13
|
-
declare function normalizeArgs(_args: Partial<IArguments>): NormalizedArguments
|
|
12
|
+
export declare function normalizeArgs<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(_args: Partial<IArguments>): NormalizedArguments<S, O>;
|
|
13
|
+
export default normalizeArgs;
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizeArgs = void 0;
|
|
3
4
|
const options_js_1 = require("./options.js");
|
|
4
|
-
exports.default = normalizeArgs;
|
|
5
5
|
/**
|
|
6
6
|
* Normalizes the given arguments, accounting for optional args.
|
|
7
7
|
*/
|
|
8
8
|
function normalizeArgs(_args) {
|
|
9
|
-
let path
|
|
9
|
+
let path;
|
|
10
|
+
let schema;
|
|
11
|
+
let options;
|
|
12
|
+
let callback;
|
|
10
13
|
const args = Array.prototype.slice.call(_args);
|
|
11
14
|
if (typeof args[args.length - 1] === "function") {
|
|
12
15
|
// The last parameter is a callback function
|
|
@@ -49,3 +52,5 @@ function normalizeArgs(_args) {
|
|
|
49
52
|
callback,
|
|
50
53
|
};
|
|
51
54
|
}
|
|
55
|
+
exports.normalizeArgs = normalizeArgs;
|
|
56
|
+
exports.default = normalizeArgs;
|
package/dist/lib/options.d.ts
CHANGED
|
@@ -1,14 +1,45 @@
|
|
|
1
|
-
import type { HTTPResolverOptions, JSONSchemaObject, Plugin, ResolverOptions } from "./types/index.js";
|
|
1
|
+
import type { HTTPResolverOptions, JSONSchema, JSONSchemaObject, Plugin, ResolverOptions } from "./types/index.js";
|
|
2
2
|
export type DeepPartial<T> = T extends object ? {
|
|
3
3
|
[P in keyof T]?: DeepPartial<T[P]>;
|
|
4
4
|
} : T;
|
|
5
|
+
export interface DereferenceOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Determines whether circular `$ref` pointers are handled.
|
|
8
|
+
*
|
|
9
|
+
* If set to `false`, then a `ReferenceError` will be thrown if the schema contains any circular references.
|
|
10
|
+
*
|
|
11
|
+
* 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`.
|
|
12
|
+
*/
|
|
13
|
+
circular?: boolean | "ignore";
|
|
14
|
+
/**
|
|
15
|
+
* A function, called for each path, which can return true to stop this path and all
|
|
16
|
+
* subpaths from being dereferenced further. This is useful in schemas where some
|
|
17
|
+
* subpaths contain literal $ref keys that should not be dereferenced.
|
|
18
|
+
*/
|
|
19
|
+
excludedPathMatcher?(path: string): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Callback invoked during dereferencing.
|
|
22
|
+
*
|
|
23
|
+
* @argument {string} path - The path being dereferenced (ie. the `$ref` string)
|
|
24
|
+
* @argument {JSONSchemaObject} value - The JSON-Schema that the `$ref` resolved to
|
|
25
|
+
* @argument {JSONSchemaObject} parent - The parent of the dereferenced object
|
|
26
|
+
* @argument {string} parentPropName - The prop name of the parent object whose value was dereferenced
|
|
27
|
+
*/
|
|
28
|
+
onDereference?(path: string, value: JSONSchemaObject, parent?: JSONSchemaObject, parentPropName?: string): void;
|
|
29
|
+
/**
|
|
30
|
+
* Whether a reference should resolve relative to its directory/path, or from the cwd
|
|
31
|
+
*
|
|
32
|
+
* Default: `relative`
|
|
33
|
+
*/
|
|
34
|
+
externalReferenceResolution?: "relative" | "root";
|
|
35
|
+
}
|
|
5
36
|
/**
|
|
6
37
|
* Options that determine how JSON schemas are parsed, resolved, and dereferenced.
|
|
7
38
|
*
|
|
8
39
|
* @param [options] - Overridden options
|
|
9
40
|
* @class
|
|
10
41
|
*/
|
|
11
|
-
export interface $RefParserOptions {
|
|
42
|
+
export interface $RefParserOptions<S> {
|
|
12
43
|
/**
|
|
13
44
|
* The `parse` options determine how different types of files will be parsed.
|
|
14
45
|
*
|
|
@@ -33,10 +64,10 @@ export interface $RefParserOptions {
|
|
|
33
64
|
* Determines whether external $ref pointers will be resolved. If this option is disabled, then external `$ref` pointers will simply be ignored.
|
|
34
65
|
*/
|
|
35
66
|
external?: boolean;
|
|
36
|
-
file?: Partial<ResolverOptions
|
|
37
|
-
http?: HTTPResolverOptions | boolean;
|
|
67
|
+
file?: Partial<ResolverOptions<S>> | boolean;
|
|
68
|
+
http?: HTTPResolverOptions<S> | boolean;
|
|
38
69
|
} & {
|
|
39
|
-
[key: string]: Partial<ResolverOptions
|
|
70
|
+
[key: string]: Partial<ResolverOptions<S>> | HTTPResolverOptions<S> | boolean | undefined;
|
|
40
71
|
};
|
|
41
72
|
/**
|
|
42
73
|
* By default, JSON Schema $Ref Parser throws the first error it encounters. Setting `continueOnError` to `true`
|
|
@@ -47,46 +78,16 @@ export interface $RefParserOptions {
|
|
|
47
78
|
/**
|
|
48
79
|
* The `dereference` options control how JSON Schema `$Ref` Parser will dereference `$ref` pointers within the JSON schema.
|
|
49
80
|
*/
|
|
50
|
-
dereference:
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
*/
|
|
58
|
-
circular?: boolean | "ignore";
|
|
59
|
-
/**
|
|
60
|
-
* A function, called for each path, which can return true to stop this path and all
|
|
61
|
-
* subpaths from being dereferenced further. This is useful in schemas where some
|
|
62
|
-
* subpaths contain literal $ref keys that should not be dereferenced.
|
|
63
|
-
*/
|
|
64
|
-
excludedPathMatcher?(path: string): boolean;
|
|
65
|
-
/**
|
|
66
|
-
* Callback invoked during dereferencing.
|
|
67
|
-
*
|
|
68
|
-
* @argument {string} path - The path being dereferenced (ie. the `$ref` string)
|
|
69
|
-
* @argument {JSONSchemaObject} value - The JSON-Schema that the `$ref` resolved to
|
|
70
|
-
* @argument {JSONSchemaObject} parent - The parent of the dereferenced object
|
|
71
|
-
* @argument {string} parentPropName - The prop name of the parent object whose value was dereferenced
|
|
72
|
-
*/
|
|
73
|
-
onDereference?(path: string, value: JSONSchemaObject, parent?: JSONSchemaObject, parentPropName?: string): void;
|
|
74
|
-
/**
|
|
75
|
-
* Whether a reference should resolve relative to its directory/path, or from the cwd
|
|
76
|
-
*
|
|
77
|
-
* Default: `relative`
|
|
78
|
-
*/
|
|
79
|
-
externalReferenceResolution?: "relative" | "root";
|
|
80
|
-
/**
|
|
81
|
-
* Whether to clone the schema before dereferencing it.
|
|
82
|
-
* This is useful when you want to dereference the same schema multiple times, but you don't want to modify the original schema.
|
|
83
|
-
* Default: `true` due to mutating the input being the default behavior historically
|
|
84
|
-
*/
|
|
85
|
-
mutateInputSchema?: boolean;
|
|
86
|
-
};
|
|
81
|
+
dereference: DereferenceOptions;
|
|
82
|
+
/**
|
|
83
|
+
* Whether to clone the schema before dereferencing it.
|
|
84
|
+
* This is useful when you want to dereference the same schema multiple times, but you don't want to modify the original schema.
|
|
85
|
+
* Default: `true` due to mutating the input being the default behavior historically
|
|
86
|
+
*/
|
|
87
|
+
mutateInputSchema?: boolean;
|
|
87
88
|
}
|
|
88
|
-
export declare const getJsonSchemaRefParserDefaultOptions: () => $RefParserOptions
|
|
89
|
-
export declare const getNewOptions: (options:
|
|
90
|
-
export type Options = $RefParserOptions
|
|
91
|
-
export type ParserOptions = DeepPartial<$RefParserOptions
|
|
89
|
+
export declare const getJsonSchemaRefParserDefaultOptions: () => $RefParserOptions<JSONSchema>;
|
|
90
|
+
export declare const getNewOptions: <S, O>(options: O | undefined) => O & $RefParserOptions<S>;
|
|
91
|
+
export type Options = $RefParserOptions<JSONSchema>;
|
|
92
|
+
export type ParserOptions = DeepPartial<$RefParserOptions<JSONSchema>>;
|
|
92
93
|
export default $RefParserOptions;
|
package/dist/lib/parse.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import type $Refs from "./refs.js";
|
|
3
3
|
import type { Options } from "./options.js";
|
|
4
|
-
|
|
4
|
+
import type { JSONSchema } from "./types/index.js";
|
|
5
5
|
/**
|
|
6
6
|
* Reads and parses the specified file path or URL.
|
|
7
7
|
*/
|
|
8
|
-
declare function parse(path: string, $refs: $Refs
|
|
8
|
+
declare function parse<S extends JSONSchema = JSONSchema, O extends Options = Options>(path: string, $refs: $Refs<S>, options: O): Promise<string | Buffer | S | undefined>;
|
|
9
|
+
export default parse;
|
package/dist/lib/parse.js
CHANGED
|
@@ -27,7 +27,6 @@ const ono_1 = require("@jsdevtools/ono");
|
|
|
27
27
|
const url = __importStar(require("./util/url.js"));
|
|
28
28
|
const plugins = __importStar(require("./util/plugins.js"));
|
|
29
29
|
const errors_js_1 = require("./util/errors.js");
|
|
30
|
-
exports.default = parse;
|
|
31
30
|
/**
|
|
32
31
|
* Reads and parses the specified file path or URL.
|
|
33
32
|
*/
|
|
@@ -72,7 +71,7 @@ async function parse(path, $refs, options) {
|
|
|
72
71
|
* @param file.url - The full URL of the referenced file
|
|
73
72
|
* @param file.extension - The lowercased file extension (e.g. ".txt", ".html", etc.)
|
|
74
73
|
* @param options
|
|
75
|
-
*
|
|
74
|
+
* @param $refs
|
|
76
75
|
* @returns
|
|
77
76
|
* The promise resolves with the raw file contents and the resolver that was used.
|
|
78
77
|
*/
|
|
@@ -113,6 +112,7 @@ async function readFile(file, options, $refs) {
|
|
|
113
112
|
* @param file.extension - The lowercased file extension (e.g. ".txt", ".html", etc.)
|
|
114
113
|
* @param file.data - The file contents. This will be whatever data type was returned by the resolver
|
|
115
114
|
* @param options
|
|
115
|
+
* @param $refs
|
|
116
116
|
*
|
|
117
117
|
* @returns
|
|
118
118
|
* The promise resolves with the parsed file contents and the parser that was used.
|
|
@@ -166,3 +166,4 @@ function isEmpty(value) {
|
|
|
166
166
|
(typeof value === "string" && value.trim().length === 0) ||
|
|
167
167
|
(Buffer.isBuffer(value) && value.length === 0));
|
|
168
168
|
}
|
|
169
|
+
exports.default = parse;
|
package/dist/lib/pointer.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type $RefParserOptions from "./options.js";
|
|
2
2
|
import $Ref from "./ref.js";
|
|
3
|
+
import type { JSONSchema } from "./types";
|
|
3
4
|
/**
|
|
4
5
|
* This class represents a single JSON pointer and its resolved value.
|
|
5
6
|
*
|
|
@@ -8,11 +9,11 @@ import $Ref from "./ref.js";
|
|
|
8
9
|
* @param [friendlyPath] - The original user-specified path (used for error messages)
|
|
9
10
|
* @class
|
|
10
11
|
*/
|
|
11
|
-
declare class Pointer {
|
|
12
|
+
declare class Pointer<S = JSONSchema> {
|
|
12
13
|
/**
|
|
13
14
|
* The {@link $Ref} object that contains this {@link Pointer} object.
|
|
14
15
|
*/
|
|
15
|
-
$ref: $Ref
|
|
16
|
+
$ref: $Ref<S>;
|
|
16
17
|
/**
|
|
17
18
|
* The file path or URL, containing the JSON pointer in the hash.
|
|
18
19
|
* This path is relative to the path of the main JSON schema file.
|
|
@@ -36,7 +37,7 @@ declare class Pointer {
|
|
|
36
37
|
* Resolving a single pointer may require resolving multiple $Refs.
|
|
37
38
|
*/
|
|
38
39
|
indirections: number;
|
|
39
|
-
constructor($ref: $Ref
|
|
40
|
+
constructor($ref: $Ref<S>, path: string, friendlyPath?: string);
|
|
40
41
|
/**
|
|
41
42
|
* Resolves the value of a nested property within the given object.
|
|
42
43
|
*
|
|
@@ -50,7 +51,7 @@ declare class Pointer {
|
|
|
50
51
|
* the {@link Pointer#$ref} and {@link Pointer#path} will reflect the resolution path
|
|
51
52
|
* of the resolved value.
|
|
52
53
|
*/
|
|
53
|
-
resolve(obj: any, options?: $RefParserOptions
|
|
54
|
+
resolve(obj: any, options?: $RefParserOptions<S>, pathFromRoot?: string): this;
|
|
54
55
|
/**
|
|
55
56
|
* Sets the value of a nested property within the given object.
|
|
56
57
|
*
|
|
@@ -61,7 +62,7 @@ declare class Pointer {
|
|
|
61
62
|
* @returns
|
|
62
63
|
* Returns the modified object, or an entirely new object if the entire object is overwritten.
|
|
63
64
|
*/
|
|
64
|
-
set(obj: any, value: any, options?: $RefParserOptions): any;
|
|
65
|
+
set(obj: any, value: any, options?: $RefParserOptions<S>): any;
|
|
65
66
|
/**
|
|
66
67
|
* Parses a JSON pointer (or a path containing a JSON pointer in the hash)
|
|
67
68
|
* and returns an array of the pointer's tokens.
|