Skip to content

Commit bdb426b

Browse files
committed
fix(types): add generics to the normalize args, clean up comments in index
1 parent 51b0b0d commit bdb426b

File tree

2 files changed

+5
-60
lines changed

2 files changed

+5
-60
lines changed

lib/index.ts

-55
Original file line numberDiff line numberDiff line change
@@ -178,19 +178,6 @@ export class $RefParser {
178178
options: ParserOptions,
179179
callback: $RefsCallback,
180180
): Promise<void>;
181-
/**
182-
* Parses the given JSON schema and resolves any JSON references, including references in
183-
* externally-referenced files.
184-
*
185-
* @param [path] - The file path or URL of the JSON schema
186-
* @param [schema] - A JSON schema object. This object will be used instead of reading from `path`.
187-
* @param [options] - Options that determine how the schema is parsed and resolved
188-
* @param [callback]
189-
* - An error-first callback. The second parameter is a {@link $Refs} object containing the resolved JSON references
190-
*
191-
* @returns
192-
* The returned promise resolves with a {@link $Refs} object containing the resolved JSON references
193-
*/
194181
async resolve() {
195182
const args = normalizeArgs(arguments);
196183

@@ -231,17 +218,6 @@ export class $RefParser {
231218
return instance.resolve.apply(instance, arguments as any);
232219
}
233220

234-
/**
235-
* Parses the given JSON schema, resolves any JSON references, and bundles all external references
236-
* into the main JSON schema. This produces a JSON schema that only has *internal* references,
237-
* not any *external* references.
238-
*
239-
* @param [path] - The file path or URL of the JSON schema
240-
* @param [schema] - A JSON schema object. This object will be used instead of reading from `path`.
241-
* @param [options] - Options that determine how the schema is parsed, resolved, and dereferenced
242-
* @param [callback] - An error-first callback. The second parameter is the bundled JSON schema object
243-
* @returns - The returned promise resolves with the bundled JSON schema object.
244-
*/
245221
/**
246222
* 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.
247223
*
@@ -269,17 +245,6 @@ export class $RefParser {
269245
return instance.bundle.apply(instance, arguments as any);
270246
}
271247

272-
/**
273-
* Parses the given JSON schema, resolves any JSON references, and bundles all external references
274-
* into the main JSON schema. This produces a JSON schema that only has *internal* references,
275-
* not any *external* references.
276-
*
277-
* @param [path] - The file path or URL of the JSON schema
278-
* @param [schema] - A JSON schema object. This object will be used instead of reading from `path`.
279-
* @param [options] - Options that determine how the schema is parsed, resolved, and dereferenced
280-
* @param [callback] - An error-first callback. The second parameter is the bundled JSON schema object
281-
* @returns - The returned promise resolves with the bundled JSON schema object.
282-
*/
283248
/**
284249
* 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.
285250
*
@@ -314,16 +279,6 @@ export class $RefParser {
314279
}
315280
}
316281

317-
/**
318-
* Parses the given JSON schema, resolves any JSON references, and dereferences the JSON schema.
319-
* That is, all JSON references are replaced with their resolved values.
320-
*
321-
* @param [path] - The file path or URL of the JSON schema
322-
* @param [schema] - A JSON schema object. This object will be used instead of reading from `path`.
323-
* @param [options] - Options that determine how the schema is parsed, resolved, and dereferenced
324-
* @param [callback] - An error-first callback. The second parameter is the dereferenced JSON schema object
325-
* @returns - The returned promise resolves with the dereferenced JSON schema object.
326-
*/
327282
/**
328283
* 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.
329284
*
@@ -351,16 +306,6 @@ export class $RefParser {
351306
return instance.dereference.apply(instance, arguments as any);
352307
}
353308

354-
/**
355-
* Parses the given JSON schema, resolves any JSON references, and dereferences the JSON schema.
356-
* That is, all JSON references are replaced with their resolved values.
357-
*
358-
* @param [path] - The file path or URL of the JSON schema
359-
* @param [schema] - A JSON schema object. This object will be used instead of reading from `path`.
360-
* @param [options] - Options that determine how the schema is parsed, resolved, and dereferenced
361-
* @param [callback] - An error-first callback. The second parameter is the dereferenced JSON schema object
362-
* @returns - The returned promise resolves with the dereferenced JSON schema object.
363-
*/
364309
/**
365310
* 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.
366311
*

lib/normalize-args.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,18 @@ import { getNewOptions } from "./options.js";
22
import type { JSONSchema, SchemaCallback } from "./types";
33
import type $RefParserOptions from "./options";
44

5-
export default normalizeArgs;
6-
75
// 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
86
// In the future, I'd like to deprecate the api and accept only named parameters in index.ts
9-
export interface NormalizedArguments {
7+
export interface NormalizedArguments<T = $RefParserOptions> {
108
path: string;
119
schema: JSONSchema;
12-
options: $RefParserOptions;
10+
options: T;
1311
callback: SchemaCallback;
1412
}
1513
/**
1614
* Normalizes the given arguments, accounting for optional args.
1715
*/
18-
function normalizeArgs(_args: Partial<IArguments>): NormalizedArguments {
16+
export function normalizeArgs<T = $RefParserOptions>(_args: Partial<IArguments>): NormalizedArguments<T> {
1917
let path, schema, options, callback;
2018
const args = Array.prototype.slice.call(_args) as any[];
2119

@@ -61,3 +59,5 @@ function normalizeArgs(_args: Partial<IArguments>): NormalizedArguments {
6159
callback,
6260
};
6361
}
62+
63+
export default normalizeArgs;

0 commit comments

Comments
 (0)