@apidevtools/json-schema-ref-parser 11.5.2 → 11.5.4
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 +1 -1
- package/dist/lib/dereference.d.ts +1 -1
- package/dist/lib/index.d.ts +32 -32
- package/dist/lib/index.js +1 -1
- package/dist/lib/normalize-args.d.ts +3 -3
- package/dist/lib/options.d.ts +4 -4
- package/dist/lib/parse.d.ts +2 -2
- package/dist/lib/pointer.d.ts +6 -6
- package/dist/lib/ref.d.ts +8 -9
- package/dist/lib/refs.d.ts +10 -10
- package/dist/lib/resolve-external.d.ts +2 -2
- package/dist/lib/resolve-external.js +2 -2
- package/dist/lib/types/index.d.ts +5 -4
- package/dist/lib/util/errors.d.ts +2 -2
- package/dist/lib/util/plugins.d.ts +4 -4
- package/dist/lib/util/plugins.js +1 -1
- package/lib/bundle.ts +5 -5
- package/lib/dereference.ts +5 -5
- package/lib/index.ts +48 -44
- package/lib/normalize-args.ts +4 -4
- package/lib/options.ts +5 -4
- package/lib/parse.ts +8 -8
- package/lib/pointer.ts +6 -6
- package/lib/ref.ts +12 -10
- package/lib/refs.ts +14 -11
- package/lib/resolve-external.ts +13 -13
- package/lib/resolvers/http.ts +2 -2
- package/lib/types/index.ts +8 -4
- package/lib/util/errors.ts +5 -5
- package/lib/util/plugins.ts +18 -16
- package/package.json +1 -1
package/dist/lib/bundle.d.ts
CHANGED
|
@@ -9,5 +9,5 @@ import type { JSONSchema } from "./index";
|
|
|
9
9
|
* @param parser
|
|
10
10
|
* @param options
|
|
11
11
|
*/
|
|
12
|
-
declare function bundle<S extends
|
|
12
|
+
declare function bundle<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(parser: $RefParser<S, O>, options: O): void;
|
|
13
13
|
export default bundle;
|
|
@@ -9,4 +9,4 @@ export default dereference;
|
|
|
9
9
|
* @param parser
|
|
10
10
|
* @param options
|
|
11
11
|
*/
|
|
12
|
-
declare function dereference<S extends
|
|
12
|
+
declare function dereference<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(parser: $RefParser<S, O>, options: O): void;
|
package/dist/lib/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export type RefParserSchema = string | JSONSchema;
|
|
|
9
9
|
*
|
|
10
10
|
* @class
|
|
11
11
|
*/
|
|
12
|
-
export declare class $RefParser<S extends
|
|
12
|
+
export declare class $RefParser<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>> {
|
|
13
13
|
/**
|
|
14
14
|
* The parsed (and possibly dereferenced) JSON schema object
|
|
15
15
|
*
|
|
@@ -23,7 +23,7 @@ export declare class $RefParser<S extends JSONSchema = JSONSchema, O extends Par
|
|
|
23
23
|
* @type {$Refs}
|
|
24
24
|
* @readonly
|
|
25
25
|
*/
|
|
26
|
-
$refs: $Refs<S>;
|
|
26
|
+
$refs: $Refs<S, O>;
|
|
27
27
|
/**
|
|
28
28
|
* Parses the given JSON schema.
|
|
29
29
|
* This method does not resolve any JSON references.
|
|
@@ -41,12 +41,12 @@ export declare class $RefParser<S extends JSONSchema = JSONSchema, O extends Par
|
|
|
41
41
|
parse(schema: S | string, options: O, callback: SchemaCallback<S>): Promise<void>;
|
|
42
42
|
parse(baseUrl: string, schema: S | string, options: O): Promise<S>;
|
|
43
43
|
parse(baseUrl: string, schema: S | string, options: O, callback: SchemaCallback<S>): Promise<void>;
|
|
44
|
-
static parse<S extends
|
|
45
|
-
static parse<S extends
|
|
46
|
-
static parse<S extends
|
|
47
|
-
static parse<S extends
|
|
48
|
-
static parse<S extends
|
|
49
|
-
static parse<S extends
|
|
44
|
+
static parse<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(schema: S | string): Promise<S>;
|
|
45
|
+
static parse<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(schema: S | string, callback: SchemaCallback<S>): Promise<void>;
|
|
46
|
+
static parse<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(schema: S | string, options: O): Promise<S>;
|
|
47
|
+
static parse<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(schema: S | string, options: O, callback: SchemaCallback<S>): Promise<void>;
|
|
48
|
+
static parse<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(baseUrl: string, schema: S | string, options: O): Promise<S>;
|
|
49
|
+
static parse<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(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<S extends JSONSchema = JSONSchema, O extends Par
|
|
|
58
58
|
* @param options (optional)
|
|
59
59
|
* @param callback (optional) A callback that will receive a `$Refs` object
|
|
60
60
|
*/
|
|
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>;
|
|
61
|
+
resolve(schema: S | string): Promise<$Refs<S, O>>;
|
|
62
|
+
resolve(schema: S | string, callback: $RefsCallback<S, O>): Promise<void>;
|
|
63
|
+
resolve(schema: S | string, options: O): Promise<$Refs<S, O>>;
|
|
64
|
+
resolve(schema: S | string, options: O, callback: $RefsCallback<S, O>): Promise<void>;
|
|
65
|
+
resolve(baseUrl: string, schema: S | string, options: O): Promise<$Refs<S, O>>;
|
|
66
|
+
resolve(baseUrl: string, schema: S | string, options: O, callback: $RefsCallback<S, O>): 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,12 +75,12 @@ export declare class $RefParser<S extends JSONSchema = JSONSchema, O extends Par
|
|
|
75
75
|
* @param options (optional)
|
|
76
76
|
* @param callback (optional) A callback that will receive a `$Refs` object
|
|
77
77
|
*/
|
|
78
|
-
static resolve<S extends
|
|
79
|
-
static resolve<S extends
|
|
80
|
-
static resolve<S extends
|
|
81
|
-
static resolve<S extends
|
|
82
|
-
static resolve<S extends
|
|
83
|
-
static resolve<S extends
|
|
78
|
+
static resolve<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(schema: S | string): Promise<$Refs<S, O>>;
|
|
79
|
+
static resolve<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(schema: S | string, callback: $RefsCallback<S, O>): Promise<void>;
|
|
80
|
+
static resolve<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(schema: S | string, options: O): Promise<$Refs<S, O>>;
|
|
81
|
+
static resolve<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(schema: S | string, options: O, callback: $RefsCallback<S, O>): Promise<void>;
|
|
82
|
+
static resolve<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(baseUrl: string, schema: S | string, options: O): Promise<$Refs<S, O>>;
|
|
83
|
+
static resolve<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(baseUrl: string, schema: S | string, options: O, callback: $RefsCallback<S, O>): Promise<void>;
|
|
84
84
|
/**
|
|
85
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.
|
|
86
86
|
*
|
|
@@ -92,12 +92,12 @@ export declare class $RefParser<S extends JSONSchema = JSONSchema, O extends Par
|
|
|
92
92
|
* @param options (optional)
|
|
93
93
|
* @param callback (optional) A callback that will receive the bundled schema object
|
|
94
94
|
*/
|
|
95
|
-
static bundle<S extends
|
|
96
|
-
static bundle<S extends
|
|
97
|
-
static bundle<S extends
|
|
98
|
-
static bundle<S extends
|
|
99
|
-
static bundle<S extends
|
|
100
|
-
static bundle<S extends
|
|
95
|
+
static bundle<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(schema: S | string): Promise<S>;
|
|
96
|
+
static bundle<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(schema: S | string, callback: SchemaCallback<S>): Promise<void>;
|
|
97
|
+
static bundle<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(schema: S | string, options: O): Promise<S>;
|
|
98
|
+
static bundle<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(schema: S | string, options: O, callback: SchemaCallback<S>): Promise<void>;
|
|
99
|
+
static bundle<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(baseUrl: string, schema: S | string, options: O): Promise<S>;
|
|
100
|
+
static bundle<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(baseUrl: string, schema: S | string, options: O, callback: SchemaCallback<S>): Promise<S>;
|
|
101
101
|
/**
|
|
102
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.
|
|
103
103
|
*
|
|
@@ -126,12 +126,12 @@ export declare class $RefParser<S extends JSONSchema = JSONSchema, O extends Par
|
|
|
126
126
|
* @param options (optional)
|
|
127
127
|
* @param callback (optional) A callback that will receive the dereferenced schema object
|
|
128
128
|
*/
|
|
129
|
-
static dereference<S extends
|
|
130
|
-
static dereference<S extends
|
|
131
|
-
static dereference<S extends
|
|
132
|
-
static dereference<S extends
|
|
133
|
-
static dereference<S extends
|
|
134
|
-
static dereference<S extends
|
|
129
|
+
static dereference<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(schema: S | string): Promise<S>;
|
|
130
|
+
static dereference<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(schema: S | string, callback: SchemaCallback<S>): Promise<void>;
|
|
131
|
+
static dereference<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(schema: S | string, options: O): Promise<S>;
|
|
132
|
+
static dereference<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(schema: S | string, options: O, callback: SchemaCallback<S>): Promise<void>;
|
|
133
|
+
static dereference<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(baseUrl: string, schema: S | string, options: O): Promise<S>;
|
|
134
|
+
static dereference<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(baseUrl: string, schema: S | string, options: O, callback: SchemaCallback<S>): Promise<void>;
|
|
135
135
|
/**
|
|
136
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.
|
|
137
137
|
*
|
package/dist/lib/index.js
CHANGED
|
@@ -90,7 +90,7 @@ class $RefParser {
|
|
|
90
90
|
args.path = url.fromFileSystemPath(args.path);
|
|
91
91
|
pathType = "file";
|
|
92
92
|
}
|
|
93
|
-
else if (!args.path && args.schema && args.schema.$id) {
|
|
93
|
+
else if (!args.path && args.schema && "$id" in args.schema && args.schema.$id) {
|
|
94
94
|
// when schema id has defined an URL should use that hostname to request the references,
|
|
95
95
|
// instead of using the current page URL
|
|
96
96
|
const params = url.parse(args.schema.$id);
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { Options, ParserOptions } from "./options.js";
|
|
2
2
|
import type { JSONSchema, SchemaCallback } from "./types";
|
|
3
|
-
export interface NormalizedArguments<S extends
|
|
3
|
+
export interface NormalizedArguments<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>> {
|
|
4
4
|
path: string;
|
|
5
5
|
schema: S;
|
|
6
|
-
options: O & Options
|
|
6
|
+
options: O & Options<S>;
|
|
7
7
|
callback: SchemaCallback<S>;
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
10
|
* Normalizes the given arguments, accounting for optional args.
|
|
11
11
|
*/
|
|
12
|
-
export declare function normalizeArgs<S extends
|
|
12
|
+
export declare function normalizeArgs<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(_args: Partial<IArguments>): NormalizedArguments<S, O>;
|
|
13
13
|
export default normalizeArgs;
|
package/dist/lib/options.d.ts
CHANGED
|
@@ -40,7 +40,7 @@ export interface DereferenceOptions {
|
|
|
40
40
|
* @param [options] - Overridden options
|
|
41
41
|
* @class
|
|
42
42
|
*/
|
|
43
|
-
export interface $RefParserOptions<S extends
|
|
43
|
+
export interface $RefParserOptions<S extends object = JSONSchema> {
|
|
44
44
|
/**
|
|
45
45
|
* The `parse` options determine how different types of files will be parsed.
|
|
46
46
|
*
|
|
@@ -88,7 +88,7 @@ export interface $RefParserOptions<S extends JSONSchema = JSONSchema> {
|
|
|
88
88
|
mutateInputSchema?: boolean;
|
|
89
89
|
}
|
|
90
90
|
export declare const getJsonSchemaRefParserDefaultOptions: () => $RefParserOptions<JSONSchema>;
|
|
91
|
-
export declare const getNewOptions: <S extends
|
|
91
|
+
export declare const getNewOptions: <S extends object = JSONSchema, O extends {
|
|
92
92
|
parse?: {
|
|
93
93
|
[x: string]: boolean | {
|
|
94
94
|
name?: string | undefined;
|
|
@@ -651,6 +651,6 @@ export declare const getNewOptions: <S extends JSONSchema = JSONSchema, O extend
|
|
|
651
651
|
} | undefined;
|
|
652
652
|
mutateInputSchema?: boolean | undefined;
|
|
653
653
|
}>(options: O | undefined) => O & $RefParserOptions<S>;
|
|
654
|
-
export type Options = $RefParserOptions<
|
|
655
|
-
export type ParserOptions = DeepPartial<$RefParserOptions<
|
|
654
|
+
export type Options<S extends object = JSONSchema> = $RefParserOptions<S>;
|
|
655
|
+
export type ParserOptions<S extends object = JSONSchema> = DeepPartial<$RefParserOptions<S>>;
|
|
656
656
|
export default $RefParserOptions;
|
package/dist/lib/parse.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import type $Refs from "./refs.js";
|
|
3
|
-
import type {
|
|
3
|
+
import type { ParserOptions } 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<S extends
|
|
8
|
+
declare function parse<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(path: string, $refs: $Refs<S, O>, options: O): Promise<string | Buffer | S | undefined>;
|
|
9
9
|
export default parse;
|
package/dist/lib/pointer.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import type { ParserOptions } from "./options.js";
|
|
2
2
|
import $Ref from "./ref.js";
|
|
3
3
|
import type { JSONSchema } from "./types";
|
|
4
4
|
/**
|
|
@@ -9,11 +9,11 @@ import type { JSONSchema } from "./types";
|
|
|
9
9
|
* @param [friendlyPath] - The original user-specified path (used for error messages)
|
|
10
10
|
* @class
|
|
11
11
|
*/
|
|
12
|
-
declare class Pointer<S extends
|
|
12
|
+
declare class Pointer<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>> {
|
|
13
13
|
/**
|
|
14
14
|
* The {@link $Ref} object that contains this {@link Pointer} object.
|
|
15
15
|
*/
|
|
16
|
-
$ref: $Ref<S>;
|
|
16
|
+
$ref: $Ref<S, O>;
|
|
17
17
|
/**
|
|
18
18
|
* The file path or URL, containing the JSON pointer in the hash.
|
|
19
19
|
* This path is relative to the path of the main JSON schema file.
|
|
@@ -37,7 +37,7 @@ declare class Pointer<S extends JSONSchema = JSONSchema> {
|
|
|
37
37
|
* Resolving a single pointer may require resolving multiple $Refs.
|
|
38
38
|
*/
|
|
39
39
|
indirections: number;
|
|
40
|
-
constructor($ref: $Ref<S>, path: string, friendlyPath?: string);
|
|
40
|
+
constructor($ref: $Ref<S, O>, path: string, friendlyPath?: string);
|
|
41
41
|
/**
|
|
42
42
|
* Resolves the value of a nested property within the given object.
|
|
43
43
|
*
|
|
@@ -51,7 +51,7 @@ declare class Pointer<S extends JSONSchema = JSONSchema> {
|
|
|
51
51
|
* the {@link Pointer#$ref} and {@link Pointer#path} will reflect the resolution path
|
|
52
52
|
* of the resolved value.
|
|
53
53
|
*/
|
|
54
|
-
resolve(obj:
|
|
54
|
+
resolve(obj: S, options?: O, pathFromRoot?: string): this;
|
|
55
55
|
/**
|
|
56
56
|
* Sets the value of a nested property within the given object.
|
|
57
57
|
*
|
|
@@ -62,7 +62,7 @@ declare class Pointer<S extends JSONSchema = JSONSchema> {
|
|
|
62
62
|
* @returns
|
|
63
63
|
* Returns the modified object, or an entirely new object if the entire object is overwritten.
|
|
64
64
|
*/
|
|
65
|
-
set(obj:
|
|
65
|
+
set(obj: S, value: any, options?: O): any;
|
|
66
66
|
/**
|
|
67
67
|
* Parses a JSON pointer (or a path containing a JSON pointer in the hash)
|
|
68
68
|
* and returns an array of the pointer's tokens.
|
package/dist/lib/ref.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import Pointer from "./pointer.js";
|
|
2
2
|
import type { JSONParserError, MissingPointerError, ParserError, ResolverError } from "./util/errors.js";
|
|
3
3
|
import type $Refs from "./refs.js";
|
|
4
|
-
import type $RefParserOptions from "./options.js";
|
|
5
4
|
import type { ParserOptions } from "./options.js";
|
|
6
5
|
import type { JSONSchema } from "./types";
|
|
7
6
|
export type $RefError = JSONParserError | ResolverError | ParserError | MissingPointerError;
|
|
@@ -10,7 +9,7 @@ export type $RefError = JSONParserError | ResolverError | ParserError | MissingP
|
|
|
10
9
|
*
|
|
11
10
|
* @class
|
|
12
11
|
*/
|
|
13
|
-
declare class $Ref<S extends
|
|
12
|
+
declare class $Ref<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>> {
|
|
14
13
|
/**
|
|
15
14
|
* The file path or URL of the referenced file.
|
|
16
15
|
* This path is relative to the path of the main JSON schema file.
|
|
@@ -34,7 +33,7 @@ declare class $Ref<S extends JSONSchema = JSONSchema> {
|
|
|
34
33
|
*
|
|
35
34
|
* @type {$Refs}
|
|
36
35
|
*/
|
|
37
|
-
$refs: $Refs<S>;
|
|
36
|
+
$refs: $Refs<S, O>;
|
|
38
37
|
/**
|
|
39
38
|
* Indicates the type of {@link $Ref#path} (e.g. "file", "http", etc.)
|
|
40
39
|
*/
|
|
@@ -43,7 +42,7 @@ declare class $Ref<S extends JSONSchema = JSONSchema> {
|
|
|
43
42
|
* List of all errors. Undefined if no errors.
|
|
44
43
|
*/
|
|
45
44
|
errors: Array<$RefError>;
|
|
46
|
-
constructor($refs: $Refs<S>);
|
|
45
|
+
constructor($refs: $Refs<S, O>);
|
|
47
46
|
/**
|
|
48
47
|
* Pushes an error to errors array.
|
|
49
48
|
*
|
|
@@ -58,7 +57,7 @@ declare class $Ref<S extends JSONSchema = JSONSchema> {
|
|
|
58
57
|
* @param options
|
|
59
58
|
* @returns
|
|
60
59
|
*/
|
|
61
|
-
exists(path: string, options?:
|
|
60
|
+
exists(path: string, options?: O): boolean;
|
|
62
61
|
/**
|
|
63
62
|
* Resolves the given JSON reference within this {@link $Ref#value} and returns the resolved value.
|
|
64
63
|
*
|
|
@@ -66,7 +65,7 @@ declare class $Ref<S extends JSONSchema = JSONSchema> {
|
|
|
66
65
|
* @param options
|
|
67
66
|
* @returns - Returns the resolved value
|
|
68
67
|
*/
|
|
69
|
-
get(path: string, options?:
|
|
68
|
+
get(path: string, options?: O): any;
|
|
70
69
|
/**
|
|
71
70
|
* Resolves the given JSON reference within this {@link $Ref#value}.
|
|
72
71
|
*
|
|
@@ -76,7 +75,7 @@ declare class $Ref<S extends JSONSchema = JSONSchema> {
|
|
|
76
75
|
* @param pathFromRoot - The path of `obj` from the schema root
|
|
77
76
|
* @returns
|
|
78
77
|
*/
|
|
79
|
-
resolve(path: string, options?:
|
|
78
|
+
resolve(path: string, options?: O, friendlyPath?: string, pathFromRoot?: string): Pointer<S, O> | null;
|
|
80
79
|
/**
|
|
81
80
|
* Sets the value of a nested property within this {@link $Ref#value}.
|
|
82
81
|
* If the property, or any of its parents don't exist, they will be created.
|
|
@@ -110,7 +109,7 @@ declare class $Ref<S extends JSONSchema = JSONSchema> {
|
|
|
110
109
|
* @param options
|
|
111
110
|
* @returns
|
|
112
111
|
*/
|
|
113
|
-
static isAllowed$Ref(value: unknown, options?: ParserOptions): true | undefined;
|
|
112
|
+
static isAllowed$Ref<S extends object = JSONSchema>(value: unknown, options?: ParserOptions<S>): true | undefined;
|
|
114
113
|
/**
|
|
115
114
|
* Determines whether the given value is a JSON reference that "extends" its resolved value.
|
|
116
115
|
* That is, it has extra properties (in addition to "$ref"), so rather than simply pointing to
|
|
@@ -177,6 +176,6 @@ declare class $Ref<S extends JSONSchema = JSONSchema> {
|
|
|
177
176
|
* @param resolvedValue - The resolved value, which can be any type
|
|
178
177
|
* @returns - Returns the dereferenced value
|
|
179
178
|
*/
|
|
180
|
-
static dereference<S extends
|
|
179
|
+
static dereference<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>($ref: $Ref<S, O>, resolvedValue: S): S;
|
|
181
180
|
}
|
|
182
181
|
export default $Ref;
|
package/dist/lib/refs.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import $Ref from "./ref.js";
|
|
2
2
|
import type { JSONSchema4Type, JSONSchema6Type, JSONSchema7Type } from "json-schema";
|
|
3
|
-
import type
|
|
3
|
+
import type { ParserOptions } from "./options.js";
|
|
4
4
|
import type { JSONSchema } from "./types";
|
|
5
|
-
interface $RefsMap<S extends
|
|
6
|
-
[url: string]: $Ref<S>;
|
|
5
|
+
interface $RefsMap<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>> {
|
|
6
|
+
[url: string]: $Ref<S, O>;
|
|
7
7
|
}
|
|
8
8
|
/**
|
|
9
9
|
* When you call the resolve method, the value that gets passed to the callback function (or Promise) is a $Refs object. This same object is accessible via the parser.$refs property of $RefParser objects.
|
|
@@ -12,7 +12,7 @@ interface $RefsMap<S extends JSONSchema = JSONSchema> {
|
|
|
12
12
|
*
|
|
13
13
|
* See https://apitools.dev/json-schema-ref-parser/docs/refs.html
|
|
14
14
|
*/
|
|
15
|
-
export default class $Refs<S extends
|
|
15
|
+
export default class $Refs<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>> {
|
|
16
16
|
/**
|
|
17
17
|
* This property is true if the schema contains any circular references. You may want to check this property before serializing the dereferenced schema as JSON, since JSON.stringify() does not support circular references by default.
|
|
18
18
|
*
|
|
@@ -57,7 +57,7 @@ export default class $Refs<S extends JSONSchema = JSONSchema> {
|
|
|
57
57
|
* @param [options]
|
|
58
58
|
* @returns - Returns the resolved value
|
|
59
59
|
*/
|
|
60
|
-
get(path: string, options?:
|
|
60
|
+
get(path: string, options?: O): JSONSchema4Type | JSONSchema6Type | JSONSchema7Type;
|
|
61
61
|
/**
|
|
62
62
|
* 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.
|
|
63
63
|
*
|
|
@@ -72,13 +72,13 @@ export default class $Refs<S extends JSONSchema = JSONSchema> {
|
|
|
72
72
|
* @returns
|
|
73
73
|
* @protected
|
|
74
74
|
*/
|
|
75
|
-
_get$Ref(path:
|
|
75
|
+
_get$Ref(path: string): $Ref<S, O>;
|
|
76
76
|
/**
|
|
77
77
|
* Creates a new {@link $Ref} object and adds it to this {@link $Refs} object.
|
|
78
78
|
*
|
|
79
79
|
* @param path - The file path or URL of the referenced file
|
|
80
80
|
*/
|
|
81
|
-
_add(path: string): $Ref<S>;
|
|
81
|
+
_add(path: string): $Ref<S, O>;
|
|
82
82
|
/**
|
|
83
83
|
* Resolves the given JSON reference.
|
|
84
84
|
*
|
|
@@ -88,21 +88,21 @@ export default class $Refs<S extends JSONSchema = JSONSchema> {
|
|
|
88
88
|
* @returns
|
|
89
89
|
* @protected
|
|
90
90
|
*/
|
|
91
|
-
_resolve(path: string, pathFromRoot: string, options?:
|
|
91
|
+
_resolve(path: string, pathFromRoot: string, options?: O): import("./pointer.js").default<S, O> | null;
|
|
92
92
|
/**
|
|
93
93
|
* A map of paths/urls to {@link $Ref} objects
|
|
94
94
|
*
|
|
95
95
|
* @type {object}
|
|
96
96
|
* @protected
|
|
97
97
|
*/
|
|
98
|
-
_$refs: $RefsMap<S>;
|
|
98
|
+
_$refs: $RefsMap<S, O>;
|
|
99
99
|
/**
|
|
100
100
|
* The {@link $Ref} object that is the root of the JSON schema.
|
|
101
101
|
*
|
|
102
102
|
* @type {$Ref}
|
|
103
103
|
* @protected
|
|
104
104
|
*/
|
|
105
|
-
_root$Ref: $Ref<S>;
|
|
105
|
+
_root$Ref: $Ref<S, O>;
|
|
106
106
|
constructor();
|
|
107
107
|
/**
|
|
108
108
|
* Returns the paths of all the files/URLs that are referenced by the JSON schema,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ParserOptions } from "./options.js";
|
|
2
2
|
import type { JSONSchema } from "./types/index.js";
|
|
3
3
|
import type $RefParser from "./index.js";
|
|
4
4
|
/**
|
|
@@ -11,5 +11,5 @@ import type $RefParser from "./index.js";
|
|
|
11
11
|
* The promise resolves once all JSON references in the schema have been resolved,
|
|
12
12
|
* including nested references that are contained in externally-referenced files.
|
|
13
13
|
*/
|
|
14
|
-
declare function resolveExternal<S extends
|
|
14
|
+
declare function resolveExternal<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(parser: $RefParser<S, O>, options: O): Promise<void> | Promise<any[]>;
|
|
15
15
|
export default resolveExternal;
|
|
@@ -42,7 +42,7 @@ const errors_js_1 = require("./util/errors.js");
|
|
|
42
42
|
* including nested references that are contained in externally-referenced files.
|
|
43
43
|
*/
|
|
44
44
|
function resolveExternal(parser, options) {
|
|
45
|
-
if (!options.resolve
|
|
45
|
+
if (!options.resolve?.external) {
|
|
46
46
|
// Nothing to resolve, so exit early
|
|
47
47
|
return Promise.resolve();
|
|
48
48
|
}
|
|
@@ -101,7 +101,7 @@ function crawl(obj, path, $refs, options, seen, external) {
|
|
|
101
101
|
* including nested references that are contained in externally-referenced files.
|
|
102
102
|
*/
|
|
103
103
|
async function resolve$Ref($ref, path, $refs, options) {
|
|
104
|
-
const shouldResolveOnCwd = options.dereference
|
|
104
|
+
const shouldResolveOnCwd = options.dereference?.externalReferenceResolution === "root";
|
|
105
105
|
const resolvedPath = url.resolve(shouldResolveOnCwd ? url.cwd() : path, $ref.$ref);
|
|
106
106
|
const withoutHash = url.stripHash(resolvedPath);
|
|
107
107
|
// $ref.$ref = url.relative($refs._root$Ref.path, resolvedPath);
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import type { JSONSchema4, JSONSchema4Object, JSONSchema6, JSONSchema6Object, JSONSchema7, JSONSchema7Object } from "json-schema";
|
|
3
3
|
import type $Refs from "../refs.js";
|
|
4
|
+
import type { ParserOptions } from "../options";
|
|
4
5
|
export type JSONSchema = JSONSchema4 | JSONSchema6 | JSONSchema7;
|
|
5
6
|
export type JSONSchemaObject = JSONSchema4Object | JSONSchema6Object | JSONSchema7Object;
|
|
6
|
-
export type SchemaCallback<S extends
|
|
7
|
-
export type $RefsCallback<S extends
|
|
7
|
+
export type SchemaCallback<S extends object = JSONSchema> = (err: Error | null, schema?: S | object | null) => any;
|
|
8
|
+
export type $RefsCallback<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>> = (err: Error | null, $refs?: $Refs<S, O>) => any;
|
|
8
9
|
/**
|
|
9
10
|
* See https://apitools.dev/json-schema-ref-parser/docs/options.html
|
|
10
11
|
*/
|
|
11
|
-
export interface HTTPResolverOptions<S extends
|
|
12
|
+
export interface HTTPResolverOptions<S extends object = JSONSchema> extends Partial<ResolverOptions<S>> {
|
|
12
13
|
/**
|
|
13
14
|
* 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.
|
|
14
15
|
*/
|
|
@@ -31,7 +32,7 @@ export interface HTTPResolverOptions<S extends JSONSchema = JSONSchema> extends
|
|
|
31
32
|
*
|
|
32
33
|
* See https://apitools.dev/json-schema-ref-parser/docs/plugins/resolvers.html
|
|
33
34
|
*/
|
|
34
|
-
export interface ResolverOptions<S extends
|
|
35
|
+
export interface ResolverOptions<S extends object = JSONSchema> {
|
|
35
36
|
name?: string;
|
|
36
37
|
/**
|
|
37
38
|
* All resolvers have an order property, even the built-in resolvers. If you don't specify an order property, then your resolver will run last. Specifying `order: 1`, like we did in this example, will make your resolver run first. Or you can squeeze your resolver in-between some of the built-in resolvers. For example, `order: 101` would make it run after the file resolver, but before the HTTP resolver. You can see the order of all the built-in resolvers by looking at their source code.
|
|
@@ -11,10 +11,10 @@ export declare class JSONParserError extends Error {
|
|
|
11
11
|
constructor(message: string, source?: string);
|
|
12
12
|
get footprint(): string;
|
|
13
13
|
}
|
|
14
|
-
export declare class JSONParserErrorGroup<S extends
|
|
14
|
+
export declare class JSONParserErrorGroup<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>> extends Error {
|
|
15
15
|
files: $RefParser<S, O>;
|
|
16
16
|
constructor(parser: $RefParser<S, O>);
|
|
17
|
-
static getParserErrors<S extends
|
|
17
|
+
static getParserErrors<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(parser: $RefParser<S, O>): JSONParserError[];
|
|
18
18
|
get errors(): Array<JSONParserError | InvalidPointerError | ResolverError | ParserError | MissingPointerError | UnmatchedParserError | UnmatchedResolverError>;
|
|
19
19
|
}
|
|
20
20
|
export declare class ParserError extends JSONParserError {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import type { FileInfo, JSONSchema } from "../types/index.js";
|
|
3
|
-
import type
|
|
3
|
+
import type { ParserOptions } from "../options.js";
|
|
4
4
|
import type { ResolverOptions } from "../types/index.js";
|
|
5
5
|
import type $Refs from "../refs.js";
|
|
6
6
|
import type { Plugin } from "../types/index.js";
|
|
@@ -10,7 +10,7 @@ import type { Plugin } from "../types/index.js";
|
|
|
10
10
|
*
|
|
11
11
|
* @returns
|
|
12
12
|
*/
|
|
13
|
-
export declare function all<S extends
|
|
13
|
+
export declare function all<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(plugins: O["resolve"]): Plugin[];
|
|
14
14
|
/**
|
|
15
15
|
* Filters the given plugins, returning only the ones return `true` for the given method.
|
|
16
16
|
*/
|
|
@@ -19,7 +19,7 @@ export declare function filter(plugins: Plugin[], method: any, file: any): Plugi
|
|
|
19
19
|
* Sorts the given plugins, in place, by their `order` property.
|
|
20
20
|
*/
|
|
21
21
|
export declare function sort(plugins: Plugin[]): Plugin[];
|
|
22
|
-
export interface PluginResult<S extends
|
|
22
|
+
export interface PluginResult<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>> {
|
|
23
23
|
plugin: Plugin;
|
|
24
24
|
result?: string | Buffer | S;
|
|
25
25
|
error?: any;
|
|
@@ -32,4 +32,4 @@ export interface PluginResult<S extends JSONSchema = JSONSchema> {
|
|
|
32
32
|
* If the promise rejects, or the callback is called with an error, then the next plugin is called.
|
|
33
33
|
* If ALL plugins fail, then the last error is thrown.
|
|
34
34
|
*/
|
|
35
|
-
export declare function run<S extends
|
|
35
|
+
export declare function run<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(plugins: Plugin[], method: keyof Plugin | keyof ResolverOptions<S>, file: FileInfo, $refs: $Refs<S, O>): Promise<PluginResult<S, O>>;
|
package/dist/lib/util/plugins.js
CHANGED
package/lib/bundle.ts
CHANGED
|
@@ -14,7 +14,7 @@ import type { JSONSchema } from "./index";
|
|
|
14
14
|
* @param parser
|
|
15
15
|
* @param options
|
|
16
16
|
*/
|
|
17
|
-
function bundle<S extends
|
|
17
|
+
function bundle<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
|
|
18
18
|
parser: $RefParser<S, O>,
|
|
19
19
|
options: O,
|
|
20
20
|
) {
|
|
@@ -40,14 +40,14 @@ function bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions = Par
|
|
|
40
40
|
* @param $refs
|
|
41
41
|
* @param options
|
|
42
42
|
*/
|
|
43
|
-
function crawl<S extends
|
|
43
|
+
function crawl<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
|
|
44
44
|
parent: any,
|
|
45
45
|
key: string | null,
|
|
46
46
|
path: string,
|
|
47
47
|
pathFromRoot: string,
|
|
48
48
|
indirections: number,
|
|
49
49
|
inventory: unknown[],
|
|
50
|
-
$refs: $Refs<S>,
|
|
50
|
+
$refs: $Refs<S, O>,
|
|
51
51
|
options: O,
|
|
52
52
|
) {
|
|
53
53
|
const obj = key === null ? parent : parent[key];
|
|
@@ -102,14 +102,14 @@ function crawl<S extends JSONSchema = JSONSchema, O extends ParserOptions = Pars
|
|
|
102
102
|
* @param $refs
|
|
103
103
|
* @param options
|
|
104
104
|
*/
|
|
105
|
-
function inventory$Ref<S extends
|
|
105
|
+
function inventory$Ref<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
|
|
106
106
|
$refParent: any,
|
|
107
107
|
$refKey: any,
|
|
108
108
|
path: string,
|
|
109
109
|
pathFromRoot: any,
|
|
110
110
|
indirections: any,
|
|
111
111
|
inventory: any,
|
|
112
|
-
$refs: $Refs<S>,
|
|
112
|
+
$refs: $Refs<S, O>,
|
|
113
113
|
options: O,
|
|
114
114
|
) {
|
|
115
115
|
const $ref = $refKey === null ? $refParent : $refParent[$refKey];
|
package/lib/dereference.ts
CHANGED
|
@@ -16,7 +16,7 @@ export default dereference;
|
|
|
16
16
|
* @param parser
|
|
17
17
|
* @param options
|
|
18
18
|
*/
|
|
19
|
-
function dereference<S extends
|
|
19
|
+
function dereference<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
|
|
20
20
|
parser: $RefParser<S, O>,
|
|
21
21
|
options: O,
|
|
22
22
|
) {
|
|
@@ -48,14 +48,14 @@ function dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions
|
|
|
48
48
|
* @param options
|
|
49
49
|
* @returns
|
|
50
50
|
*/
|
|
51
|
-
function crawl<S extends
|
|
51
|
+
function crawl<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
|
|
52
52
|
obj: any,
|
|
53
53
|
path: string,
|
|
54
54
|
pathFromRoot: string,
|
|
55
55
|
parents: Set<any>,
|
|
56
56
|
processedObjects: Set<any>,
|
|
57
57
|
dereferencedCache: any,
|
|
58
|
-
$refs: $Refs<S>,
|
|
58
|
+
$refs: $Refs<S, O>,
|
|
59
59
|
options: O,
|
|
60
60
|
) {
|
|
61
61
|
let dereferenced;
|
|
@@ -161,14 +161,14 @@ function crawl<S extends JSONSchema = JSONSchema, O extends ParserOptions = Pars
|
|
|
161
161
|
* @param options
|
|
162
162
|
* @returns
|
|
163
163
|
*/
|
|
164
|
-
function dereference$Ref<S extends
|
|
164
|
+
function dereference$Ref<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
|
|
165
165
|
$ref: any,
|
|
166
166
|
path: string,
|
|
167
167
|
pathFromRoot: string,
|
|
168
168
|
parents: Set<any>,
|
|
169
169
|
processedObjects: any,
|
|
170
170
|
dereferencedCache: any,
|
|
171
|
-
$refs: $Refs<S>,
|
|
171
|
+
$refs: $Refs<S, O>,
|
|
172
172
|
options: O,
|
|
173
173
|
) {
|
|
174
174
|
const isExternalRef = $Ref.isExternal$Ref($ref);
|