@apidevtools/json-schema-ref-parser 11.5.2 → 11.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,17 +7,21 @@ import type {
7
7
  JSONSchema7Object,
8
8
  } from "json-schema";
9
9
  import type $Refs from "../refs.js";
10
+ import type { ParserOptions } from "../options";
10
11
 
11
12
  export type JSONSchema = JSONSchema4 | JSONSchema6 | JSONSchema7;
12
13
  export type JSONSchemaObject = JSONSchema4Object | JSONSchema6Object | JSONSchema7Object;
13
- export type SchemaCallback<S extends JSONSchema = JSONSchema> = (err: Error | null, schema?: S | object | null) => any;
14
- export type $RefsCallback<S extends JSONSchema = JSONSchema> = (err: Error | null, $refs?: $Refs<S>) => any;
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
+ err: Error | null,
17
+ $refs?: $Refs<S, O>,
18
+ ) => any;
15
19
 
16
20
  /**
17
21
  * See https://apitools.dev/json-schema-ref-parser/docs/options.html
18
22
  */
19
23
 
20
- export interface HTTPResolverOptions<S extends JSONSchema = JSONSchema> extends Partial<ResolverOptions<S>> {
24
+ export interface HTTPResolverOptions<S extends object = JSONSchema> extends Partial<ResolverOptions<S>> {
21
25
  /**
22
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.
23
27
  */
@@ -44,7 +48,7 @@ export interface HTTPResolverOptions<S extends JSONSchema = JSONSchema> extends
44
48
  *
45
49
  * See https://apitools.dev/json-schema-ref-parser/docs/plugins/resolvers.html
46
50
  */
47
- export interface ResolverOptions<S extends JSONSchema = JSONSchema> {
51
+ export interface ResolverOptions<S extends object = JSONSchema> {
48
52
  name?: string;
49
53
  /**
50
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,8 +38,8 @@ export class JSONParserError extends Error {
38
38
  }
39
39
 
40
40
  export class JSONParserErrorGroup<
41
- S extends JSONSchema = JSONSchema,
42
- O extends ParserOptions = ParserOptions,
41
+ S extends object = JSONSchema,
42
+ O extends ParserOptions<S> = ParserOptions<S>,
43
43
  > extends Error {
44
44
  files: $RefParser<S, O>;
45
45
 
@@ -55,12 +55,12 @@ export class JSONParserErrorGroup<
55
55
  Ono.extend(this);
56
56
  }
57
57
 
58
- static getParserErrors<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
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 = [];
62
62
 
63
- for (const $ref of Object.values(parser.$refs._$refs) as $Ref<S>[]) {
63
+ for (const $ref of Object.values(parser.$refs._$refs) as $Ref<S, O>[]) {
64
64
  if ($ref.errors) {
65
65
  errors.push(...$ref.errors);
66
66
  }
@@ -78,7 +78,7 @@ export class JSONParserErrorGroup<
78
78
  | UnmatchedParserError
79
79
  | UnmatchedResolverError
80
80
  > {
81
- return JSONParserErrorGroup.getParserErrors<S>(this.files);
81
+ return JSONParserErrorGroup.getParserErrors<S, O>(this.files);
82
82
  }
83
83
  }
84
84
 
@@ -1,5 +1,5 @@
1
1
  import type { FileInfo, JSONSchema } from "../types/index.js";
2
- import type $RefParserOptions from "../options.js";
2
+ import type { ParserOptions } from "../options.js";
3
3
  import type { ResolverOptions } from "../types/index.js";
4
4
  import type $Refs from "../refs.js";
5
5
  import type { Plugin } from "../types/index.js";
@@ -10,14 +10,16 @@ import type { Plugin } from "../types/index.js";
10
10
  *
11
11
  * @returns
12
12
  */
13
- export function all<S extends JSONSchema = JSONSchema>(plugins: $RefParserOptions<S>["resolve"]): Plugin[] {
14
- return Object.keys(plugins)
13
+ export function all<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
14
+ plugins: O["resolve"],
15
+ ): Plugin[] {
16
+ return (Object.keys(plugins || {}) as (keyof ResolverOptions<S>)[])
15
17
  .filter((key) => {
16
- return typeof plugins[key] === "object";
18
+ return typeof plugins![key] === "object";
17
19
  })
18
20
  .map((key) => {
19
- (plugins[key] as ResolverOptions<S>)!.name = key;
20
- return plugins[key] as Plugin;
21
+ (plugins![key] as ResolverOptions<S>)!.name = key;
22
+ return plugins![key] as Plugin;
21
23
  });
22
24
  }
23
25
 
@@ -43,7 +45,7 @@ export function sort(plugins: Plugin[]) {
43
45
  });
44
46
  }
45
47
 
46
- export interface PluginResult<S extends JSONSchema = JSONSchema> {
48
+ export interface PluginResult<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>> {
47
49
  plugin: Plugin;
48
50
  result?: string | Buffer | S;
49
51
  error?: any;
@@ -57,17 +59,17 @@ export interface PluginResult<S extends JSONSchema = JSONSchema> {
57
59
  * If the promise rejects, or the callback is called with an error, then the next plugin is called.
58
60
  * If ALL plugins fail, then the last error is thrown.
59
61
  */
60
- export async function run<S extends JSONSchema = JSONSchema>(
62
+ export async function run<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
61
63
  plugins: Plugin[],
62
64
  method: keyof Plugin | keyof ResolverOptions<S>,
63
65
  file: FileInfo,
64
- $refs: $Refs<S>,
66
+ $refs: $Refs<S, O>,
65
67
  ) {
66
68
  let plugin: Plugin;
67
- let lastError: PluginResult<S>;
69
+ let lastError: PluginResult<S, O>;
68
70
  let index = 0;
69
71
 
70
- return new Promise<PluginResult<S>>((resolve, reject) => {
72
+ return new Promise<PluginResult<S, O>>((resolve, reject) => {
71
73
  runNextPlugin();
72
74
 
73
75
  function runNextPlugin() {
@@ -94,7 +96,7 @@ export async function run<S extends JSONSchema = JSONSchema>(
94
96
  }
95
97
  }
96
98
 
97
- function callback(err: PluginResult<S>["error"], result: PluginResult<S>["result"]) {
99
+ function callback(err: PluginResult<S, O>["error"], result: PluginResult<S, O>["result"]) {
98
100
  if (err) {
99
101
  onError(err);
100
102
  } else {
@@ -102,7 +104,7 @@ export async function run<S extends JSONSchema = JSONSchema>(
102
104
  }
103
105
  }
104
106
 
105
- function onSuccess(result: PluginResult<S>["result"]) {
107
+ function onSuccess(result: PluginResult<S, O>["result"]) {
106
108
  // console.log(' success');
107
109
  resolve({
108
110
  plugin,
@@ -110,7 +112,7 @@ export async function run<S extends JSONSchema = JSONSchema>(
110
112
  });
111
113
  }
112
114
 
113
- function onError(error: PluginResult<S>["error"]) {
115
+ function onError(error: PluginResult<S, O>["error"]) {
114
116
  // console.log(' %s', err.message || err);
115
117
  lastError = {
116
118
  plugin,
@@ -127,12 +129,12 @@ export async function run<S extends JSONSchema = JSONSchema>(
127
129
  * If the value is a RegExp, then it will be tested against the file URL.
128
130
  * If the value is an array, then it will be compared against the file extension.
129
131
  */
130
- function getResult<S extends JSONSchema = JSONSchema>(
132
+ function getResult<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
131
133
  obj: Plugin,
132
134
  prop: keyof Plugin | keyof ResolverOptions<S>,
133
135
  file: FileInfo,
134
136
  callback?: (err?: Error, result?: any) => void,
135
- $refs?: any,
137
+ $refs?: $Refs<S, O>,
136
138
  ) {
137
139
  const value = obj[prop as keyof typeof obj] as unknown;
138
140
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apidevtools/json-schema-ref-parser",
3
- "version": "11.5.2",
3
+ "version": "11.5.4",
4
4
  "description": "Parse, Resolve, and Dereference JSON Schema $ref pointers",
5
5
  "keywords": [
6
6
  "json",