-
Notifications
You must be signed in to change notification settings - Fork 41
/
index.d.ts
120 lines (100 loc) · 3.8 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// Type definitions for express-oas-generator 1.0.17
// Project: https://github.com/mpashkovskiy/express-oas-generator
// Definitions by: Kipras Melnikovas <https://github.com/sarpik>
/**
* Make sure to check out
* https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html
*/
import { Express } from 'express';
import { OpenAPIV2, OpenAPIV3 } from 'openapi-types';
import { SwaggerUiOptions } from "swagger-ui-express"
/** re-export for ease of use for the end user */
export {
OpenAPIV2,
OpenAPIV3,
SwaggerUiOptions
};
export enum SPEC_OUTPUT_FILE_BEHAVIOR {
PRESERVE = 'PRESERVE',
RECREATE = 'RECREATE'
}
/** Options for `handleResponses` */
export interface HandleResponsesOptions {
/** from where there generated documentation will be available */
swaggerUiServePath?: string;
/**
* where to write the openAPI specification to.
*
* Specify this to create the openAPI specification file
*/
specOutputPath?: string;
/** either the Swagger specification or a function with one argument, which returns the spec */
predefinedSpec?: object | OpenAPIV2.Document | OpenAPIV3.Document |
((spec: OpenAPIV2.Document) => OpenAPIV2.Document) |
((spec: OpenAPIV3.Document) => OpenAPIV3.Document);
/** how often to write the openAPI specification to file */
writeIntervalMs?: number;
/** Mongoose model names */
mongooseModels?: Array<string>;
/** Tags to be used */
tags?: Array<string>;
/** Ignored node environments */
ignoredNodeEnvironments?: Array<string>;
/** Always serve api docs */
alwaysServeDocs?: boolean;
specOutputFileBehavior: SPEC_OUTPUT_FILE_BEHAVIOR | string;
swaggerDocumentOptions: SwaggerUiOptions;
}
/**
* Apply this **first**!
*
* (straight after creating the express app (as the very first middleware))
*
* @description apply the `response` middleware.
*/
export function handleResponses(expressApp: Express, options: HandleResponsesOptions): void;
/**
* Apply this **last**!
*
* (as the very last middleware of your express app)
*
* @description apply the `request` middleware
* Applies to the `app` you provided in `handleResponses`
*
* Also, since this is the last function you'll need to invoke,
* it also initializes the specification and serves the api documentation.
* The options are for these tasks.
*/
export function handleRequests(): void;
/**
* @warn it's preferred that you use `handleResponses`,
* `handleRequests` and `serveApiDocs` **individually**
* and not directly from this `init` function,
* because we need `handleRequests` to be placed as the
* very last middleware and we cannot guarantee this here,
* since we're only using an arbitrary setTimeout of `1000` ms.
*
* See
* https://github.com/mpashkovskiy/express-oas-generator/pull/32#issuecomment-546807216
*
* @description initialize the `express-oas-generator`.
*
* This will apply both `handleResponses` and `handleRequests`
* and also will call `serveApiDocs`.
*/
export function init(
expressApp: Express,
predefinedSpec?: HandleResponsesOptions['predefinedSpec'],
specOutputPath?: HandleResponsesOptions['specOutputPath'],
writeIntervalMs?: HandleResponsesOptions['writeIntervalMs'],
swaggerUiServePath?: HandleResponsesOptions['swaggerUiServePath'],
mongooseModels?: HandleResponsesOptions['mongooseModels'],
tags?: HandleResponsesOptions['tags'],
ignoredNodeEnvironments?: HandleResponsesOptions['ignoredNodeEnvironments'],
alwaysServeDocs?: HandleResponsesOptions['alwaysServeDocs'],
specOutputFileBehavior?: HandleResponsesOptions['specOutputFileBehavior'],
swaggerDocumentOptions?: HandleResponsesOptions['swaggerDocumentOptions']
): void;
export const getSpec: () => object | OpenAPIV2.Document;
export const getSpecV3: (callback: (err: object | string, specV3: object | OpenAPIV3.Document) => void) => void
export const setPackageInfoPath: (pkgInfoPath: string) => void;