-
Notifications
You must be signed in to change notification settings - Fork 63
/
openapi31.ts
378 lines (352 loc) · 12 KB
/
openapi31.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
/* eslint-disable @typescript-eslint/no-explicit-any */
// Typed interfaces for OpenAPI 3.1.0
// see https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md
import { ServerObject } from './oas-common';
import { ISpecificationExtension, SpecificationExtension } from './specification-extension';
export * from './oas-common';
export type { ISpecificationExtension, SpecificationExtension } from './specification-extension';
export interface OpenAPIObject extends ISpecificationExtension {
openapi: string;
info: InfoObject;
servers?: ServerObject[];
paths?: PathsObject;
components?: ComponentsObject;
security?: SecurityRequirementObject[];
tags?: TagObject[];
externalDocs?: ExternalDocumentationObject;
/** Webhooks added in v. 3.1.0 */
webhooks?: PathsObject;
}
export interface InfoObject extends ISpecificationExtension {
title: string;
description?: string;
termsOfService?: string;
contact?: ContactObject;
license?: LicenseObject;
version: string;
}
export interface ContactObject extends ISpecificationExtension {
name?: string;
url?: string;
email?: string;
}
export interface LicenseObject extends ISpecificationExtension {
name: string;
url?: string;
}
export interface ComponentsObject extends ISpecificationExtension {
schemas?: { [schema: string]: SchemaObject | ReferenceObject };
responses?: { [response: string]: ResponseObject | ReferenceObject };
parameters?: { [parameter: string]: ParameterObject | ReferenceObject };
examples?: { [example: string]: ExampleObject | ReferenceObject };
requestBodies?: { [request: string]: RequestBodyObject | ReferenceObject };
headers?: { [header: string]: HeaderObject | ReferenceObject };
securitySchemes?: { [securityScheme: string]: SecuritySchemeObject | ReferenceObject };
links?: { [link: string]: LinkObject | ReferenceObject };
callbacks?: { [callback: string]: CallbackObject | ReferenceObject };
}
/**
* Rename it to Paths Object to be consistent with the spec
* See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#pathsObject
*/
export interface PathsObject extends ISpecificationExtension {
// [path: string]: PathItemObject;
[path: string]: PathItemObject
}
/**
* @deprecated
* Create a type alias for backward compatibility
*/
export type PathObject = PathsObject;
export function getPath(
pathsObject: PathsObject | undefined,
path: string
): PathItemObject | undefined {
if (SpecificationExtension.isValidExtension(path)) {
return undefined;
}
return pathsObject ? (pathsObject[path] as PathItemObject) : undefined;
}
export interface PathItemObject extends ISpecificationExtension {
$ref?: string;
summary?: string;
description?: string;
get?: OperationObject;
put?: OperationObject;
post?: OperationObject;
delete?: OperationObject;
options?: OperationObject;
head?: OperationObject;
patch?: OperationObject;
trace?: OperationObject;
servers?: ServerObject[];
parameters?: (ParameterObject | ReferenceObject)[];
}
export interface OperationObject extends ISpecificationExtension {
tags?: string[];
summary?: string;
description?: string;
externalDocs?: ExternalDocumentationObject;
operationId?: string;
parameters?: (ParameterObject | ReferenceObject)[];
requestBody?: RequestBodyObject | ReferenceObject;
responses: ResponsesObject;
callbacks?: CallbacksObject;
deprecated?: boolean;
security?: SecurityRequirementObject[];
servers?: ServerObject[];
}
export interface ExternalDocumentationObject extends ISpecificationExtension {
description?: string;
url: string;
}
/**
* The location of a parameter.
* Possible values are "query", "header", "path" or "cookie".
* Specification:
* https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#parameter-locations
*/
export type ParameterLocation = 'query' | 'header' | 'path' | 'cookie';
/**
* The style of a parameter.
* Describes how the parameter value will be serialized.
* (serialization is not implemented yet)
* Specification:
* https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#style-values
*/
export type ParameterStyle =
| 'matrix'
| 'label'
| 'form'
| 'simple'
| 'spaceDelimited'
| 'pipeDelimited'
| 'deepObject';
export interface BaseParameterObject extends ISpecificationExtension {
description?: string;
required?: boolean;
deprecated?: boolean;
allowEmptyValue?: boolean;
style?: ParameterStyle; // "matrix" | "label" | "form" | "simple" | "spaceDelimited" | "pipeDelimited" | "deepObject";
explode?: boolean;
allowReserved?: boolean;
schema?: SchemaObject | ReferenceObject;
examples?: { [param: string]: ExampleObject | ReferenceObject };
example?: any;
content?: ContentObject;
}
export interface ParameterObject extends BaseParameterObject {
name: string;
in: ParameterLocation; // "query" | "header" | "path" | "cookie";
}
export interface RequestBodyObject extends ISpecificationExtension {
description?: string;
content: ContentObject;
required?: boolean;
}
export interface ContentObject {
[mediatype: string]: MediaTypeObject;
}
export interface MediaTypeObject extends ISpecificationExtension {
schema?: SchemaObject | ReferenceObject;
examples?: ExamplesObject;
example?: any;
encoding?: EncodingObject;
}
export interface EncodingObject extends ISpecificationExtension {
// [property: string]: EncodingPropertyObject;
[property: string]: EncodingPropertyObject | any; // Hack for allowing ISpecificationExtension
}
export interface EncodingPropertyObject {
contentType?: string;
headers?: { [key: string]: HeaderObject | ReferenceObject };
style?: string;
explode?: boolean;
allowReserved?: boolean;
[key: string]: any; // (any) = Hack for allowing ISpecificationExtension
}
export interface ResponsesObject extends ISpecificationExtension {
default?: ResponseObject | ReferenceObject;
// [statuscode: string]: ResponseObject | ReferenceObject;
[statuscode: string]: ResponseObject | ReferenceObject | any; // (any) = Hack for allowing ISpecificationExtension
}
export interface ResponseObject extends ISpecificationExtension {
description: string;
headers?: HeadersObject;
content?: ContentObject;
links?: LinksObject;
}
export interface CallbacksObject extends ISpecificationExtension {
// [name: string]: CallbackObject | ReferenceObject;
[name: string]: CallbackObject | ReferenceObject | any; // Hack for allowing ISpecificationExtension
}
export interface CallbackObject extends ISpecificationExtension {
// [name: string]: PathItemObject;
[name: string]: PathItemObject | any; // Hack for allowing ISpecificationExtension
}
export interface HeadersObject {
[name: string]: HeaderObject | ReferenceObject;
}
export interface ExampleObject {
summary?: string;
description?: string;
value?: any;
externalValue?: string;
[property: string]: any; // Hack for allowing ISpecificationExtension
}
export interface LinksObject {
[name: string]: LinkObject | ReferenceObject;
}
export interface LinkObject extends ISpecificationExtension {
operationRef?: string;
operationId?: string;
parameters?: LinkParametersObject;
requestBody?: any | string;
description?: string;
server?: ServerObject;
[property: string]: any; // Hack for allowing ISpecificationExtension
}
export interface LinkParametersObject {
[name: string]: any | string;
}
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface HeaderObject extends BaseParameterObject {
$ref?: string;
}
export interface TagObject extends ISpecificationExtension {
name: string;
description?: string;
externalDocs?: ExternalDocumentationObject;
[extension: string]: any; // Hack for allowing ISpecificationExtension
}
export interface ExamplesObject {
[name: string]: ExampleObject | ReferenceObject;
}
export interface ReferenceObject {
$ref: string;
summary?: string;
description?: string;
}
/**
* A type guard to check if the given value is a `ReferenceObject`.
* See https://www.typescriptlang.org/docs/handbook/advanced-types.html#type-guards-and-differentiating-types
*
* @param obj The value to check.
*/
export function isReferenceObject(obj: any): obj is ReferenceObject {
return Object.prototype.hasOwnProperty.call(obj, '$ref');
}
export type SchemaObjectType =
| 'integer'
| 'number'
| 'string'
| 'boolean'
| 'object'
| 'null'
| 'array';
export interface SchemaObject extends ISpecificationExtension {
discriminator?: DiscriminatorObject;
readOnly?: boolean;
writeOnly?: boolean;
xml?: XmlObject;
externalDocs?: ExternalDocumentationObject;
/** @deprecated use examples instead */
example?: any;
examples?: any[];
deprecated?: boolean;
type?: SchemaObjectType | SchemaObjectType[];
format?:
| 'int32'
| 'int64'
| 'float'
| 'double'
| 'byte'
| 'binary'
| 'date'
| 'date-time'
| 'password'
| string;
allOf?: (SchemaObject | ReferenceObject)[];
oneOf?: (SchemaObject | ReferenceObject)[];
anyOf?: (SchemaObject | ReferenceObject)[];
not?: SchemaObject | ReferenceObject;
items?: SchemaObject | ReferenceObject;
properties?: { [propertyName: string]: SchemaObject | ReferenceObject };
additionalProperties?: SchemaObject | ReferenceObject | boolean;
description?: string;
default?: any;
title?: string;
multipleOf?: number;
maximum?: number;
/** @desc In OpenAPI 3.1: number */
exclusiveMaximum?: number;
minimum?: number;
/** @desc In OpenAPI 3.1: number */
exclusiveMinimum?: number;
maxLength?: number;
minLength?: number;
pattern?: string;
maxItems?: number;
minItems?: number;
uniqueItems?: boolean;
maxProperties?: number;
minProperties?: number;
required?: string[];
enum?: any[];
prefixItems?: (SchemaObject | ReferenceObject)[];
}
/**
* A type guard to check if the given object is a `SchemaObject`.
* Useful to distinguish from `ReferenceObject` values that can be used
* in most places where `SchemaObject` is allowed.
*
* See https://www.typescriptlang.org/docs/handbook/advanced-types.html#type-guards-and-differentiating-types
*
* @param schema The value to check.
*/
export function isSchemaObject(schema: SchemaObject | ReferenceObject): schema is SchemaObject {
return !Object.prototype.hasOwnProperty.call(schema, '$ref');
}
export interface SchemasObject {
[schema: string]: SchemaObject;
}
export interface DiscriminatorObject {
propertyName: string;
mapping?: { [key: string]: string };
}
export interface XmlObject extends ISpecificationExtension {
name?: string;
namespace?: string;
prefix?: string;
attribute?: boolean;
wrapped?: boolean;
}
export type SecuritySchemeType = 'apiKey' | 'http' | 'oauth2' | 'openIdConnect';
export interface SecuritySchemeObject extends ISpecificationExtension {
type: SecuritySchemeType;
description?: string;
name?: string; // required only for apiKey
in?: string; // required only for apiKey
scheme?: string; // required only for http
bearerFormat?: string;
flows?: OAuthFlowsObject; // required only for oauth2
openIdConnectUrl?: string; // required only for openIdConnect
}
export interface OAuthFlowsObject extends ISpecificationExtension {
implicit?: OAuthFlowObject;
password?: OAuthFlowObject;
clientCredentials?: OAuthFlowObject;
authorizationCode?: OAuthFlowObject;
}
export interface OAuthFlowObject extends ISpecificationExtension {
authorizationUrl?: string;
tokenUrl?: string;
refreshUrl?: string;
scopes: ScopesObject;
}
export interface ScopesObject extends ISpecificationExtension {
[scope: string]: any; // Hack for allowing ISpecificationExtension
}
export interface SecurityRequirementObject {
[name: string]: string[];
}