@apidevtools/json-schema-ref-parser 11.4.0 → 11.4.2
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/index.d.ts +3 -51
- package/dist/lib/index.js +3 -14
- package/dist/lib/normalize-args.d.ts +10 -7
- package/dist/lib/normalize-args.js +5 -3
- package/dist/lib/options.d.ts +4 -3
- package/dist/lib/options.js +4 -3
- package/dist/lib/types/index.d.ts +1 -1
- package/lib/index.ts +17 -65
- package/lib/normalize-args.ts +15 -5
- package/lib/options.ts +5 -5
- package/lib/types/index.ts +1 -1
- package/package.json +1 -1
package/dist/lib/index.d.ts
CHANGED
|
@@ -1,15 +1,8 @@
|
|
|
1
1
|
import $Refs from "./refs.js";
|
|
2
|
-
import { JSONParserError, InvalidPointerError, MissingPointerError, ResolverError, ParserError, UnmatchedParserError, UnmatchedResolverError } from "./util/errors.js";
|
|
2
|
+
import { JSONParserError, InvalidPointerError, MissingPointerError, ResolverError, ParserError, UnmatchedParserError, UnmatchedResolverError, isHandledError, JSONParserErrorGroup } from "./util/errors.js";
|
|
3
3
|
import type { ParserOptions } from "./options.js";
|
|
4
4
|
import type { $RefsCallback, JSONSchema, SchemaCallback } from "./types/index.js";
|
|
5
|
-
export
|
|
6
|
-
export { InvalidPointerError };
|
|
7
|
-
export { MissingPointerError };
|
|
8
|
-
export { ResolverError };
|
|
9
|
-
export { ParserError };
|
|
10
|
-
export { UnmatchedParserError };
|
|
11
|
-
export { UnmatchedResolverError };
|
|
12
|
-
type RefParserSchema = string | JSONSchema;
|
|
5
|
+
export type RefParserSchema = string | JSONSchema;
|
|
13
6
|
/**
|
|
14
7
|
* This class parses a JSON schema, builds a map of its JSON references and their resolved values,
|
|
15
8
|
* and provides methods for traversing, manipulating, and dereferencing those references.
|
|
@@ -88,17 +81,6 @@ export declare class $RefParser {
|
|
|
88
81
|
static resolve(schema: RefParserSchema, options: ParserOptions, callback: $RefsCallback): Promise<void>;
|
|
89
82
|
static resolve(baseUrl: string, schema: RefParserSchema, options: ParserOptions): Promise<$Refs>;
|
|
90
83
|
static resolve(baseUrl: string, schema: RefParserSchema, options: ParserOptions, callback: $RefsCallback): Promise<void>;
|
|
91
|
-
/**
|
|
92
|
-
* Parses the given JSON schema, resolves any JSON references, and bundles all external references
|
|
93
|
-
* into the main JSON schema. This produces a JSON schema that only has *internal* references,
|
|
94
|
-
* not any *external* references.
|
|
95
|
-
*
|
|
96
|
-
* @param [path] - The file path or URL of the JSON schema
|
|
97
|
-
* @param [schema] - A JSON schema object. This object will be used instead of reading from `path`.
|
|
98
|
-
* @param [options] - Options that determine how the schema is parsed, resolved, and dereferenced
|
|
99
|
-
* @param [callback] - An error-first callback. The second parameter is the bundled JSON schema object
|
|
100
|
-
* @returns - The returned promise resolves with the bundled JSON schema object.
|
|
101
|
-
*/
|
|
102
84
|
/**
|
|
103
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.
|
|
104
86
|
*
|
|
@@ -116,17 +98,6 @@ export declare class $RefParser {
|
|
|
116
98
|
static bundle(schema: RefParserSchema, options: ParserOptions, callback: SchemaCallback): Promise<void>;
|
|
117
99
|
static bundle(baseUrl: string, schema: RefParserSchema, options: ParserOptions): Promise<JSONSchema>;
|
|
118
100
|
static bundle(baseUrl: string, schema: RefParserSchema, options: ParserOptions, callback: SchemaCallback): Promise<JSONSchema>;
|
|
119
|
-
/**
|
|
120
|
-
* Parses the given JSON schema, resolves any JSON references, and bundles all external references
|
|
121
|
-
* into the main JSON schema. This produces a JSON schema that only has *internal* references,
|
|
122
|
-
* not any *external* references.
|
|
123
|
-
*
|
|
124
|
-
* @param [path] - The file path or URL of the JSON schema
|
|
125
|
-
* @param [schema] - A JSON schema object. This object will be used instead of reading from `path`.
|
|
126
|
-
* @param [options] - Options that determine how the schema is parsed, resolved, and dereferenced
|
|
127
|
-
* @param [callback] - An error-first callback. The second parameter is the bundled JSON schema object
|
|
128
|
-
* @returns - The returned promise resolves with the bundled JSON schema object.
|
|
129
|
-
*/
|
|
130
101
|
/**
|
|
131
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.
|
|
132
103
|
*
|
|
@@ -144,16 +115,6 @@ export declare class $RefParser {
|
|
|
144
115
|
bundle(schema: RefParserSchema, options: ParserOptions, callback: SchemaCallback): Promise<void>;
|
|
145
116
|
bundle(baseUrl: string, schema: RefParserSchema, options: ParserOptions): Promise<JSONSchema>;
|
|
146
117
|
bundle(baseUrl: string, schema: RefParserSchema, options: ParserOptions, callback: SchemaCallback): Promise<void>;
|
|
147
|
-
/**
|
|
148
|
-
* Parses the given JSON schema, resolves any JSON references, and dereferences the JSON schema.
|
|
149
|
-
* That is, all JSON references are replaced with their resolved values.
|
|
150
|
-
*
|
|
151
|
-
* @param [path] - The file path or URL of the JSON schema
|
|
152
|
-
* @param [schema] - A JSON schema object. This object will be used instead of reading from `path`.
|
|
153
|
-
* @param [options] - Options that determine how the schema is parsed, resolved, and dereferenced
|
|
154
|
-
* @param [callback] - An error-first callback. The second parameter is the dereferenced JSON schema object
|
|
155
|
-
* @returns - The returned promise resolves with the dereferenced JSON schema object.
|
|
156
|
-
*/
|
|
157
118
|
/**
|
|
158
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.
|
|
159
120
|
*
|
|
@@ -171,16 +132,6 @@ export declare class $RefParser {
|
|
|
171
132
|
static dereference(schema: RefParserSchema, options: ParserOptions, callback: SchemaCallback): Promise<void>;
|
|
172
133
|
static dereference(baseUrl: string, schema: RefParserSchema, options: ParserOptions): Promise<JSONSchema>;
|
|
173
134
|
static dereference(baseUrl: string, schema: RefParserSchema, options: ParserOptions, callback: SchemaCallback): Promise<void>;
|
|
174
|
-
/**
|
|
175
|
-
* Parses the given JSON schema, resolves any JSON references, and dereferences the JSON schema.
|
|
176
|
-
* That is, all JSON references are replaced with their resolved values.
|
|
177
|
-
*
|
|
178
|
-
* @param [path] - The file path or URL of the JSON schema
|
|
179
|
-
* @param [schema] - A JSON schema object. This object will be used instead of reading from `path`.
|
|
180
|
-
* @param [options] - Options that determine how the schema is parsed, resolved, and dereferenced
|
|
181
|
-
* @param [callback] - An error-first callback. The second parameter is the dereferenced JSON schema object
|
|
182
|
-
* @returns - The returned promise resolves with the dereferenced JSON schema object.
|
|
183
|
-
*/
|
|
184
135
|
/**
|
|
185
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.
|
|
186
137
|
*
|
|
@@ -204,3 +155,4 @@ export declare const parse: typeof $RefParser.parse;
|
|
|
204
155
|
export declare const resolve: typeof $RefParser.resolve;
|
|
205
156
|
export declare const bundle: typeof $RefParser.bundle;
|
|
206
157
|
export declare const dereference: typeof $RefParser.dereference;
|
|
158
|
+
export { UnmatchedResolverError, JSONParserError, JSONSchema, InvalidPointerError, MissingPointerError, ResolverError, ParserError, UnmatchedParserError, ParserOptions, $RefsCallback, isHandledError, JSONParserErrorGroup, SchemaCallback, };
|
package/dist/lib/index.js
CHANGED
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.
|
|
29
|
+
exports.JSONParserErrorGroup = exports.isHandledError = exports.UnmatchedParserError = exports.ParserError = exports.ResolverError = exports.MissingPointerError = exports.InvalidPointerError = exports.JSONParserError = exports.UnmatchedResolverError = exports.dereference = exports.bundle = exports.resolve = exports.parse = exports.$RefParser = void 0;
|
|
30
30
|
const refs_js_1 = __importDefault(require("./refs.js"));
|
|
31
31
|
const parse_js_1 = __importDefault(require("./parse.js"));
|
|
32
32
|
const normalize_args_js_1 = __importDefault(require("./normalize-args.js"));
|
|
@@ -42,6 +42,8 @@ Object.defineProperty(exports, "ResolverError", { enumerable: true, get: functio
|
|
|
42
42
|
Object.defineProperty(exports, "ParserError", { enumerable: true, get: function () { return errors_js_1.ParserError; } });
|
|
43
43
|
Object.defineProperty(exports, "UnmatchedParserError", { enumerable: true, get: function () { return errors_js_1.UnmatchedParserError; } });
|
|
44
44
|
Object.defineProperty(exports, "UnmatchedResolverError", { enumerable: true, get: function () { return errors_js_1.UnmatchedResolverError; } });
|
|
45
|
+
Object.defineProperty(exports, "isHandledError", { enumerable: true, get: function () { return errors_js_1.isHandledError; } });
|
|
46
|
+
Object.defineProperty(exports, "JSONParserErrorGroup", { enumerable: true, get: function () { return errors_js_1.JSONParserErrorGroup; } });
|
|
45
47
|
const ono_1 = require("@jsdevtools/ono");
|
|
46
48
|
const maybe_js_1 = __importDefault(require("./util/maybe.js"));
|
|
47
49
|
/**
|
|
@@ -137,19 +139,6 @@ class $RefParser {
|
|
|
137
139
|
const parser = new $RefParser();
|
|
138
140
|
return parser.parse.apply(parser, arguments);
|
|
139
141
|
}
|
|
140
|
-
/**
|
|
141
|
-
* Parses the given JSON schema and resolves any JSON references, including references in
|
|
142
|
-
* externally-referenced files.
|
|
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 and resolved
|
|
147
|
-
* @param [callback]
|
|
148
|
-
* - An error-first callback. The second parameter is a {@link $Refs} object containing the resolved JSON references
|
|
149
|
-
*
|
|
150
|
-
* @returns
|
|
151
|
-
* The returned promise resolves with a {@link $Refs} object containing the resolved JSON references
|
|
152
|
-
*/
|
|
153
142
|
async resolve() {
|
|
154
143
|
const args = (0, normalize_args_js_1.default)(arguments);
|
|
155
144
|
try {
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
import type { JSONSchema, SchemaCallback } from "./types";
|
|
2
|
+
import type $RefParserOptions from "./options";
|
|
3
|
+
export interface NormalizedArguments<T = $RefParserOptions> {
|
|
4
|
+
path: string;
|
|
5
|
+
schema: JSONSchema;
|
|
6
|
+
options: T;
|
|
7
|
+
callback: SchemaCallback;
|
|
8
|
+
}
|
|
2
9
|
/**
|
|
3
10
|
* Normalizes the given arguments, accounting for optional args.
|
|
4
11
|
*/
|
|
5
|
-
declare function normalizeArgs(_args: Partial<IArguments>):
|
|
6
|
-
|
|
7
|
-
schema: any;
|
|
8
|
-
options: any;
|
|
9
|
-
callback: any;
|
|
10
|
-
};
|
|
12
|
+
export declare function normalizeArgs<T = $RefParserOptions>(_args: Partial<IArguments>): NormalizedArguments<T>;
|
|
13
|
+
export default normalizeArgs;
|
|
@@ -1,7 +1,7 @@
|
|
|
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
|
*/
|
|
@@ -36,9 +36,9 @@ function normalizeArgs(_args) {
|
|
|
36
36
|
options = (0, options_js_1.getNewOptions)(options);
|
|
37
37
|
}
|
|
38
38
|
catch (e) {
|
|
39
|
-
console.
|
|
39
|
+
console.error(`JSON Schema Ref Parser: Error normalizing options: ${e}`);
|
|
40
40
|
}
|
|
41
|
-
if (!options.mutateInputSchema) {
|
|
41
|
+
if (!options.mutateInputSchema && typeof schema === "object") {
|
|
42
42
|
// Make a deep clone of the schema, so that we don't alter the original object
|
|
43
43
|
schema = JSON.parse(JSON.stringify(schema));
|
|
44
44
|
}
|
|
@@ -49,3 +49,5 @@ function normalizeArgs(_args) {
|
|
|
49
49
|
callback,
|
|
50
50
|
};
|
|
51
51
|
}
|
|
52
|
+
exports.normalizeArgs = normalizeArgs;
|
|
53
|
+
exports.default = normalizeArgs;
|
package/dist/lib/options.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { HTTPResolverOptions, JSONSchemaObject, Plugin, ResolverOptions } from "./types/index.js";
|
|
2
|
-
type DeepPartial<T> = T extends object ? {
|
|
2
|
+
export type DeepPartial<T> = T extends object ? {
|
|
3
3
|
[P in keyof T]?: DeepPartial<T[P]>;
|
|
4
4
|
} : T;
|
|
5
5
|
/**
|
|
@@ -8,7 +8,7 @@ type DeepPartial<T> = T extends object ? {
|
|
|
8
8
|
* @param [options] - Overridden options
|
|
9
9
|
* @class
|
|
10
10
|
*/
|
|
11
|
-
interface $RefParserOptions {
|
|
11
|
+
export interface $RefParserOptions {
|
|
12
12
|
/**
|
|
13
13
|
* The `parse` options determine how different types of files will be parsed.
|
|
14
14
|
*
|
|
@@ -85,7 +85,8 @@ interface $RefParserOptions {
|
|
|
85
85
|
mutateInputSchema?: boolean;
|
|
86
86
|
};
|
|
87
87
|
}
|
|
88
|
-
export declare const
|
|
88
|
+
export declare const getJsonSchemaRefParserDefaultOptions: () => $RefParserOptions;
|
|
89
|
+
export declare const getNewOptions: (options: DeepPartial<$RefParserOptions> | undefined) => $RefParserOptions;
|
|
89
90
|
export type Options = $RefParserOptions;
|
|
90
91
|
export type ParserOptions = DeepPartial<$RefParserOptions>;
|
|
91
92
|
export default $RefParserOptions;
|
package/dist/lib/options.js
CHANGED
|
@@ -3,14 +3,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getNewOptions = void 0;
|
|
6
|
+
exports.getNewOptions = exports.getJsonSchemaRefParserDefaultOptions = void 0;
|
|
7
7
|
const json_js_1 = __importDefault(require("./parsers/json.js"));
|
|
8
8
|
const yaml_js_1 = __importDefault(require("./parsers/yaml.js"));
|
|
9
9
|
const text_js_1 = __importDefault(require("./parsers/text.js"));
|
|
10
10
|
const binary_js_1 = __importDefault(require("./parsers/binary.js"));
|
|
11
11
|
const file_js_1 = __importDefault(require("./resolvers/file.js"));
|
|
12
12
|
const http_js_1 = __importDefault(require("./resolvers/http.js"));
|
|
13
|
-
const
|
|
13
|
+
const getJsonSchemaRefParserDefaultOptions = () => {
|
|
14
14
|
const defaults = {
|
|
15
15
|
/**
|
|
16
16
|
* Determines how different types of files will be parsed.
|
|
@@ -74,8 +74,9 @@ const getDefaults = () => {
|
|
|
74
74
|
};
|
|
75
75
|
return defaults;
|
|
76
76
|
};
|
|
77
|
+
exports.getJsonSchemaRefParserDefaultOptions = getJsonSchemaRefParserDefaultOptions;
|
|
77
78
|
const getNewOptions = (options) => {
|
|
78
|
-
const newOptions =
|
|
79
|
+
const newOptions = (0, exports.getJsonSchemaRefParserDefaultOptions)();
|
|
79
80
|
if (options) {
|
|
80
81
|
merge(newOptions, options);
|
|
81
82
|
}
|
|
@@ -3,7 +3,7 @@ import type { JSONSchema4, JSONSchema4Object, JSONSchema6, JSONSchema6Object, JS
|
|
|
3
3
|
import type $Refs from "../refs.js";
|
|
4
4
|
export type JSONSchema = JSONSchema4 | JSONSchema6 | JSONSchema7;
|
|
5
5
|
export type JSONSchemaObject = JSONSchema4Object | JSONSchema6Object | JSONSchema7Object;
|
|
6
|
-
export type SchemaCallback = (err: Error | null, schema?: JSONSchema | object) => any;
|
|
6
|
+
export type SchemaCallback = (err: Error | null, schema?: JSONSchema | object | null) => any;
|
|
7
7
|
export type $RefsCallback = (err: Error | null, $refs?: $Refs) => any;
|
|
8
8
|
/**
|
|
9
9
|
* See https://apitools.dev/json-schema-ref-parser/docs/options.html
|
package/lib/index.ts
CHANGED
|
@@ -21,15 +21,7 @@ import maybe from "./util/maybe.js";
|
|
|
21
21
|
import type { ParserOptions } from "./options.js";
|
|
22
22
|
import type { $RefsCallback, JSONSchema, SchemaCallback } from "./types/index.js";
|
|
23
23
|
|
|
24
|
-
export
|
|
25
|
-
export { InvalidPointerError };
|
|
26
|
-
export { MissingPointerError };
|
|
27
|
-
export { ResolverError };
|
|
28
|
-
export { ParserError };
|
|
29
|
-
export { UnmatchedParserError };
|
|
30
|
-
export { UnmatchedResolverError };
|
|
31
|
-
|
|
32
|
-
type RefParserSchema = string | JSONSchema;
|
|
24
|
+
export type RefParserSchema = string | JSONSchema;
|
|
33
25
|
|
|
34
26
|
/**
|
|
35
27
|
* This class parses a JSON schema, builds a map of its JSON references and their resolved values,
|
|
@@ -76,7 +68,6 @@ export class $RefParser {
|
|
|
76
68
|
options: ParserOptions,
|
|
77
69
|
callback: SchemaCallback,
|
|
78
70
|
): Promise<void>;
|
|
79
|
-
|
|
80
71
|
async parse() {
|
|
81
72
|
const args = normalizeArgs(arguments as any);
|
|
82
73
|
let promise;
|
|
@@ -187,19 +178,6 @@ export class $RefParser {
|
|
|
187
178
|
options: ParserOptions,
|
|
188
179
|
callback: $RefsCallback,
|
|
189
180
|
): Promise<void>;
|
|
190
|
-
/**
|
|
191
|
-
* Parses the given JSON schema and resolves any JSON references, including references in
|
|
192
|
-
* externally-referenced files.
|
|
193
|
-
*
|
|
194
|
-
* @param [path] - The file path or URL of the JSON schema
|
|
195
|
-
* @param [schema] - A JSON schema object. This object will be used instead of reading from `path`.
|
|
196
|
-
* @param [options] - Options that determine how the schema is parsed and resolved
|
|
197
|
-
* @param [callback]
|
|
198
|
-
* - An error-first callback. The second parameter is a {@link $Refs} object containing the resolved JSON references
|
|
199
|
-
*
|
|
200
|
-
* @returns
|
|
201
|
-
* The returned promise resolves with a {@link $Refs} object containing the resolved JSON references
|
|
202
|
-
*/
|
|
203
181
|
async resolve() {
|
|
204
182
|
const args = normalizeArgs(arguments);
|
|
205
183
|
|
|
@@ -240,17 +218,6 @@ export class $RefParser {
|
|
|
240
218
|
return instance.resolve.apply(instance, arguments as any);
|
|
241
219
|
}
|
|
242
220
|
|
|
243
|
-
/**
|
|
244
|
-
* Parses the given JSON schema, resolves any JSON references, and bundles all external references
|
|
245
|
-
* into the main JSON schema. This produces a JSON schema that only has *internal* references,
|
|
246
|
-
* not any *external* references.
|
|
247
|
-
*
|
|
248
|
-
* @param [path] - The file path or URL of the JSON schema
|
|
249
|
-
* @param [schema] - A JSON schema object. This object will be used instead of reading from `path`.
|
|
250
|
-
* @param [options] - Options that determine how the schema is parsed, resolved, and dereferenced
|
|
251
|
-
* @param [callback] - An error-first callback. The second parameter is the bundled JSON schema object
|
|
252
|
-
* @returns - The returned promise resolves with the bundled JSON schema object.
|
|
253
|
-
*/
|
|
254
221
|
/**
|
|
255
222
|
* 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.
|
|
256
223
|
*
|
|
@@ -278,17 +245,6 @@ export class $RefParser {
|
|
|
278
245
|
return instance.bundle.apply(instance, arguments as any);
|
|
279
246
|
}
|
|
280
247
|
|
|
281
|
-
/**
|
|
282
|
-
* Parses the given JSON schema, resolves any JSON references, and bundles all external references
|
|
283
|
-
* into the main JSON schema. This produces a JSON schema that only has *internal* references,
|
|
284
|
-
* not any *external* references.
|
|
285
|
-
*
|
|
286
|
-
* @param [path] - The file path or URL of the JSON schema
|
|
287
|
-
* @param [schema] - A JSON schema object. This object will be used instead of reading from `path`.
|
|
288
|
-
* @param [options] - Options that determine how the schema is parsed, resolved, and dereferenced
|
|
289
|
-
* @param [callback] - An error-first callback. The second parameter is the bundled JSON schema object
|
|
290
|
-
* @returns - The returned promise resolves with the bundled JSON schema object.
|
|
291
|
-
*/
|
|
292
248
|
/**
|
|
293
249
|
* 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.
|
|
294
250
|
*
|
|
@@ -323,16 +279,6 @@ export class $RefParser {
|
|
|
323
279
|
}
|
|
324
280
|
}
|
|
325
281
|
|
|
326
|
-
/**
|
|
327
|
-
* Parses the given JSON schema, resolves any JSON references, and dereferences the JSON schema.
|
|
328
|
-
* That is, all JSON references are replaced with their resolved values.
|
|
329
|
-
*
|
|
330
|
-
* @param [path] - The file path or URL of the JSON schema
|
|
331
|
-
* @param [schema] - A JSON schema object. This object will be used instead of reading from `path`.
|
|
332
|
-
* @param [options] - Options that determine how the schema is parsed, resolved, and dereferenced
|
|
333
|
-
* @param [callback] - An error-first callback. The second parameter is the dereferenced JSON schema object
|
|
334
|
-
* @returns - The returned promise resolves with the dereferenced JSON schema object.
|
|
335
|
-
*/
|
|
336
282
|
/**
|
|
337
283
|
* 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.
|
|
338
284
|
*
|
|
@@ -360,16 +306,6 @@ export class $RefParser {
|
|
|
360
306
|
return instance.dereference.apply(instance, arguments as any);
|
|
361
307
|
}
|
|
362
308
|
|
|
363
|
-
/**
|
|
364
|
-
* Parses the given JSON schema, resolves any JSON references, and dereferences the JSON schema.
|
|
365
|
-
* That is, all JSON references are replaced with their resolved values.
|
|
366
|
-
*
|
|
367
|
-
* @param [path] - The file path or URL of the JSON schema
|
|
368
|
-
* @param [schema] - A JSON schema object. This object will be used instead of reading from `path`.
|
|
369
|
-
* @param [options] - Options that determine how the schema is parsed, resolved, and dereferenced
|
|
370
|
-
* @param [callback] - An error-first callback. The second parameter is the dereferenced JSON schema object
|
|
371
|
-
* @returns - The returned promise resolves with the dereferenced JSON schema object.
|
|
372
|
-
*/
|
|
373
309
|
/**
|
|
374
310
|
* 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.
|
|
375
311
|
*
|
|
@@ -418,3 +354,19 @@ export const parse = $RefParser.parse;
|
|
|
418
354
|
export const resolve = $RefParser.resolve;
|
|
419
355
|
export const bundle = $RefParser.bundle;
|
|
420
356
|
export const dereference = $RefParser.dereference;
|
|
357
|
+
|
|
358
|
+
export {
|
|
359
|
+
UnmatchedResolverError,
|
|
360
|
+
JSONParserError,
|
|
361
|
+
JSONSchema,
|
|
362
|
+
InvalidPointerError,
|
|
363
|
+
MissingPointerError,
|
|
364
|
+
ResolverError,
|
|
365
|
+
ParserError,
|
|
366
|
+
UnmatchedParserError,
|
|
367
|
+
ParserOptions,
|
|
368
|
+
$RefsCallback,
|
|
369
|
+
isHandledError,
|
|
370
|
+
JSONParserErrorGroup,
|
|
371
|
+
SchemaCallback,
|
|
372
|
+
};
|
package/lib/normalize-args.ts
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
import { getNewOptions } from "./options.js";
|
|
2
|
+
import type { JSONSchema, SchemaCallback } from "./types";
|
|
3
|
+
import type $RefParserOptions from "./options";
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
+
// I really dislike this function and the way it's written. It's not clear what it's doing, and it's way too flexible
|
|
6
|
+
// In the future, I'd like to deprecate the api and accept only named parameters in index.ts
|
|
7
|
+
export interface NormalizedArguments<T = $RefParserOptions> {
|
|
8
|
+
path: string;
|
|
9
|
+
schema: JSONSchema;
|
|
10
|
+
options: T;
|
|
11
|
+
callback: SchemaCallback;
|
|
12
|
+
}
|
|
5
13
|
/**
|
|
6
14
|
* Normalizes the given arguments, accounting for optional args.
|
|
7
15
|
*/
|
|
8
|
-
function normalizeArgs(_args: Partial<IArguments>) {
|
|
16
|
+
export function normalizeArgs<T = $RefParserOptions>(_args: Partial<IArguments>): NormalizedArguments<T> {
|
|
9
17
|
let path, schema, options, callback;
|
|
10
18
|
const args = Array.prototype.slice.call(_args) as any[];
|
|
11
19
|
|
|
@@ -36,10 +44,10 @@ function normalizeArgs(_args: Partial<IArguments>) {
|
|
|
36
44
|
try {
|
|
37
45
|
options = getNewOptions(options);
|
|
38
46
|
} catch (e) {
|
|
39
|
-
console.
|
|
47
|
+
console.error(`JSON Schema Ref Parser: Error normalizing options: ${e}`);
|
|
40
48
|
}
|
|
41
49
|
|
|
42
|
-
if (!options.mutateInputSchema) {
|
|
50
|
+
if (!options.mutateInputSchema && typeof schema === "object") {
|
|
43
51
|
// Make a deep clone of the schema, so that we don't alter the original object
|
|
44
52
|
schema = JSON.parse(JSON.stringify(schema));
|
|
45
53
|
}
|
|
@@ -51,3 +59,5 @@ function normalizeArgs(_args: Partial<IArguments>) {
|
|
|
51
59
|
callback,
|
|
52
60
|
};
|
|
53
61
|
}
|
|
62
|
+
|
|
63
|
+
export default normalizeArgs;
|
package/lib/options.ts
CHANGED
|
@@ -7,7 +7,7 @@ import httpResolver from "./resolvers/http.js";
|
|
|
7
7
|
|
|
8
8
|
import type { HTTPResolverOptions, JSONSchemaObject, Plugin, ResolverOptions } from "./types/index.js";
|
|
9
9
|
|
|
10
|
-
type DeepPartial<T> = T extends object
|
|
10
|
+
export type DeepPartial<T> = T extends object
|
|
11
11
|
? {
|
|
12
12
|
[P in keyof T]?: DeepPartial<T[P]>;
|
|
13
13
|
}
|
|
@@ -18,7 +18,7 @@ type DeepPartial<T> = T extends object
|
|
|
18
18
|
* @param [options] - Overridden options
|
|
19
19
|
* @class
|
|
20
20
|
*/
|
|
21
|
-
interface $RefParserOptions {
|
|
21
|
+
export interface $RefParserOptions {
|
|
22
22
|
/**
|
|
23
23
|
* The `parse` options determine how different types of files will be parsed.
|
|
24
24
|
*
|
|
@@ -101,7 +101,7 @@ interface $RefParserOptions {
|
|
|
101
101
|
};
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
-
const
|
|
104
|
+
export const getJsonSchemaRefParserDefaultOptions = () => {
|
|
105
105
|
const defaults = {
|
|
106
106
|
/**
|
|
107
107
|
* Determines how different types of files will be parsed.
|
|
@@ -172,8 +172,8 @@ const getDefaults = () => {
|
|
|
172
172
|
return defaults;
|
|
173
173
|
};
|
|
174
174
|
|
|
175
|
-
export const getNewOptions = (options: DeepPartial<$RefParserOptions>): $RefParserOptions => {
|
|
176
|
-
const newOptions =
|
|
175
|
+
export const getNewOptions = (options: DeepPartial<$RefParserOptions> | undefined): $RefParserOptions => {
|
|
176
|
+
const newOptions = getJsonSchemaRefParserDefaultOptions();
|
|
177
177
|
if (options) {
|
|
178
178
|
merge(newOptions, options);
|
|
179
179
|
}
|
package/lib/types/index.ts
CHANGED
|
@@ -10,7 +10,7 @@ import type $Refs from "../refs.js";
|
|
|
10
10
|
|
|
11
11
|
export type JSONSchema = JSONSchema4 | JSONSchema6 | JSONSchema7;
|
|
12
12
|
export type JSONSchemaObject = JSONSchema4Object | JSONSchema6Object | JSONSchema7Object;
|
|
13
|
-
export type SchemaCallback = (err: Error | null, schema?: JSONSchema | object) => any;
|
|
13
|
+
export type SchemaCallback = (err: Error | null, schema?: JSONSchema | object | null) => any;
|
|
14
14
|
export type $RefsCallback = (err: Error | null, $refs?: $Refs) => any;
|
|
15
15
|
|
|
16
16
|
/**
|