Skip to content

Commit be3f009

Browse files
committed
Restore original types
1 parent ae7a9bb commit be3f009

File tree

3 files changed

+6
-182
lines changed

3 files changed

+6
-182
lines changed

lib/index.d.ts

+4-180
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { OpenAPI } from "openapi-types";
22

3+
export = SwaggerParser;
4+
35
/**
46
* This is the default export of Swagger Parser. You can creates instances of this class using new SwaggerParser(), or you can just call its static methods.
57
*
68
* See https://apitools.dev/swagger-parser/docs/swagger-parser.html
79
*/
8-
export class SwaggerParser {
10+
declare class SwaggerParser {
911

1012
/**
1113
* The `api` property is the parsed/bundled/dereferenced OpenAPI definition. This is the same value that is passed to the callback function (or Promise) when calling the parse, bundle, or dereference methods.
@@ -203,7 +205,7 @@ export class SwaggerParser {
203205
}
204206

205207
// eslint-disable-next-line no-redeclare
206-
export namespace SwaggerParser {
208+
declare namespace SwaggerParser {
207209

208210
export type ApiCallback = (err: Error | null, api?: OpenAPI.Document) => any;
209211
export type $RefsCallback = (err: Error | null, $refs?: $Refs) => any;
@@ -435,181 +437,3 @@ export namespace SwaggerParser {
435437
}
436438

437439
}
438-
439-
/**
440-
* Parses, dereferences, and validates the given Swagger API.
441-
* Depending on the options, validation can include JSON Schema validation and/or Swagger Spec validation.
442-
*
443-
* See https://apitools.dev/swagger-parser/docs/swagger-parser.html#validateapi-options-callback
444-
*
445-
* @param api An OpenAPI definition, or the file path or URL of an OpenAPI definition. See the `parse` method for more info.
446-
* @param options (optional)
447-
* @param callback (optional) A callback that will receive the dereferenced OpenAPI definition
448-
*/
449-
export function validate(api: string | OpenAPI.Document, callback: SwaggerParser.ApiCallback): void;
450-
export function validate(api: string | OpenAPI.Document, options: SwaggerParser.Options, callback: SwaggerParser.ApiCallback): void;
451-
export function validate(baseUrl: string, api: string | OpenAPI.Document, options: SwaggerParser.Options, callback: SwaggerParser.ApiCallback): void;
452-
export function validate(api: string | OpenAPI.Document): Promise<OpenAPI.Document>;
453-
export function validate(api: string | OpenAPI.Document, options: SwaggerParser.Options): Promise<OpenAPI.Document>;
454-
export function validate(baseUrl: string, api: string | OpenAPI.Document, options: SwaggerParser.Options): Promise<OpenAPI.Document>;
455-
456-
/**
457-
* Parses, dereferences, and validates the given Swagger API.
458-
* Depending on the options, validation can include JSON Schema validation and/or Swagger Spec validation.
459-
*
460-
* See https://apitools.dev/swagger-parser/docs/swagger-parser.html#validateapi-options-callback
461-
*
462-
* @param api An OpenAPI definition, or the file path or URL of an OpenAPI definition. See the `parse` method for more info.
463-
* @param options (optional)
464-
* @param callback (optional) A callback that will receive the dereferenced OpenAPI definition
465-
*/
466-
export function validate(api: string | OpenAPI.Document, callback: SwaggerParser.ApiCallback): void;
467-
export function validate(api: string | OpenAPI.Document, options: SwaggerParser.Options, callback: SwaggerParser.ApiCallback): void;
468-
export function validate(baseUrl: string, api: string | OpenAPI.Document, options: SwaggerParser.Options, callback: SwaggerParser.ApiCallback): void;
469-
export function validate(api: string | OpenAPI.Document): Promise<OpenAPI.Document>;
470-
export function validate(api: string | OpenAPI.Document, options: SwaggerParser.Options): Promise<OpenAPI.Document>;
471-
export function validate(baseUrl: string, api: string | OpenAPI.Document, options: SwaggerParser.Options): Promise<OpenAPI.Document>;
472-
473-
/**
474-
* Dereferences all `$ref` pointers in the OpenAPI definition, replacing each reference with its resolved value. This results in an API definition 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.
475-
*
476-
* The dereference method maintains object reference equality, meaning that all `$ref` pointers that point to the same object will be replaced with references to the same object. Again, this is great for programmatic usage, but it does introduce the risk of circular references, so be careful if you intend to serialize the API definition using `JSON.stringify()`. Consider using the bundle method instead, which does not create circular references.
477-
*
478-
* See https://apitools.dev/swagger-parser/docs/swagger-parser.html#dereferenceapi-options-callback
479-
*
480-
* @param api An OpenAPI definition, or the file path or URL of an OpenAPI definition. See the `parse` method for more info.
481-
* @param options (optional)
482-
* @param callback (optional) A callback that will receive the dereferenced OpenAPI definition
483-
*/
484-
export function dereference(api: string | OpenAPI.Document, callback: SwaggerParser.ApiCallback): void;
485-
export function dereference(api: string | OpenAPI.Document, options: SwaggerParser.Options, callback: SwaggerParser.ApiCallback): void;
486-
export function dereference(baseUrl: string, api: string | OpenAPI.Document, options: SwaggerParser.Options, callback: SwaggerParser.ApiCallback): void;
487-
export function dereference(api: string | OpenAPI.Document): Promise<OpenAPI.Document>;
488-
export function dereference(api: string | OpenAPI.Document, options: SwaggerParser.Options): Promise<OpenAPI.Document>;
489-
export function dereference(baseUrl: string, api: string | OpenAPI.Document, options: SwaggerParser.Options): Promise<OpenAPI.Document>;
490-
491-
/**
492-
* Dereferences all `$ref` pointers in the OpenAPI definition, replacing each reference with its resolved value. This results in an API definition 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.
493-
*
494-
* The dereference method maintains object reference equality, meaning that all `$ref` pointers that point to the same object will be replaced with references to the same object. Again, this is great for programmatic usage, but it does introduce the risk of circular references, so be careful if you intend to serialize the API definition using `JSON.stringify()`. Consider using the bundle method instead, which does not create circular references.
495-
*
496-
* See https://apitools.dev/swagger-parser/docs/swagger-parser.html#dereferenceapi-options-callback
497-
*
498-
* @param api An OpenAPI definition, or the file path or URL of an OpenAPI definition. See the `parse` method for more info.
499-
* @param options (optional)
500-
* @param callback (optional) A callback that will receive the dereferenced OpenAPI definition
501-
*/
502-
export function dereference(api: string | OpenAPI.Document, callback: SwaggerParser.ApiCallback): void;
503-
export function dereference(api: string | OpenAPI.Document, options: SwaggerParser.Options, callback: SwaggerParser.ApiCallback): void;
504-
export function dereference(baseUrl: string, api: string | OpenAPI.Document, options: SwaggerParser.Options, callback: SwaggerParser.ApiCallback): void;
505-
export function dereference(api: string | OpenAPI.Document): Promise<OpenAPI.Document>;
506-
export function dereference(api: string | OpenAPI.Document, options: SwaggerParser.Options): Promise<OpenAPI.Document>;
507-
export function dereference(baseUrl: string, api: string | OpenAPI.Document, options: SwaggerParser.Options): Promise<OpenAPI.Document>;
508-
509-
/**
510-
* Bundles all referenced files/URLs into a single API definition that only has internal `$ref` pointers. This lets you split-up your API definition however you want while you're building it, but easily combine all those files together when it's time to package or distribute the API definition to other people. The resulting API definition size will be small, since it will still contain internal JSON references rather than being fully-dereferenced.
511-
*
512-
* This also eliminates the risk of circular references, so the API definition can be safely serialized using `JSON.stringify()`.
513-
*
514-
* See https://apitools.dev/swagger-parser/docs/swagger-parser.html#bundleapi-options-callback
515-
*
516-
* @param api An OpenAPI definition, or the file path or URL of an OpenAPI definition. See the `parse` method for more info.
517-
* @param options (optional)
518-
* @param callback (optional) A callback that will receive the bundled API definition object
519-
*/
520-
export function bundle(api: string | OpenAPI.Document, callback: SwaggerParser.ApiCallback): void;
521-
export function bundle(api: string | OpenAPI.Document, options: SwaggerParser.Options, callback: SwaggerParser.ApiCallback): void;
522-
export function bundle(baseUrl: string, api: string | OpenAPI.Document, options: SwaggerParser.Options, callback: SwaggerParser.ApiCallback): void;
523-
export function bundle(api: string | OpenAPI.Document): Promise<OpenAPI.Document>;
524-
export function bundle(api: string | OpenAPI.Document, options: SwaggerParser.Options): Promise<OpenAPI.Document>;
525-
export function bundle(baseUrl: string, api: string | OpenAPI.Document, options: SwaggerParser.Options): Promise<OpenAPI.Document>;
526-
527-
/**
528-
* Bundles all referenced files/URLs into a single API definition that only has internal `$ref` pointers. This lets you split-up your API definition however you want while you're building it, but easily combine all those files together when it's time to package or distribute the API definition to other people. The resulting API definition size will be small, since it will still contain internal JSON references rather than being fully-dereferenced.
529-
*
530-
* This also eliminates the risk of circular references, so the API definition can be safely serialized using `JSON.stringify()`.
531-
*
532-
* See https://apitools.dev/swagger-parser/docs/swagger-parser.html#bundleapi-options-callback
533-
*
534-
* @param api An OpenAPI definition, or the file path or URL of an OpenAPI definition. See the `parse` method for more info.
535-
* @param options (optional)
536-
* @param callback (optional) A callback that will receive the bundled API definition object
537-
*/
538-
export function bundle(api: string | OpenAPI.Document, callback: SwaggerParser.ApiCallback): void;
539-
export function bundle(api: string | OpenAPI.Document, options: SwaggerParser.Options, callback: SwaggerParser.ApiCallback): void;
540-
export function bundle(baseUrl: string, api: string | OpenAPI.Document, options: SwaggerParser.Options, callback: SwaggerParser.ApiCallback): void;
541-
export function bundle(api: string | OpenAPI.Document): Promise<OpenAPI.Document>;
542-
export function bundle(api: string | OpenAPI.Document, options: SwaggerParser.Options): Promise<OpenAPI.Document>;
543-
export function bundle(baseUrl: string, api: string | OpenAPI.Document, options: SwaggerParser.Options): Promise<OpenAPI.Document>;
544-
545-
/**
546-
* *This method is used internally by other methods, such as `bundle` and `dereference`. You probably won't need to call this method yourself.*
547-
*
548-
* Parses the given OpenAPI definition file (in JSON or YAML format), and returns it as a JavaScript object. This method `does not` resolve `$ref` pointers or dereference anything. It simply parses one file and returns it.
549-
*
550-
* See https://apitools.dev/swagger-parser/docs/swagger-parser.html#parseapi-options-callback
551-
*
552-
* @param api An OpenAPI definition, or the file path or URL of an OpenAPI definition. The path can be absolute or relative. In Node, the path is relative to `process.cwd()`. In the browser, it's relative to the URL of the page.
553-
* @param options (optional)
554-
* @param callback (optional) A callback that will receive the parsed OpenAPI definition object, or an error
555-
*/
556-
export function parse(api: string | OpenAPI.Document, callback: SwaggerParser.ApiCallback): void;
557-
export function parse(api: string | OpenAPI.Document, options: SwaggerParser.Options, callback: SwaggerParser.ApiCallback): void;
558-
export function parse(baseUrl: string, api: string | OpenAPI.Document, options: SwaggerParser.Options, callback: SwaggerParser.ApiCallback): void;
559-
export function parse(api: string | OpenAPI.Document): Promise<OpenAPI.Document>;
560-
export function parse(api: string | OpenAPI.Document, options: SwaggerParser.Options): Promise<OpenAPI.Document>;
561-
export function parse(baseUrl: string, api: string | OpenAPI.Document, options: SwaggerParser.Options): Promise<OpenAPI.Document>;
562-
563-
/**
564-
* *This method is used internally by other methods, such as `bundle` and `dereference`. You probably won't need to call this method yourself.*
565-
*
566-
* Parses the given OpenAPI definition file (in JSON or YAML format), and returns it as a JavaScript object. This method `does not` resolve `$ref` pointers or dereference anything. It simply parses one file and returns it.
567-
*
568-
* See https://apitools.dev/swagger-parser/docs/swagger-parser.html#parseapi-options-callback
569-
*
570-
* @param api An OpenAPI definition, or the file path or URL of an OpenAPI definition. The path can be absolute or relative. In Node, the path is relative to `process.cwd()`. In the browser, it's relative to the URL of the page.
571-
* @param options (optional)
572-
* @param callback (optional) A callback that will receive the parsed OpenAPI definition object, or an error
573-
*/
574-
export function parse(api: string | OpenAPI.Document, callback: SwaggerParser.ApiCallback): void;
575-
export function parse(api: string | OpenAPI.Document, options: SwaggerParser.Options, callback: SwaggerParser.ApiCallback): void;
576-
export function parse(baseUrl: string, api: string | OpenAPI.Document, options: SwaggerParser.Options, callback: SwaggerParser.ApiCallback): void;
577-
export function parse(api: string | OpenAPI.Document): Promise<OpenAPI.Document>;
578-
export function parse(api: string | OpenAPI.Document, options: SwaggerParser.Options): Promise<OpenAPI.Document>;
579-
export function parse(baseUrl: string, api: string | OpenAPI.Document, options: SwaggerParser.Options): Promise<OpenAPI.Document>;
580-
581-
/**
582-
* *This method is used internally by other methods, such as `bundle` and `dereference`. You probably won't need to call this method yourself.*
583-
*
584-
* Resolves all JSON references (`$ref` pointers) in the given OpenAPI definition file. If it references any other files/URLs, then they will be downloaded and resolved as well. This method **does not** dereference anything. It simply gives you a `$Refs` object, which is a map of all the resolved references and their values.
585-
*
586-
* See https://apitools.dev/swagger-parser/docs/swagger-parser.html#resolveapi-options-callback
587-
*
588-
* @param api An OpenAPI definition, or the file path or URL of an OpenAPI definition. See the `parse` method for more info.
589-
* @param options (optional)
590-
* @param callback (optional) A callback that will receive a `$Refs` object
591-
*/
592-
export function resolve(api: string | OpenAPI.Document, callback: SwaggerParser.$RefsCallback): void;
593-
export function resolve(api: string | OpenAPI.Document, options: SwaggerParser.Options, callback: SwaggerParser.$RefsCallback): void;
594-
export function resolve(baseUrl: string, api: string | OpenAPI.Document, options: SwaggerParser.Options, callback: SwaggerParser.$RefsCallback): void;
595-
export function resolve(api: string | OpenAPI.Document): Promise<SwaggerParser.$Refs>;
596-
export function resolve(api: string | OpenAPI.Document, options: SwaggerParser.Options): Promise<SwaggerParser.$Refs>;
597-
export function resolve(baseUrl: string, api: string | OpenAPI.Document, options: SwaggerParser.Options): Promise<SwaggerParser.$Refs>;
598-
599-
/**
600-
* *This method is used internally by other methods, such as `bundle` and `dereference`. You probably won't need to call this method yourself.*
601-
*
602-
* Resolves all JSON references (`$ref` pointers) in the given OpenAPI definition file. If it references any other files/URLs, then they will be downloaded and resolved as well. This method **does not** dereference anything. It simply gives you a `$Refs` object, which is a map of all the resolved references and their values.
603-
*
604-
* See https://apitools.dev/swagger-parser/docs/swagger-parser.html#resolveapi-options-callback
605-
*
606-
* @param api An OpenAPI definition, or the file path or URL of an OpenAPI definition. See the `parse` method for more info.
607-
* @param options (optional)
608-
* @param callback (optional) A callback that will receive a `$Refs` object
609-
*/
610-
export function resolve(api: string | OpenAPI.Document, callback: SwaggerParser.$RefsCallback): void;
611-
export function resolve(api: string | OpenAPI.Document, options: SwaggerParser.Options, callback: SwaggerParser.$RefsCallback): void;
612-
export function resolve(baseUrl: string, api: string | OpenAPI.Document, options: SwaggerParser.Options, callback: SwaggerParser.$RefsCallback): void;
613-
export function resolve(api: string | OpenAPI.Document): Promise<SwaggerParser.$Refs>;
614-
export function resolve(api: string | OpenAPI.Document, options: SwaggerParser.Options): Promise<SwaggerParser.$Refs>;
615-
export function resolve(baseUrl: string, api: string | OpenAPI.Document, options: SwaggerParser.Options): Promise<SwaggerParser.$Refs>;

test/specs/callbacks-promises/callbacks-promises.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe("Callback & Promise syntax", () => {
2020

2121
function testCallbackSuccess (method) {
2222
return function (done) {
23-
let parser = new SwaggerParser.SwaggerParser();
23+
let parser = new SwaggerParser();
2424
parser[method](path.rel("specs/callbacks-promises/callbacks-promises.yaml"), (err, result) => {
2525
try {
2626
expect(err).to.equal(null);

test/specs/typescript-definition.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const openapiObject: OpenAPI.Document = {
1919

2020

2121
// SwaggerParser class instance
22-
let parser = new SwaggerParser.SwaggerParser();
22+
let parser = new SwaggerParser();
2323

2424

2525
// SwaggerParser instance properties

0 commit comments

Comments
 (0)