@apidevtools/json-schema-ref-parser 11.4.0 → 11.4.1
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 -9
- package/dist/lib/index.js +3 -1
- package/dist/lib/normalize-args.d.ts +9 -6
- package/dist/lib/normalize-args.js +2 -2
- 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 -10
- package/lib/normalize-args.ts +13 -3
- 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.
|
|
@@ -204,3 +197,4 @@ export declare const parse: typeof $RefParser.parse;
|
|
|
204
197
|
export declare const resolve: typeof $RefParser.resolve;
|
|
205
198
|
export declare const bundle: typeof $RefParser.bundle;
|
|
206
199
|
export declare const dereference: typeof $RefParser.dereference;
|
|
200
|
+
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
|
/**
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
+
import type { JSONSchema, SchemaCallback } from "./types";
|
|
2
|
+
import type $RefParserOptions from "./options";
|
|
1
3
|
export default normalizeArgs;
|
|
4
|
+
export interface NormalizedArguments {
|
|
5
|
+
path: string;
|
|
6
|
+
schema: JSONSchema;
|
|
7
|
+
options: $RefParserOptions;
|
|
8
|
+
callback: SchemaCallback;
|
|
9
|
+
}
|
|
2
10
|
/**
|
|
3
11
|
* Normalizes the given arguments, accounting for optional args.
|
|
4
12
|
*/
|
|
5
|
-
declare function normalizeArgs(_args: Partial<IArguments>):
|
|
6
|
-
path: string;
|
|
7
|
-
schema: any;
|
|
8
|
-
options: any;
|
|
9
|
-
callback: any;
|
|
10
|
-
};
|
|
13
|
+
declare function normalizeArgs(_args: Partial<IArguments>): NormalizedArguments;
|
|
@@ -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
|
}
|
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;
|
|
@@ -418,3 +409,19 @@ export const parse = $RefParser.parse;
|
|
|
418
409
|
export const resolve = $RefParser.resolve;
|
|
419
410
|
export const bundle = $RefParser.bundle;
|
|
420
411
|
export const dereference = $RefParser.dereference;
|
|
412
|
+
|
|
413
|
+
export {
|
|
414
|
+
UnmatchedResolverError,
|
|
415
|
+
JSONParserError,
|
|
416
|
+
JSONSchema,
|
|
417
|
+
InvalidPointerError,
|
|
418
|
+
MissingPointerError,
|
|
419
|
+
ResolverError,
|
|
420
|
+
ParserError,
|
|
421
|
+
UnmatchedParserError,
|
|
422
|
+
ParserOptions,
|
|
423
|
+
$RefsCallback,
|
|
424
|
+
isHandledError,
|
|
425
|
+
JSONParserErrorGroup,
|
|
426
|
+
SchemaCallback,
|
|
427
|
+
};
|
package/lib/normalize-args.ts
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
import { getNewOptions } from "./options.js";
|
|
2
|
+
import type { JSONSchema, SchemaCallback } from "./types";
|
|
3
|
+
import type $RefParserOptions from "./options";
|
|
2
4
|
|
|
3
5
|
export default normalizeArgs;
|
|
4
6
|
|
|
7
|
+
// 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
|
|
8
|
+
// In the future, I'd like to deprecate the api and accept only named parameters in index.ts
|
|
9
|
+
export interface NormalizedArguments {
|
|
10
|
+
path: string;
|
|
11
|
+
schema: JSONSchema;
|
|
12
|
+
options: $RefParserOptions;
|
|
13
|
+
callback: SchemaCallback;
|
|
14
|
+
}
|
|
5
15
|
/**
|
|
6
16
|
* Normalizes the given arguments, accounting for optional args.
|
|
7
17
|
*/
|
|
8
|
-
function normalizeArgs(_args: Partial<IArguments>) {
|
|
18
|
+
function normalizeArgs(_args: Partial<IArguments>): NormalizedArguments {
|
|
9
19
|
let path, schema, options, callback;
|
|
10
20
|
const args = Array.prototype.slice.call(_args) as any[];
|
|
11
21
|
|
|
@@ -36,10 +46,10 @@ function normalizeArgs(_args: Partial<IArguments>) {
|
|
|
36
46
|
try {
|
|
37
47
|
options = getNewOptions(options);
|
|
38
48
|
} catch (e) {
|
|
39
|
-
console.
|
|
49
|
+
console.error(`JSON Schema Ref Parser: Error normalizing options: ${e}`);
|
|
40
50
|
}
|
|
41
51
|
|
|
42
|
-
if (!options.mutateInputSchema) {
|
|
52
|
+
if (!options.mutateInputSchema && typeof schema === "object") {
|
|
43
53
|
// Make a deep clone of the schema, so that we don't alter the original object
|
|
44
54
|
schema = JSON.parse(JSON.stringify(schema));
|
|
45
55
|
}
|
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
|
/**
|