-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathhttp-spec.ts
More file actions
358 lines (312 loc) · 10.6 KB
/
http-spec.ts
File metadata and controls
358 lines (312 loc) · 10.6 KB
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
import { JSONSchema7 } from 'json-schema';
import { Dictionary } from './basic';
import { Extensions, IComponentNode, INode, INodeExample, INodeExternalExample, IShareableNode, ISpecExtensions } from './graph';
import { IServer } from './servers';
/**
* HTTP Service
*/
export interface IHttpService extends INode, IShareableNode, ISpecExtensions {
name: string;
version: string;
servers?: IServer[];
security?: HttpSecurityScheme[][];
securitySchemes?: HttpSecurityScheme[];
termsOfService?: string;
contact?: {
name?: string;
url?: string;
email?: string;
};
license?: {
name: string;
url?: string;
identifier?: string;
};
logo?: {
altText: string;
href?: string;
url?: string;
backgroundColor?: string;
};
infoExtensions?: Extensions;
internal?: boolean;
externalDocs?: IExternalDocs;
}
export interface IBundledHttpService extends Omit<IHttpService, 'securitySchemes'> {
operations: IHttpOperation<true>[];
webhooks: IHttpWebhookOperation<true>[];
components: {
schemas: (IComponentNode & JSONSchema7)[];
responses: (IComponentNode & (IHttpOperationResponse<true> | Reference))[];
path: (IComponentNode & (IHttpHeaderParam<true> | Reference))[];
query: (IComponentNode & (IHttpQueryParam<true> | Reference))[];
header: (IComponentNode & (IHttpHeaderParam<true> | Reference))[];
cookie: (IComponentNode & (IHttpCookieParam<true> | Reference))[];
/**
* component parameters that are only references to external/unavailable
* parameter definitions; parameters whose definitions are available
* will always be found in path, query, header, or cookie.
*/
unknownParameters: (IComponentNode & Reference)[];
examples: (IComponentNode & (INodeExample | INodeExternalExample | Reference))[];
requestBodies: (IComponentNode & (IHttpOperationRequestBody<true> | Reference))[];
securitySchemes: (IComponentNode & (HttpSecurityScheme | Reference))[];
callbacks: (IComponentNode & (IHttpCallbackOperation | IHttpKeyedReference))[];
};
}
/**
* HTTP Operation & Webhooks
*/
export interface IHttpEndpointOperation<Bundle extends boolean = false> extends INode, IShareableNode, ISpecExtensions {
method: string;
request?: Bundle extends true ? IHttpOperationRequest<true> | Reference : IHttpOperationRequest<false>;
responses: (Bundle extends true
? IHttpOperationResponse<true> | (Pick<IHttpOperationResponse, 'code'> & Reference)
: IHttpOperationResponse<false>)[];
servers?: IServer[];
callbacks?: (Bundle extends true ? (IHttpCallbackOperation | IHttpKeyedReference)[] : IHttpCallbackOperation<false>)[];
security?: HttpSecurityScheme[][];
securityDeclarationType?: HttpOperationSecurityDeclarationTypes;
deprecated?: boolean;
internal?: boolean;
externalDocs?: IExternalDocs;
}
export interface IHttpOperation<Bundle extends boolean = false> extends IHttpEndpointOperation<Bundle> {
path: string;
}
export interface IHttpWebhookOperation<Bundle extends boolean = false> extends IHttpEndpointOperation<Bundle> {
name: string;
}
export enum HttpOperationSecurityDeclarationTypes {
/** Indicates that the operation has no security declarations. */
None = 'none', // For empty `security` array on operation object
/** Indicates that the operation has explicit security declarations. */
Declared = 'declared', // For non-empty `security` array on operation object
/** Indicates that the operation inherits its security declarations from the service. */
InheritedFromService = 'inheritedFromService', // Undefined `security` property on operation object
}
export interface IHttpCallbackOperation<Bundle extends boolean = false>
extends Omit<IHttpOperation<Bundle>, 'callbacks'> {
key: string;
}
export interface IHttpKeyedReference extends Reference {
key: string;
}
export interface IHttpOperationRequest<Bundle extends boolean = false> {
path?: (Bundle extends true ? IHttpPathParam<true> | Reference : IHttpPathParam<false>)[];
query?: (Bundle extends true ? IHttpQueryParam<true> | Reference : IHttpQueryParam<false>)[];
headers?: (Bundle extends true ? IHttpHeaderParam<true> | Reference : IHttpHeaderParam<false>)[];
cookie?: (Bundle extends true ? IHttpCookieParam<true> | Reference : IHttpCookieParam<false>)[];
unknown?: Reference[];
body?: Bundle extends true ? IHttpOperationRequestBody<true> | Reference : IHttpOperationRequestBody<false>;
}
// https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#requestBodyObject
export interface IHttpOperationRequestBody<Bundle extends boolean = false> extends IShareableNode, ISpecExtensions {
contents?: IMediaTypeContent<Bundle>[];
required?: boolean;
description?: string;
name?: string;
}
export interface IHttpOperationResponse<Bundle extends boolean = false> extends IShareableNode, ISpecExtensions {
// Note: code MAY contain uppercase "X" to indicate wildcard
// Examples: 200, 2XX, 4XX, XXX ("default" in OAS)
// When mocking, should select most specific defined code
code: string;
contents?: IMediaTypeContent<Bundle>[];
headers?: (Bundle extends true
? IHttpHeaderParam<true> | (Pick<IHttpHeaderParam, 'name'> & Reference)
: IHttpHeaderParam<false>)[];
description?: string;
}
/**
* HTTP Params
*/
// Inspired by: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#parameterObject
export interface IHttpParam<Bundle extends boolean = false> extends IHttpContent<Bundle>, IShareableNode, ISpecExtensions {
name: string;
style: HttpParamStyles;
description?: string;
explode?: boolean;
required?: boolean;
deprecated?: boolean;
/** Captures any properties that were explicitly defined. */
explicitProperties?: string[]
}
export enum HttpParamStyles {
/** Used when OAS2 type !== array */
Unspecified = "unspecified",
/**
* OAS 3.x style simple
* OAS 2 collectionFormat csv
*/
Simple = 'simple',
/**
* OAS 3.x style matrix
* OAS 2 collectionFormat no support
*/
Matrix = 'matrix',
/**
* OAS 3.x style label
* OAS 2 collectionFormat no support
*/
Label = 'label',
/**
* OAS 3.x style form
* OAS 2 collectionFormat
* * csv, when explode === false
* * multi, when explode === true
*/
Form = 'form',
/**
* OAS 3.x no support
* OAS 2 collectionFormat csv when explode === undefined
*/
CommaDelimited = 'commaDelimited',
/**
* OAS 3.x style spaceDelimited
* OAS 2 collectionFormat ssv
*/
SpaceDelimited = 'spaceDelimited',
/**
* OAS 3.x style spaceDelimited
* OAS 2 collectionFormat pipes
*/
PipeDelimited = 'pipeDelimited',
/**
* OAS 3.x style deepObject
* OAS 2 collectionFormat no support
*/
DeepObject = 'deepObject',
/**
* OAS 3.x style no support
* OAS 2 collectionFormat tsv
*/
TabDelimited = 'tabDelimited',
}
export interface IHttpPathParam<Bundle extends boolean = false> extends IHttpParam<Bundle> {
// should default to simple
style:
| HttpParamStyles.Unspecified
| HttpParamStyles.Label
| HttpParamStyles.Matrix
| HttpParamStyles.Simple;
}
export interface IHttpQueryParam<Bundle extends boolean = false> extends IHttpParam<Bundle> {
// should default to form
style:
| HttpParamStyles.Unspecified
| HttpParamStyles.Form
| HttpParamStyles.CommaDelimited
| HttpParamStyles.SpaceDelimited
| HttpParamStyles.PipeDelimited
| HttpParamStyles.DeepObject
| HttpParamStyles.TabDelimited;
allowEmptyValue?: boolean;
allowReserved?: boolean;
}
export interface IHttpHeaderParam<Bundle extends boolean = false> extends IHttpParam<Bundle> {
// should default to simple
style: HttpParamStyles.Unspecified | HttpParamStyles.Simple;
}
export interface IHttpCookieParam<Bundle extends boolean = false> extends IHttpParam<Bundle> {
// should default to form
style: HttpParamStyles.Unspecified | HttpParamStyles.Form;
}
/**
* HTTP Content
*/
export interface IHttpContent<Bundle extends boolean = false> extends IShareableNode, ISpecExtensions {
schema?: JSONSchema7;
examples?: (Bundle extends true
? INodeExample | INodeExternalExample | (IHttpKeyedReference)
: INodeExample | INodeExternalExample)[];
encodings?: IHttpEncoding<Bundle>[];
}
export interface IMediaTypeContent<Bundle extends boolean = false> extends IHttpContent<Bundle> {
mediaType: string;
}
export interface IHttpEncoding<Bundle extends boolean = false> extends ISpecExtensions {
property: string;
// defaults to form
style:
| HttpParamStyles.Form
| HttpParamStyles.CommaDelimited
| HttpParamStyles.SpaceDelimited
| HttpParamStyles.PipeDelimited
| HttpParamStyles.DeepObject;
headers?: (Bundle extends true ? IHttpHeaderParam<true> | Reference : IHttpHeaderParam<false>)[];
mediaType?: string;
explode?: boolean;
allowReserved?: boolean;
}
/**
* HTTP Security
*/
export type HttpSecurityScheme =
| IApiKeySecurityScheme
| IBearerSecurityScheme
| IBasicSecurityScheme
| IOauth2SecurityScheme
| IOpenIdConnectSecurityScheme
| IMutualTLSSecurityScheme;
interface ISecurityScheme extends IShareableNode, ISpecExtensions {
key: string;
description?: string;
}
export interface IApiKeySecurityScheme extends ISecurityScheme {
type: 'apiKey';
name: string;
in: 'query' | 'header' | 'cookie';
}
export interface IBearerSecurityScheme extends ISecurityScheme {
type: 'http';
scheme: 'bearer';
bearerFormat?: string;
}
export interface IBasicSecurityScheme extends ISecurityScheme {
type: 'http';
scheme: 'basic' | 'digest';
}
export interface IOpenIdConnectSecurityScheme extends ISecurityScheme {
type: 'openIdConnect';
openIdConnectUrl: string;
}
export interface IOauth2SecurityScheme extends ISecurityScheme {
type: 'oauth2';
flows: IOauthFlowObjects;
}
export interface IMutualTLSSecurityScheme extends ISecurityScheme {
type: 'mutualTLS';
}
export interface IOauthFlowObjects {
implicit?: IOauth2ImplicitFlow;
password?: IOauth2PasswordFlow;
clientCredentials?: IOauth2ClientCredentialsFlow;
authorizationCode?: IOauth2AuthorizationCodeFlow;
}
export interface IOauth2Flow {
scopes: Dictionary<string, string>;
refreshUrl?: string;
}
export interface IOauth2ImplicitFlow extends IOauth2Flow {
authorizationUrl: string;
}
export interface IOauth2AuthorizationCodeFlow extends IOauth2Flow {
authorizationUrl: string;
tokenUrl: string;
}
export interface IOauth2PasswordFlow extends IOauth2Flow {
tokenUrl: string;
}
export interface IOauth2ClientCredentialsFlow extends IOauth2Flow {
tokenUrl: string;
}
export type Reference = {
$ref: string;
summary?: string;
description?: string;
};
export interface IExternalDocs extends ISpecExtensions {
description?: string;
url: string;
}