@apidevtools/json-schema-ref-parser 11.5.1 → 11.5.3

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.
@@ -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 JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(parser: $RefParser<S, O>, options: O): void;
12
+ declare function bundle<S extends JSONSchema = 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 JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(parser: $RefParser<S, O>, options: O): void;
12
+ declare function dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(parser: $RefParser<S, O>, options: O): void;
@@ -9,7 +9,7 @@ export type RefParserSchema = string | JSONSchema;
9
9
  *
10
10
  * @class
11
11
  */
12
- export declare class $RefParser<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions> {
12
+ export declare class $RefParser<S extends JSONSchema = 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 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>;
44
+ static parse<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(schema: S | string): Promise<S>;
45
+ static parse<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(schema: S | string, callback: SchemaCallback<S>): Promise<void>;
46
+ static parse<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(schema: S | string, options: O): Promise<S>;
47
+ static parse<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(schema: S | string, options: O, callback: SchemaCallback<S>): Promise<void>;
48
+ static parse<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(baseUrl: string, schema: S | string, options: O): Promise<S>;
49
+ static parse<S extends JSONSchema = 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 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>;
78
+ static resolve<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(schema: S | string): Promise<$Refs<S, O>>;
79
+ static resolve<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(schema: S | string, callback: $RefsCallback<S, O>): Promise<void>;
80
+ static resolve<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(schema: S | string, options: O): Promise<$Refs<S, O>>;
81
+ static resolve<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(schema: S | string, options: O, callback: $RefsCallback<S, O>): Promise<void>;
82
+ static resolve<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(baseUrl: string, schema: S | string, options: O): Promise<$Refs<S, O>>;
83
+ static resolve<S extends JSONSchema = 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 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>;
95
+ static bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(schema: S | string): Promise<S>;
96
+ static bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(schema: S | string, callback: SchemaCallback<S>): Promise<void>;
97
+ static bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(schema: S | string, options: O): Promise<S>;
98
+ static bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(schema: S | string, options: O, callback: SchemaCallback<S>): Promise<void>;
99
+ static bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(baseUrl: string, schema: S | string, options: O): Promise<S>;
100
+ static bundle<S extends JSONSchema = 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 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>;
129
+ static dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(schema: S | string): Promise<S>;
130
+ static dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(schema: S | string, callback: SchemaCallback<S>): Promise<void>;
131
+ static dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(schema: S | string, options: O): Promise<S>;
132
+ static dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(schema: S | string, options: O, callback: SchemaCallback<S>): Promise<void>;
133
+ static dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(baseUrl: string, schema: S | string, options: O): Promise<S>;
134
+ static dereference<S extends JSONSchema = 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
  *
@@ -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 JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions> {
3
+ export interface NormalizedArguments<S extends JSONSchema = 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 JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(_args: Partial<IArguments>): NormalizedArguments<S, O>;
12
+ export declare function normalizeArgs<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(_args: Partial<IArguments>): NormalizedArguments<S, O>;
13
13
  export default normalizeArgs;
@@ -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<JSONSchema>;
655
- export type ParserOptions = DeepPartial<$RefParserOptions<JSONSchema>>;
654
+ export type Options<S extends JSONSchema = JSONSchema> = $RefParserOptions<S>;
655
+ export type ParserOptions<S extends JSONSchema = JSONSchema> = DeepPartial<$RefParserOptions<S>>;
656
656
  export default $RefParserOptions;
@@ -1,9 +1,9 @@
1
1
  /// <reference types="node" />
2
2
  import type $Refs from "./refs.js";
3
- import type { Options } from "./options.js";
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 JSONSchema = JSONSchema, O extends Options = Options>(path: string, $refs: $Refs<S>, options: O): Promise<string | Buffer | S | undefined>;
8
+ declare function parse<S extends JSONSchema = 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;
@@ -1,4 +1,4 @@
1
- import type $RefParserOptions from "./options.js";
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 JSONSchema = JSONSchema> {
12
+ declare class Pointer<S extends JSONSchema = 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: any, options?: $RefParserOptions<S>, pathFromRoot?: string): this;
54
+ resolve(obj: any, 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: any, value: any, options?: $RefParserOptions<S>): any;
65
+ set(obj: any, 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 JSONSchema = JSONSchema> {
12
+ declare class $Ref<S extends JSONSchema = 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?: $RefParserOptions<S>): boolean;
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?: $RefParserOptions<S>): any;
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?: $RefParserOptions<S>, friendlyPath?: string, pathFromRoot?: string): Pointer<S> | null;
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 JSONSchema = 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 JSONSchema = JSONSchema>($ref: $Ref<S>, resolvedValue: S): S;
179
+ static dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>($ref: $Ref<S, O>, resolvedValue: S): S;
181
180
  }
182
181
  export default $Ref;
@@ -1,9 +1,9 @@
1
1
  import $Ref from "./ref.js";
2
2
  import type { JSONSchema4Type, JSONSchema6Type, JSONSchema7Type } from "json-schema";
3
- import type $RefParserOptions from "./options.js";
3
+ import type { ParserOptions } from "./options.js";
4
4
  import type { JSONSchema } from "./types";
5
- interface $RefsMap<S extends JSONSchema = JSONSchema> {
6
- [url: string]: $Ref<S>;
5
+ interface $RefsMap<S extends JSONSchema = 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 JSONSchema = JSONSchema> {
15
+ export default class $Refs<S extends JSONSchema = 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
  *
@@ -26,7 +26,7 @@ export default class $Refs<S extends JSONSchema = JSONSchema> {
26
26
  *
27
27
  * @param types (optional) Optionally only return certain types of paths ("file", "http", etc.)
28
28
  */
29
- paths(...types: string[]): string[];
29
+ paths(...types: (string | string[])[]): string[];
30
30
  /**
31
31
  * Returns a map of paths/URLs and their correspond values.
32
32
  *
@@ -34,7 +34,7 @@ export default class $Refs<S extends JSONSchema = JSONSchema> {
34
34
  *
35
35
  * @param types (optional) Optionally only return values from certain locations ("file", "http", etc.)
36
36
  */
37
- values(...types: string[]): S;
37
+ values(...types: (string | string[])[]): S;
38
38
  /**
39
39
  * Returns `true` if the given path exists in the schema; otherwise, returns `false`
40
40
  *
@@ -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?: $RefParserOptions<S>): JSONSchema4Type | JSONSchema6Type | JSONSchema7Type;
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: any): $Ref<S>;
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?: any): import("./pointer.js").default<S> | null;
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,
@@ -122,6 +122,6 @@ export default class $Refs<S extends JSONSchema = JSONSchema> {
122
122
  *
123
123
  * @returns {object}
124
124
  */
125
- toJSON: (...types: string[]) => S;
125
+ toJSON: (...types: (string | string[])[]) => S;
126
126
  }
127
127
  export {};
package/dist/lib/refs.js CHANGED
@@ -46,7 +46,7 @@ class $Refs {
46
46
  * @param types (optional) Optionally only return certain types of paths ("file", "http", etc.)
47
47
  */
48
48
  paths(...types) {
49
- const paths = getPaths(this._$refs, types);
49
+ const paths = getPaths(this._$refs, types.flat());
50
50
  return paths.map((path) => {
51
51
  return (0, convert_path_to_posix_1.default)(path.decoded);
52
52
  });
@@ -60,7 +60,7 @@ class $Refs {
60
60
  */
61
61
  values(...types) {
62
62
  const $refs = this._$refs;
63
- const paths = getPaths($refs, types);
63
+ const paths = getPaths($refs, types.flat());
64
64
  return paths.reduce((obj, path) => {
65
65
  obj[(0, convert_path_to_posix_1.default)(path.decoded)] = $refs[path.encoded].value;
66
66
  return obj;
@@ -1,4 +1,4 @@
1
- import type { Options, ParserOptions } from "./options.js";
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 JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(parser: $RefParser<S, O>, options: Options): Promise<void> | Promise<any[]>;
14
+ declare function resolveExternal<S extends JSONSchema = 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.external) {
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.externalReferenceResolution === "root";
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,10 +1,11 @@
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
7
  export type SchemaCallback<S extends JSONSchema = JSONSchema> = (err: Error | null, schema?: S | object | null) => any;
7
- export type $RefsCallback<S extends JSONSchema = JSONSchema> = (err: Error | null, $refs?: $Refs<S>) => any;
8
+ export type $RefsCallback<S extends JSONSchema = 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,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 JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions> extends Error {
14
+ export declare class JSONParserErrorGroup<S extends JSONSchema = 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 JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(parser: $RefParser<S, O>): JSONParserError[];
17
+ static getParserErrors<S extends JSONSchema = 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 $RefParserOptions from "../options.js";
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 JSONSchema = JSONSchema>(plugins: $RefParserOptions<S>["resolve"]): Plugin[];
13
+ export declare function all<S extends JSONSchema = 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 JSONSchema = JSONSchema> {
22
+ export interface PluginResult<S extends JSONSchema = 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 JSONSchema = JSONSchema>(plugins: Plugin[], method: keyof Plugin | keyof ResolverOptions<S>, file: FileInfo, $refs: $Refs<S>): Promise<PluginResult<S>>;
35
+ export declare function run<S extends JSONSchema = 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>>;
@@ -8,7 +8,7 @@ exports.run = exports.sort = exports.filter = exports.all = void 0;
8
8
  * @returns
9
9
  */
10
10
  function all(plugins) {
11
- return Object.keys(plugins)
11
+ return Object.keys(plugins || {})
12
12
  .filter((key) => {
13
13
  return typeof plugins[key] === "object";
14
14
  })
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 JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
17
+ function bundle<S extends JSONSchema = 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 JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
43
+ function crawl<S extends JSONSchema = 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 JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
105
+ function inventory$Ref<S extends JSONSchema = 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];
@@ -16,7 +16,7 @@ export default dereference;
16
16
  * @param parser
17
17
  * @param options
18
18
  */
19
- function dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
19
+ function dereference<S extends JSONSchema = 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 JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
51
+ function crawl<S extends JSONSchema = 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 JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
164
+ function dereference$Ref<S extends JSONSchema = 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);