-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathOpenApiV3_1.ts
400 lines (384 loc) · 10.7 KB
/
OpenApiV3_1.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
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
import { IJsonSchemaAttribute } from "./structures/IJsonSchemaAttribute";
/**
* OpenAPI v3.1 definition.
*
* @author Jeongho Nam - /~https://github.com/samchon
*/
export namespace OpenApiV3_1 {
/**
* @internal
*/
export const is = (input: any): input is IDocument =>
typeof input === "object" &&
input !== null &&
typeof input.openapi === "string" &&
input.openapi.startsWith("3.1");
export type Method =
| "get"
| "post"
| "put"
| "delete"
| "options"
| "head"
| "patch"
| "trace";
/* -----------------------------------------------------------
DOCUMENTS
----------------------------------------------------------- */
export interface IDocument {
openapi: `3.1.${number}`;
servers?: IServer[];
info?: IDocument.IInfo;
components?: IComponents;
paths?: Record<string, IPath>;
webhooks?: Record<
string,
IJsonSchema.IReference<`#/components/pathItems/${string}`> | IPath
>;
security?: Record<string, string[]>[];
tags?: IDocument.ITag[];
}
export namespace IDocument {
export interface IInfo {
title: string;
summary?: string;
description?: string;
termsOfService?: string;
contact?: IContact;
license?: ILicense;
version: string;
}
export interface ITag {
name: string;
description?: string;
}
export interface IContact {
name?: string;
url?: string;
email?: string;
}
export interface ILicense {
name: string;
identifier?: string;
url?: string;
}
}
export interface IServer {
url: string;
description?: string;
variables?: Record<string, IServer.IVariable>;
}
export namespace IServer {
export interface IVariable {
default: string;
/** @minItems 1 */ enum?: string[];
description?: string;
}
}
/* -----------------------------------------------------------
OPERATORS
----------------------------------------------------------- */
export interface IPath extends Partial<Record<Method, IOperation>> {
parameters?: Array<
| IOperation.IParameter
| IJsonSchema.IReference<`#/components/headers/${string}`>
| IJsonSchema.IReference<`#/components/parameters/${string}`>
>;
servers?: IServer[];
summary?: string;
description?: string;
}
export interface IOperation {
operationId?: string;
parameters?: Array<
| IOperation.IParameter
| IJsonSchema.IReference<`#/components/headers/${string}`>
| IJsonSchema.IReference<`#/components/parameters/${string}`>
>;
requestBody?:
| IOperation.IRequestBody
| IJsonSchema.IReference<`#/components/requestBodies/${string}`>;
responses?: Record<
string,
| IOperation.IResponse
| IJsonSchema.IReference<`#/components/responses/${string}`>
>;
servers?: IServer[];
summary?: string;
description?: string;
security?: Record<string, string[]>[];
tags?: string[];
deprecated?: boolean;
}
export namespace IOperation {
export interface IParameter {
name?: string;
in: "path" | "query" | "header" | "cookie";
schema: IJsonSchema;
required?: boolean;
description?: string;
example?: any;
examples?: Record<
string,
IExample | IJsonSchema.IReference<`#/components/examples/${string}`>
>;
}
export interface IRequestBody {
description?: string;
required?: boolean;
content?: Record<string, IMediaType>;
}
export interface IResponse {
content?: Record<string, IMediaType>;
headers?: Record<
string,
| Omit<IOperation.IParameter, "in">
| IJsonSchema.IReference<`#/components/headers/${string}`>
>;
description?: string;
}
export interface IMediaType {
schema?: IJsonSchema;
example?: any;
examples?: Record<
string,
IExample | IJsonSchema.IReference<`#/components/examples/${string}`>
>;
}
}
export interface IExample {
summary?: string;
description?: string;
value?: any;
externalValue?: string;
}
/* -----------------------------------------------------------
SCHEMA DEFINITIONS
----------------------------------------------------------- */
export interface IComponents {
schemas?: Record<string, IJsonSchema>;
pathItems?: Record<string, IPath>;
responses?: Record<string, IOperation.IResponse>;
parameters?: Record<string, IOperation.IParameter>;
requestBodies?: Record<string, IOperation.IRequestBody>;
securitySchemes?: Record<string, ISecurityScheme>;
headers?: Record<string, Omit<IOperation.IParameter, "in">>;
examples?: Record<string, IExample>;
}
export type IJsonSchema =
| IJsonSchema.IMixed
| IJsonSchema.IConstant
| IJsonSchema.IBoolean
| IJsonSchema.IInteger
| IJsonSchema.INumber
| IJsonSchema.IString
| IJsonSchema.IArray
| IJsonSchema.IObject
| IJsonSchema.IReference
| IJsonSchema.IRecursiveReference
| IJsonSchema.IAllOf
| IJsonSchema.IAnyOf
| IJsonSchema.IOneOf
| IJsonSchema.INull
| IJsonSchema.IUnknown;
export namespace IJsonSchema {
export interface IMixed
extends IConstant,
Omit<IBoolean, "type" | "default" | "enum">,
Omit<INumber, "type" | "default" | "enum">,
Omit<IString, "type" | "default" | "enum">,
Omit<IArray, "type">,
Omit<IObject, "type">,
IOneOf,
IAnyOf,
IAllOf,
IReference {
type: Array<
| "boolean"
| "integer"
| "number"
| "string"
| "array"
| "object"
| "null"
>;
default?: any[] | null;
enum?: any[];
}
export interface IConstant extends IJsonSchemaAttribute {
const: boolean | number | string;
nullable?: boolean;
}
export interface IBoolean extends IJsonSchemaAttribute.IBoolean {
nullable?: boolean;
default?: boolean | null;
enum?: Array<boolean | null>;
}
export interface IInteger extends IJsonSchemaAttribute.IInteger {
nullable?: boolean;
/** @type int64 */ default?: number | null;
/** @type int64 */ enum?: Array<number | null>;
/** @type int64 */ minimum?: number;
/** @type int64 */ maximum?: number;
/** @type int64 */ exclusiveMinimum?: number | boolean;
/** @type int64 */ exclusiveMaximum?: number | boolean;
/**
* @type uint64
* @exclusiveMinimum 0
*/
multipleOf?: number;
}
export interface INumber extends IJsonSchemaAttribute.INumber {
nullable?: boolean;
default?: number | null;
enum?: Array<number | null>;
minimum?: number;
maximum?: number;
exclusiveMinimum?: number | boolean;
exclusiveMaximum?: number | boolean;
/** @exclusiveMinimum 0 */ multipleOf?: number;
}
export interface IString extends IJsonSchemaAttribute.IString {
nullable?: boolean;
default?: string | null;
enum?: Array<string | null>;
format?:
| "binary"
| "byte"
| "password"
| "regex"
| "uuid"
| "email"
| "hostname"
| "idn-email"
| "idn-hostname"
| "iri"
| "iri-reference"
| "ipv4"
| "ipv6"
| "uri"
| "uri-reference"
| "uri-template"
| "url"
| "date-time"
| "date"
| "time"
| "duration"
| "json-pointer"
| "relative-json-pointer"
| (string & {});
pattern?: string;
contentMediaType?: string;
/** @type uint64 */ minLength?: number;
/** @type uint64 */ maxLength?: number;
}
export interface IObject extends IJsonSchemaAttribute.IObject {
nullable?: boolean;
properties?: Record<string, IJsonSchema>;
required?: string[];
additionalProperties?: boolean | IJsonSchema;
maxProperties?: number;
minProperties?: number;
}
export interface IArray extends IJsonSchemaAttribute.IArray {
nullable?: boolean;
items?: IJsonSchema | IJsonSchema[];
prefixItems?: IJsonSchema[];
uniqueItems?: boolean;
additionalItems?: boolean | IJsonSchema;
/** @type uint64 */ minItems?: number;
/** @type uint64 */ maxItems?: number;
}
export interface IReference<Key = string> extends IJsonSchemaAttribute {
$ref: Key;
}
export interface IRecursiveReference extends IJsonSchemaAttribute {
$recursiveRef: string;
}
export interface IAllOf extends IJsonSchemaAttribute {
allOf: IJsonSchema[];
}
export interface IAnyOf extends IJsonSchemaAttribute {
anyOf: IJsonSchema[];
}
export interface IOneOf extends IJsonSchemaAttribute {
oneOf: IJsonSchema[];
discriminator?: IOneOf.IDiscriminator;
}
export namespace IOneOf {
export interface IDiscriminator {
propertyName: string;
mapping?: Record<string, string>;
}
}
export interface INull extends IJsonSchemaAttribute.INull {
default?: null;
}
export interface IUnknown extends IJsonSchemaAttribute.IUnknown {
type?: undefined;
default?: any;
}
/**
* @deprecated
* @hidden
*/
export interface __ISignificant<Type extends string> extends __IAttribute {
type: Type;
nullable?: boolean;
}
/**
* @deprecated
* @hidden
*/
export type __IAttribute = IJsonSchemaAttribute;
}
export type ISecurityScheme =
| ISecurityScheme.IApiKey
| ISecurityScheme.IHttpBasic
| ISecurityScheme.IHttpBearer
| ISecurityScheme.IOAuth2
| ISecurityScheme.IOpenId;
export namespace ISecurityScheme {
export interface IApiKey {
type: "apiKey";
in?: "header" | "query" | "cookie";
name?: string;
description?: string;
}
export interface IHttpBasic {
type: "http";
scheme: "basic";
description?: string;
}
export interface IHttpBearer {
type: "http";
scheme: "bearer";
bearerFormat?: string;
description?: string;
}
export interface IOAuth2 {
type: "oauth2";
flows: IOAuth2.IFlowSet;
description?: string;
}
export interface IOpenId {
type: "openIdConnect";
openIdConnectUrl: string;
description?: string;
}
export namespace IOAuth2 {
export interface IFlowSet {
authorizationCode?: IFlow;
implicit?: Omit<IFlow, "tokenUrl">;
password?: Omit<IFlow, "authorizationUrl">;
clientCredentials?: Omit<IFlow, "authorizationUrl">;
}
export interface IFlow {
authorizationUrl?: string;
tokenUrl?: string;
refreshUrl?: string;
scopes?: Record<string, string>;
}
}
}
}