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

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<S> = ParserOptions<S>>(parser: $RefParser<S, O>, options: O): void;
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 JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(parser: $RefParser<S, O>, options: O): void;
12
+ declare function dereference<S extends object = 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<S> = ParserOptions<S>> {
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
  *
@@ -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, 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>;
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
  *
@@ -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, 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>;
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 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>;
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 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>;
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,6 +1,6 @@
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<S> = ParserOptions<S>> {
3
+ export interface NormalizedArguments<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>> {
4
4
  path: string;
5
5
  schema: S;
6
6
  options: O & Options<S>;
@@ -9,5 +9,5 @@ export interface NormalizedArguments<S extends JSONSchema = JSONSchema, O extend
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<S> = ParserOptions<S>>(_args: Partial<IArguments>): NormalizedArguments<S, O>;
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;
@@ -40,7 +40,7 @@ export interface DereferenceOptions {
40
40
  * @param [options] - Overridden options
41
41
  * @class
42
42
  */
43
- export interface $RefParserOptions<S extends JSONSchema = JSONSchema> {
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
  *
@@ -50,9 +50,7 @@ export interface $RefParserOptions<S extends JSONSchema = JSONSchema> {
50
50
  json?: Plugin | boolean;
51
51
  yaml?: Plugin | boolean;
52
52
  binary?: Plugin | boolean;
53
- text?: (Plugin & {
54
- encoding?: string;
55
- }) | boolean;
53
+ text?: Plugin | boolean;
56
54
  [key: string]: Plugin | boolean | undefined;
57
55
  };
58
56
  /**
@@ -88,7 +86,7 @@ export interface $RefParserOptions<S extends JSONSchema = JSONSchema> {
88
86
  mutateInputSchema?: boolean;
89
87
  }
90
88
  export declare const getJsonSchemaRefParserDefaultOptions: () => $RefParserOptions<JSONSchema>;
91
- export declare const getNewOptions: <S extends JSONSchema = JSONSchema, O extends {
89
+ export declare const getNewOptions: <S extends object = JSONSchema, O extends {
92
90
  parse?: {
93
91
  [x: string]: boolean | {
94
92
  name?: string | undefined;
@@ -207,7 +205,7 @@ export declare const getNewOptions: <S extends JSONSchema = JSONSchema, O extend
207
205
  order?: number | undefined;
208
206
  allowEmpty?: boolean | undefined;
209
207
  allowBOM?: boolean | undefined;
210
- encoding?: "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "base64url" | "latin1" | "binary" | "hex" | undefined;
208
+ encoding?: BufferEncoding | undefined;
211
209
  canParse?: string | boolean | {
212
210
  exec?: {} | undefined;
213
211
  test?: {} | undefined;
@@ -488,7 +486,7 @@ export declare const getNewOptions: <S extends JSONSchema = JSONSchema, O extend
488
486
  order?: number | undefined;
489
487
  allowEmpty?: boolean | undefined;
490
488
  allowBOM?: boolean | undefined;
491
- encoding?: "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "base64url" | "latin1" | "binary" | "hex" | undefined;
489
+ encoding?: BufferEncoding | undefined;
492
490
  canParse?: string | boolean | {
493
491
  exec?: {} | undefined;
494
492
  test?: {} | undefined;
@@ -651,6 +649,6 @@ export declare const getNewOptions: <S extends JSONSchema = JSONSchema, O extend
651
649
  } | undefined;
652
650
  mutateInputSchema?: boolean | undefined;
653
651
  }>(options: O | undefined) => O & $RefParserOptions<S>;
654
- export type Options<S extends JSONSchema = JSONSchema> = $RefParserOptions<S>;
655
- export type ParserOptions<S extends JSONSchema = JSONSchema> = DeepPartial<$RefParserOptions<S>>;
652
+ export type Options<S extends object = JSONSchema> = $RefParserOptions<S>;
653
+ export type ParserOptions<S extends object = JSONSchema> = DeepPartial<$RefParserOptions<S>>;
656
654
  export default $RefParserOptions;
@@ -5,5 +5,5 @@ 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 ParserOptions<S> = ParserOptions<S>>(path: string, $refs: $Refs<S, O>, options: O): Promise<string | Buffer | S | undefined>;
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;
@@ -9,7 +9,7 @@ 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, O extends ParserOptions<S> = ParserOptions<S>> {
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
  */
@@ -51,7 +51,7 @@ declare class Pointer<S extends JSONSchema = JSONSchema, O extends ParserOptions
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?: O, pathFromRoot?: string): this;
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, O extends ParserOptions
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?: O): any;
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
@@ -9,7 +9,7 @@ export type $RefError = JSONParserError | ResolverError | ParserError | MissingP
9
9
  *
10
10
  * @class
11
11
  */
12
- declare class $Ref<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>> {
12
+ declare class $Ref<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>> {
13
13
  /**
14
14
  * The file path or URL of the referenced file.
15
15
  * This path is relative to the path of the main JSON schema file.
@@ -109,7 +109,7 @@ declare class $Ref<S extends JSONSchema = JSONSchema, O extends ParserOptions<S>
109
109
  * @param options
110
110
  * @returns
111
111
  */
112
- static isAllowed$Ref<S extends JSONSchema = JSONSchema>(value: unknown, options?: ParserOptions<S>): true | undefined;
112
+ static isAllowed$Ref<S extends object = JSONSchema>(value: unknown, options?: ParserOptions<S>): true | undefined;
113
113
  /**
114
114
  * Determines whether the given value is a JSON reference that "extends" its resolved value.
115
115
  * That is, it has extra properties (in addition to "$ref"), so rather than simply pointing to
@@ -176,6 +176,6 @@ declare class $Ref<S extends JSONSchema = JSONSchema, O extends ParserOptions<S>
176
176
  * @param resolvedValue - The resolved value, which can be any type
177
177
  * @returns - Returns the dereferenced value
178
178
  */
179
- static dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>($ref: $Ref<S, O>, resolvedValue: S): S;
179
+ static dereference<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>($ref: $Ref<S, O>, resolvedValue: S): S;
180
180
  }
181
181
  export default $Ref;
@@ -2,7 +2,7 @@ import $Ref from "./ref.js";
2
2
  import type { JSONSchema4Type, JSONSchema6Type, JSONSchema7Type } from "json-schema";
3
3
  import type { ParserOptions } from "./options.js";
4
4
  import type { JSONSchema } from "./types";
5
- interface $RefsMap<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>> {
5
+ interface $RefsMap<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>> {
6
6
  [url: string]: $Ref<S, O>;
7
7
  }
8
8
  /**
@@ -12,7 +12,7 @@ interface $RefsMap<S extends JSONSchema = JSONSchema, O extends ParserOptions<S>
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, O extends ParserOptions<S> = ParserOptions<S>> {
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
  *
@@ -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<S> = ParserOptions<S>>(parser: $RefParser<S, O>, options: O): Promise<void> | Promise<any[]>;
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;
@@ -4,12 +4,12 @@ import type $Refs from "../refs.js";
4
4
  import type { ParserOptions } from "../options";
5
5
  export type JSONSchema = JSONSchema4 | JSONSchema6 | JSONSchema7;
6
6
  export type JSONSchemaObject = JSONSchema4Object | JSONSchema6Object | JSONSchema7Object;
7
- export type SchemaCallback<S extends JSONSchema = JSONSchema> = (err: Error | null, schema?: S | object | null) => any;
8
- export type $RefsCallback<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>> = (err: Error | null, $refs?: $Refs<S, O>) => any;
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;
9
9
  /**
10
10
  * See https://apitools.dev/json-schema-ref-parser/docs/options.html
11
11
  */
12
- export interface HTTPResolverOptions<S extends JSONSchema = JSONSchema> extends Partial<ResolverOptions<S>> {
12
+ export interface HTTPResolverOptions<S extends object = JSONSchema> extends Partial<ResolverOptions<S>> {
13
13
  /**
14
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.
15
15
  */
@@ -32,7 +32,7 @@ export interface HTTPResolverOptions<S extends JSONSchema = JSONSchema> extends
32
32
  *
33
33
  * See https://apitools.dev/json-schema-ref-parser/docs/plugins/resolvers.html
34
34
  */
35
- export interface ResolverOptions<S extends JSONSchema = JSONSchema> {
35
+ export interface ResolverOptions<S extends object = JSONSchema> {
36
36
  name?: string;
37
37
  /**
38
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 JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>> extends Error {
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 JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(parser: $RefParser<S, O>): JSONParserError[];
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 {
@@ -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, O extends ParserOptions<S> = ParserOptions<S>>(plugins: O["resolve"]): Plugin[];
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 JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>> {
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, O extends Parse
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, O extends ParserOptions<S> = ParserOptions<S>>(plugins: Plugin[], method: keyof Plugin | keyof ResolverOptions<S>, file: FileInfo, $refs: $Refs<S, O>): Promise<PluginResult<S, O>>;
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/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<S> = ParserOptions<S>>(
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,7 +40,7 @@ function bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> =
40
40
  * @param $refs
41
41
  * @param options
42
42
  */
43
- function crawl<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
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,
@@ -102,7 +102,7 @@ function crawl<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = P
102
102
  * @param $refs
103
103
  * @param options
104
104
  */
105
- function inventory$Ref<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
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,
@@ -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<S> = ParserOptions<S>>(
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,7 +48,7 @@ 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<S> = ParserOptions<S>>(
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,
@@ -161,7 +161,7 @@ function crawl<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = P
161
161
  * @param options
162
162
  * @returns
163
163
  */
164
- function dereference$Ref<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
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,
package/lib/index.ts CHANGED
@@ -37,7 +37,7 @@ export type RefParserSchema = string | JSONSchema;
37
37
  *
38
38
  * @class
39
39
  */
40
- export class $RefParser<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>> {
40
+ export class $RefParser<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>> {
41
41
  /**
42
42
  * The parsed (and possibly dereferenced) JSON schema object
43
43
  *
@@ -94,10 +94,10 @@ export class $RefParser<S extends JSONSchema = JSONSchema, O extends ParserOptio
94
94
  if (url.isFileSystemPath(args.path)) {
95
95
  args.path = url.fromFileSystemPath(args.path);
96
96
  pathType = "file";
97
- } else if (!args.path && args.schema && args.schema.$id) {
97
+ } else if (!args.path && args.schema && "$id" in args.schema && args.schema.$id) {
98
98
  // when schema id has defined an URL should use that hostname to request the references,
99
99
  // instead of using the current page URL
100
- const params = url.parse(args.schema.$id);
100
+ const params = url.parse(args.schema.$id as string);
101
101
  const port = params.protocol === "https:" ? 443 : 80;
102
102
 
103
103
  args.path = `${params.protocol}//${params.hostname}:${port}`;
@@ -143,34 +143,34 @@ export class $RefParser<S extends JSONSchema = JSONSchema, O extends ParserOptio
143
143
  }
144
144
  }
145
145
 
146
- public static parse<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
146
+ public static parse<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
147
147
  schema: S | string,
148
148
  ): Promise<S>;
149
- public static parse<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
149
+ public static parse<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
150
150
  schema: S | string,
151
151
  callback: SchemaCallback<S>,
152
152
  ): Promise<void>;
153
- public static parse<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
153
+ public static parse<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
154
154
  schema: S | string,
155
155
  options: O,
156
156
  ): Promise<S>;
157
- public static parse<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
157
+ public static parse<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
158
158
  schema: S | string,
159
159
  options: O,
160
160
  callback: SchemaCallback<S>,
161
161
  ): Promise<void>;
162
- public static parse<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
162
+ public static parse<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
163
163
  baseUrl: string,
164
164
  schema: S | string,
165
165
  options: O,
166
166
  ): Promise<S>;
167
- public static parse<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
167
+ public static parse<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
168
168
  baseUrl: string,
169
169
  schema: S | string,
170
170
  options: O,
171
171
  callback: SchemaCallback<S>,
172
172
  ): Promise<void>;
173
- public static parse<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>():
173
+ public static parse<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>():
174
174
  | Promise<S>
175
175
  | Promise<void> {
176
176
  const parser = new $RefParser<S, O>();
@@ -218,34 +218,34 @@ export class $RefParser<S extends JSONSchema = JSONSchema, O extends ParserOptio
218
218
  * @param options (optional)
219
219
  * @param callback (optional) A callback that will receive a `$Refs` object
220
220
  */
221
- public static resolve<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
221
+ public static resolve<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
222
222
  schema: S | string,
223
223
  ): Promise<$Refs<S, O>>;
224
- public static resolve<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
224
+ public static resolve<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
225
225
  schema: S | string,
226
226
  callback: $RefsCallback<S, O>,
227
227
  ): Promise<void>;
228
- public static resolve<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
228
+ public static resolve<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
229
229
  schema: S | string,
230
230
  options: O,
231
231
  ): Promise<$Refs<S, O>>;
232
- public static resolve<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
232
+ public static resolve<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
233
233
  schema: S | string,
234
234
  options: O,
235
235
  callback: $RefsCallback<S, O>,
236
236
  ): Promise<void>;
237
- public static resolve<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
237
+ public static resolve<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
238
238
  baseUrl: string,
239
239
  schema: S | string,
240
240
  options: O,
241
241
  ): Promise<$Refs<S, O>>;
242
- public static resolve<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
242
+ public static resolve<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
243
243
  baseUrl: string,
244
244
  schema: S | string,
245
245
  options: O,
246
246
  callback: $RefsCallback<S, O>,
247
247
  ): Promise<void>;
248
- static resolve<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>():
248
+ static resolve<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>():
249
249
  | Promise<S>
250
250
  | Promise<void> {
251
251
  const instance = new $RefParser<S, O>();
@@ -263,34 +263,34 @@ export class $RefParser<S extends JSONSchema = JSONSchema, O extends ParserOptio
263
263
  * @param options (optional)
264
264
  * @param callback (optional) A callback that will receive the bundled schema object
265
265
  */
266
- public static bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
266
+ public static bundle<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
267
267
  schema: S | string,
268
268
  ): Promise<S>;
269
- public static bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
269
+ public static bundle<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
270
270
  schema: S | string,
271
271
  callback: SchemaCallback<S>,
272
272
  ): Promise<void>;
273
- public static bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
273
+ public static bundle<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
274
274
  schema: S | string,
275
275
  options: O,
276
276
  ): Promise<S>;
277
- public static bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
277
+ public static bundle<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
278
278
  schema: S | string,
279
279
  options: O,
280
280
  callback: SchemaCallback<S>,
281
281
  ): Promise<void>;
282
- public static bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
282
+ public static bundle<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
283
283
  baseUrl: string,
284
284
  schema: S | string,
285
285
  options: O,
286
286
  ): Promise<S>;
287
- public static bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
287
+ public static bundle<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
288
288
  baseUrl: string,
289
289
  schema: S | string,
290
290
  options: O,
291
291
  callback: SchemaCallback<S>,
292
292
  ): Promise<S>;
293
- static bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>():
293
+ static bundle<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>():
294
294
  | Promise<S>
295
295
  | Promise<void> {
296
296
  const instance = new $RefParser<S, O>();
@@ -337,34 +337,34 @@ export class $RefParser<S extends JSONSchema = JSONSchema, O extends ParserOptio
337
337
  * @param options (optional)
338
338
  * @param callback (optional) A callback that will receive the dereferenced schema object
339
339
  */
340
- public static dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
340
+ public static dereference<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
341
341
  schema: S | string,
342
342
  ): Promise<S>;
343
- public static dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
343
+ public static dereference<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
344
344
  schema: S | string,
345
345
  callback: SchemaCallback<S>,
346
346
  ): Promise<void>;
347
- public static dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
347
+ public static dereference<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
348
348
  schema: S | string,
349
349
  options: O,
350
350
  ): Promise<S>;
351
- public static dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
351
+ public static dereference<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
352
352
  schema: S | string,
353
353
  options: O,
354
354
  callback: SchemaCallback<S>,
355
355
  ): Promise<void>;
356
- public static dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
356
+ public static dereference<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
357
357
  baseUrl: string,
358
358
  schema: S | string,
359
359
  options: O,
360
360
  ): Promise<S>;
361
- public static dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
361
+ public static dereference<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
362
362
  baseUrl: string,
363
363
  schema: S | string,
364
364
  options: O,
365
365
  callback: SchemaCallback<S>,
366
366
  ): Promise<void>;
367
- static dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>():
367
+ static dereference<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>():
368
368
  | Promise<S>
369
369
  | Promise<void> {
370
370
  const instance = new $RefParser<S, O>();
@@ -404,7 +404,7 @@ export class $RefParser<S extends JSONSchema = JSONSchema, O extends ParserOptio
404
404
  }
405
405
  export default $RefParser;
406
406
 
407
- function finalize<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
407
+ function finalize<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
408
408
  parser: $RefParser<S, O>,
409
409
  ) {
410
410
  const errors = JSONParserErrorGroup.getParserErrors(parser);
@@ -4,7 +4,7 @@ import type { JSONSchema, SchemaCallback } from "./types";
4
4
 
5
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
6
  // In the future, I'd like to deprecate the api and accept only named parameters in index.ts
7
- export interface NormalizedArguments<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>> {
7
+ export interface NormalizedArguments<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>> {
8
8
  path: string;
9
9
  schema: S;
10
10
  options: O & Options<S>;
@@ -13,7 +13,7 @@ export interface NormalizedArguments<S extends JSONSchema = JSONSchema, O extend
13
13
  /**
14
14
  * Normalizes the given arguments, accounting for optional args.
15
15
  */
16
- export function normalizeArgs<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
16
+ export function normalizeArgs<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
17
17
  _args: Partial<IArguments>,
18
18
  ): NormalizedArguments<S, O> {
19
19
  let path;
package/lib/options.ts CHANGED
@@ -53,7 +53,7 @@ export interface DereferenceOptions {
53
53
  * @param [options] - Overridden options
54
54
  * @class
55
55
  */
56
- export interface $RefParserOptions<S extends JSONSchema = JSONSchema> {
56
+ export interface $RefParserOptions<S extends object = JSONSchema> {
57
57
  /**
58
58
  * The `parse` options determine how different types of files will be parsed.
59
59
  *
@@ -63,7 +63,7 @@ export interface $RefParserOptions<S extends JSONSchema = JSONSchema> {
63
63
  json?: Plugin | boolean;
64
64
  yaml?: Plugin | boolean;
65
65
  binary?: Plugin | boolean;
66
- text?: (Plugin & { encoding?: string }) | boolean;
66
+ text?: Plugin | boolean;
67
67
  [key: string]: Plugin | boolean | undefined;
68
68
  };
69
69
 
@@ -174,7 +174,7 @@ export const getJsonSchemaRefParserDefaultOptions = () => {
174
174
  return defaults;
175
175
  };
176
176
 
177
- export const getNewOptions = <S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
177
+ export const getNewOptions = <S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
178
178
  options: O | undefined,
179
179
  ): O & $RefParserOptions<S> => {
180
180
  const newOptions = getJsonSchemaRefParserDefaultOptions();
@@ -184,8 +184,8 @@ export const getNewOptions = <S extends JSONSchema = JSONSchema, O extends Parse
184
184
  return newOptions as O & $RefParserOptions<S>;
185
185
  };
186
186
 
187
- export type Options<S extends JSONSchema = JSONSchema> = $RefParserOptions<S>;
188
- export type ParserOptions<S extends JSONSchema = JSONSchema> = DeepPartial<$RefParserOptions<S>>;
187
+ export type Options<S extends object = JSONSchema> = $RefParserOptions<S>;
188
+ export type ParserOptions<S extends object = JSONSchema> = DeepPartial<$RefParserOptions<S>>;
189
189
  /**
190
190
  * Merges the properties of the source object into the target object.
191
191
  *
package/lib/parse.ts CHANGED
@@ -15,7 +15,7 @@ import type { FileInfo, JSONSchema } from "./types/index.js";
15
15
  /**
16
16
  * Reads and parses the specified file path or URL.
17
17
  */
18
- async function parse<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
18
+ async function parse<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
19
19
  path: string,
20
20
  $refs: $Refs<S, O>,
21
21
  options: O,
@@ -70,7 +70,7 @@ async function parse<S extends JSONSchema = JSONSchema, O extends ParserOptions<
70
70
  * @returns
71
71
  * The promise resolves with the raw file contents and the resolver that was used.
72
72
  */
73
- async function readFile<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
73
+ async function readFile<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
74
74
  file: FileInfo,
75
75
  options: O,
76
76
  $refs: $Refs<S, O>,
@@ -116,7 +116,7 @@ async function readFile<S extends JSONSchema = JSONSchema, O extends ParserOptio
116
116
  * @returns
117
117
  * The promise resolves with the parsed file contents and the parser that was used.
118
118
  */
119
- async function parseFile<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
119
+ async function parseFile<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
120
120
  file: FileInfo,
121
121
  options: O,
122
122
  $refs: $Refs<S, O>,
package/lib/pointer.ts CHANGED
@@ -26,7 +26,7 @@ const safeDecodeURIComponent = (encodedURIComponent: string): string => {
26
26
  * @param [friendlyPath] - The original user-specified path (used for error messages)
27
27
  * @class
28
28
  */
29
- class Pointer<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>> {
29
+ class Pointer<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>> {
30
30
  /**
31
31
  * The {@link $Ref} object that contains this {@link Pointer} object.
32
32
  */
@@ -86,7 +86,7 @@ class Pointer<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = Pa
86
86
  * the {@link Pointer#$ref} and {@link Pointer#path} will reflect the resolution path
87
87
  * of the resolved value.
88
88
  */
89
- resolve(obj: any, options?: O, pathFromRoot?: string) {
89
+ resolve(obj: S, options?: O, pathFromRoot?: string) {
90
90
  const tokens = Pointer.parse(this.path, this.originalPath);
91
91
 
92
92
  // Crawl the object, one token at a time
@@ -144,7 +144,7 @@ class Pointer<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = Pa
144
144
  * @returns
145
145
  * Returns the modified object, or an entirely new object if the entire object is overwritten.
146
146
  */
147
- set(obj: any, value: any, options?: O) {
147
+ set(obj: S, value: any, options?: O) {
148
148
  const tokens = Pointer.parse(this.path);
149
149
  let token;
150
150
 
package/lib/ref.ts CHANGED
@@ -13,7 +13,7 @@ export type $RefError = JSONParserError | ResolverError | ParserError | MissingP
13
13
  *
14
14
  * @class
15
15
  */
16
- class $Ref<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>> {
16
+ class $Ref<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>> {
17
17
  /**
18
18
  * The file path or URL of the referenced file.
19
19
  * This path is relative to the path of the main JSON schema file.
@@ -185,7 +185,7 @@ class $Ref<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = Parse
185
185
  * @param options
186
186
  * @returns
187
187
  */
188
- static isAllowed$Ref<S extends JSONSchema = JSONSchema>(value: unknown, options?: ParserOptions<S>) {
188
+ static isAllowed$Ref<S extends object = JSONSchema>(value: unknown, options?: ParserOptions<S>) {
189
189
  if (this.is$Ref(value)) {
190
190
  if (value.$ref.substring(0, 2) === "#/" || value.$ref === "#") {
191
191
  // It's a JSON Pointer reference, which is always allowed
@@ -266,7 +266,7 @@ class $Ref<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = Parse
266
266
  * @param resolvedValue - The resolved value, which can be any type
267
267
  * @returns - Returns the dereferenced value
268
268
  */
269
- static dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
269
+ static dereference<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
270
270
  $ref: $Ref<S, O>,
271
271
  resolvedValue: S,
272
272
  ): S {
package/lib/refs.ts CHANGED
@@ -6,7 +6,7 @@ import type { ParserOptions } from "./options.js";
6
6
  import convertPathToPosix from "./util/convert-path-to-posix";
7
7
  import type { JSONSchema } from "./types";
8
8
 
9
- interface $RefsMap<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>> {
9
+ interface $RefsMap<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>> {
10
10
  [url: string]: $Ref<S, O>;
11
11
  }
12
12
  /**
@@ -16,7 +16,7 @@ interface $RefsMap<S extends JSONSchema = JSONSchema, O extends ParserOptions<S>
16
16
  *
17
17
  * See https://apitools.dev/json-schema-ref-parser/docs/refs.html
18
18
  */
19
- export default class $Refs<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>> {
19
+ export default class $Refs<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>> {
20
20
  /**
21
21
  * 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.
22
22
  *
@@ -215,7 +215,7 @@ export default class $Refs<S extends JSONSchema = JSONSchema, O extends ParserOp
215
215
  * @param [types] - Only return paths of the given types ("file", "http", etc.)
216
216
  * @returns
217
217
  */
218
- function getPaths<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
218
+ function getPaths<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
219
219
  $refs: $RefsMap<S, O>,
220
220
  types: string[],
221
221
  ) {
@@ -18,7 +18,7 @@ import type $RefParser from "./index.js";
18
18
  * The promise resolves once all JSON references in the schema have been resolved,
19
19
  * including nested references that are contained in externally-referenced files.
20
20
  */
21
- function resolveExternal<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
21
+ function resolveExternal<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
22
22
  parser: $RefParser<S, O>,
23
23
  options: O,
24
24
  ) {
@@ -52,7 +52,7 @@ function resolveExternal<S extends JSONSchema = JSONSchema, O extends ParserOpti
52
52
  * If any of the JSON references point to files that contain additional JSON references,
53
53
  * then the corresponding promise will internally reference an array of promises.
54
54
  */
55
- function crawl<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
55
+ function crawl<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
56
56
  obj: string | Buffer | S | undefined | null,
57
57
  path: string,
58
58
  $refs: $Refs<S, O>,
@@ -92,14 +92,14 @@ function crawl<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = P
92
92
  * The promise resolves once all JSON references in the object have been resolved,
93
93
  * including nested references that are contained in externally-referenced files.
94
94
  */
95
- async function resolve$Ref<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
95
+ async function resolve$Ref<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
96
96
  $ref: S,
97
97
  path: string,
98
98
  $refs: $Refs<S, O>,
99
99
  options: O,
100
100
  ) {
101
101
  const shouldResolveOnCwd = options.dereference?.externalReferenceResolution === "root";
102
- const resolvedPath = url.resolve(shouldResolveOnCwd ? url.cwd() : path, $ref.$ref!);
102
+ const resolvedPath = url.resolve(shouldResolveOnCwd ? url.cwd() : path, ($ref as JSONSchema).$ref!);
103
103
  const withoutHash = url.stripHash(resolvedPath);
104
104
 
105
105
  // $ref.$ref = url.relative($refs._root$Ref.path, resolvedPath);
@@ -66,7 +66,7 @@ export default {
66
66
  * @returns
67
67
  * The promise resolves with the raw downloaded data, or rejects if there is an HTTP error.
68
68
  */
69
- async function download<S extends JSONSchema = JSONSchema>(
69
+ async function download<S extends object = JSONSchema>(
70
70
  u: URL | string,
71
71
  httpOptions: HTTPResolverOptions<S>,
72
72
  _redirects?: string[],
@@ -109,7 +109,7 @@ async function download<S extends JSONSchema = JSONSchema>(
109
109
  * Sends an HTTP GET request.
110
110
  * The promise resolves with the HTTP Response object.
111
111
  */
112
- async function get<S extends JSONSchema = JSONSchema>(u: RequestInfo | URL, httpOptions: HTTPResolverOptions<S>) {
112
+ async function get<S extends object = JSONSchema>(u: RequestInfo | URL, httpOptions: HTTPResolverOptions<S>) {
113
113
  let controller: any;
114
114
  let timeoutId: any;
115
115
  if (httpOptions.timeout) {
@@ -11,8 +11,8 @@ import type { ParserOptions } from "../options";
11
11
 
12
12
  export type JSONSchema = JSONSchema4 | JSONSchema6 | JSONSchema7;
13
13
  export type JSONSchemaObject = JSONSchema4Object | JSONSchema6Object | JSONSchema7Object;
14
- export type SchemaCallback<S extends JSONSchema = JSONSchema> = (err: Error | null, schema?: S | object | null) => any;
15
- export type $RefsCallback<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>> = (
14
+ export type SchemaCallback<S extends object = JSONSchema> = (err: Error | null, schema?: S | object | null) => any;
15
+ export type $RefsCallback<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>> = (
16
16
  err: Error | null,
17
17
  $refs?: $Refs<S, O>,
18
18
  ) => any;
@@ -21,7 +21,7 @@ export type $RefsCallback<S extends JSONSchema = JSONSchema, O extends ParserOpt
21
21
  * See https://apitools.dev/json-schema-ref-parser/docs/options.html
22
22
  */
23
23
 
24
- export interface HTTPResolverOptions<S extends JSONSchema = JSONSchema> extends Partial<ResolverOptions<S>> {
24
+ export interface HTTPResolverOptions<S extends object = JSONSchema> extends Partial<ResolverOptions<S>> {
25
25
  /**
26
26
  * 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.
27
27
  */
@@ -48,7 +48,7 @@ export interface HTTPResolverOptions<S extends JSONSchema = JSONSchema> extends
48
48
  *
49
49
  * See https://apitools.dev/json-schema-ref-parser/docs/plugins/resolvers.html
50
50
  */
51
- export interface ResolverOptions<S extends JSONSchema = JSONSchema> {
51
+ export interface ResolverOptions<S extends object = JSONSchema> {
52
52
  name?: string;
53
53
  /**
54
54
  * 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.
@@ -38,7 +38,7 @@ export class JSONParserError extends Error {
38
38
  }
39
39
 
40
40
  export class JSONParserErrorGroup<
41
- S extends JSONSchema = JSONSchema,
41
+ S extends object = JSONSchema,
42
42
  O extends ParserOptions<S> = ParserOptions<S>,
43
43
  > extends Error {
44
44
  files: $RefParser<S, O>;
@@ -55,7 +55,7 @@ export class JSONParserErrorGroup<
55
55
  Ono.extend(this);
56
56
  }
57
57
 
58
- static getParserErrors<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
58
+ static getParserErrors<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
59
59
  parser: $RefParser<S, O>,
60
60
  ) {
61
61
  const errors = [];
@@ -10,7 +10,7 @@ import type { Plugin } from "../types/index.js";
10
10
  *
11
11
  * @returns
12
12
  */
13
- export function all<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
13
+ export function all<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
14
14
  plugins: O["resolve"],
15
15
  ): Plugin[] {
16
16
  return (Object.keys(plugins || {}) as (keyof ResolverOptions<S>)[])
@@ -45,7 +45,7 @@ export function sort(plugins: Plugin[]) {
45
45
  });
46
46
  }
47
47
 
48
- export interface PluginResult<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>> {
48
+ export interface PluginResult<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>> {
49
49
  plugin: Plugin;
50
50
  result?: string | Buffer | S;
51
51
  error?: any;
@@ -59,7 +59,7 @@ export interface PluginResult<S extends JSONSchema = JSONSchema, O extends Parse
59
59
  * If the promise rejects, or the callback is called with an error, then the next plugin is called.
60
60
  * If ALL plugins fail, then the last error is thrown.
61
61
  */
62
- export async function run<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
62
+ export async function run<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
63
63
  plugins: Plugin[],
64
64
  method: keyof Plugin | keyof ResolverOptions<S>,
65
65
  file: FileInfo,
@@ -129,7 +129,7 @@ export async function run<S extends JSONSchema = JSONSchema, O extends ParserOpt
129
129
  * If the value is a RegExp, then it will be tested against the file URL.
130
130
  * If the value is an array, then it will be compared against the file extension.
131
131
  */
132
- function getResult<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
132
+ function getResult<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
133
133
  obj: Plugin,
134
134
  prop: keyof Plugin | keyof ResolverOptions<S>,
135
135
  file: FileInfo,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apidevtools/json-schema-ref-parser",
3
- "version": "11.5.3",
3
+ "version": "11.5.5",
4
4
  "description": "Parse, Resolve, and Dereference JSON Schema $ref pointers",
5
5
  "keywords": [
6
6
  "json",
@@ -67,12 +67,12 @@
67
67
  "test:watch": "vitest -w"
68
68
  },
69
69
  "devDependencies": {
70
- "@types/eslint": "8.56.5",
70
+ "@types/eslint": "8.56.9",
71
71
  "@types/js-yaml": "^4.0.9",
72
72
  "@types/node": "^18.19.21",
73
- "@typescript-eslint/eslint-plugin": "^7.1.1",
74
- "@typescript-eslint/parser": "^7.1.1",
75
- "@vitest/coverage-v8": "^1.3.1",
73
+ "@typescript-eslint/eslint-plugin": "^7.6.0",
74
+ "@typescript-eslint/parser": "^7.6.0",
75
+ "@vitest/coverage-v8": "^1.5.0",
76
76
  "cross-env": "^7.0.3",
77
77
  "eslint": "^8.57.0",
78
78
  "eslint-config-prettier": "^9.1.0",
@@ -84,8 +84,8 @@
84
84
  "jsdom": "^24.0.0",
85
85
  "prettier": "^3.2.5",
86
86
  "rimraf": "^5.0.5",
87
- "typescript": "^5.4.2",
88
- "vitest": "^1.3.1"
87
+ "typescript": "^5.4.5",
88
+ "vitest": "^1.5.0"
89
89
  },
90
90
  "dependencies": {
91
91
  "@jsdevtools/ono": "^7.1.3",