@rvoh/psychic-spec-helpers 0.7.2 → 0.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/spec/features/setup/hooks.js +2 -2
- package/dist/esm/src/unit/OpenapiSpecRequest.js +342 -21
- package/dist/esm/src/unit/OpenapiSpecSession.js +290 -12
- package/dist/types/src/unit/OpenapiSpecRequest.d.ts +15 -335
- package/dist/types/src/unit/OpenapiSpecSession.d.ts +8 -277
- package/package.json +1 -1
- package/src/unit/OpenapiSpecRequest.ts +98 -831
- package/src/unit/OpenapiSpecSession.ts +82 -696
|
@@ -1,18 +1,16 @@
|
|
|
1
|
+
import { IdType } from '@rvoh/dream'
|
|
1
2
|
import supertest, { Response } from 'supertest'
|
|
2
3
|
import { createPsychicServer } from '../index.js'
|
|
3
4
|
import fillOpenapiParams from './helpers/fillOpenapiParams.js'
|
|
4
5
|
import {
|
|
5
|
-
ExcludeNever,
|
|
6
6
|
ExtractOpenapiParams,
|
|
7
7
|
First,
|
|
8
|
-
GetOpenapiUrl,
|
|
9
8
|
GetResolvedOpenapiUrl,
|
|
10
9
|
RoutesWithHttpMethod,
|
|
11
10
|
} from './helpers/openapiTypeHelpers.js'
|
|
12
11
|
import { OpenapiSpecSession } from './OpenapiSpecSession.js'
|
|
13
|
-
import supersession, { HttpMethod } from './supersession.js'
|
|
14
|
-
import { IdType } from '@rvoh/dream'
|
|
15
12
|
import { SpecRequestOpts, SpecRequestOptsAll } from './SpecRequest.js'
|
|
13
|
+
import supersession, { HttpMethod } from './supersession.js'
|
|
16
14
|
|
|
17
15
|
export class OpenapiSpecRequest<OpenapiPaths = undefined> {
|
|
18
16
|
// eslint-disable-next-line
|
|
@@ -20,11 +18,13 @@ export class OpenapiSpecRequest<OpenapiPaths = undefined> {
|
|
|
20
18
|
// eslint-disable-next-line
|
|
21
19
|
private server: any
|
|
22
20
|
|
|
23
|
-
//
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
21
|
+
// eslint-disable-next-line
|
|
22
|
+
public async init(PsychicServer: any) {
|
|
23
|
+
// eslint-disable-next-line
|
|
24
|
+
this.PsychicServer = PsychicServer
|
|
25
|
+
this.server ||= await createPsychicServer(PsychicServer)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
28
|
public async get<
|
|
29
29
|
const Uri extends RoutesWithHttpMethod<
|
|
30
30
|
OpenapiPaths,
|
|
@@ -102,115 +102,9 @@ export class OpenapiSpecRequest<OpenapiPaths = undefined> {
|
|
|
102
102
|
* @param opts.headers - headers you would like to send with your request.
|
|
103
103
|
* (Optional)
|
|
104
104
|
*/
|
|
105
|
-
opts
|
|
106
|
-
?
|
|
105
|
+
opts?: Params['length'] extends 0
|
|
106
|
+
? OpenapiSpecRequestOptsGet<QueryMap>
|
|
107
107
|
: OpenapiSpecRequestOptsGet<QueryMap> & { [K in Params[number]]: string | IdType }
|
|
108
|
-
): Promise<OpenapiSpecResponse<JsonContent>>
|
|
109
|
-
// doesn't have Params
|
|
110
|
-
public async get<
|
|
111
|
-
const Uri extends RoutesWithHttpMethod<
|
|
112
|
-
OpenapiPaths,
|
|
113
|
-
'get' & keyof OpenapiPaths[keyof OpenapiPaths]
|
|
114
|
-
> &
|
|
115
|
-
string,
|
|
116
|
-
const ResponseCode extends Params['length'] extends 0
|
|
117
|
-
? keyof ExcludeNever<ResponseMap> & number
|
|
118
|
-
: never,
|
|
119
|
-
HttpMethodMap extends OpenapiPaths[Uri & keyof OpenapiPaths],
|
|
120
|
-
ResponseMap extends HttpMethodMap['get' & keyof HttpMethodMap]['responses' &
|
|
121
|
-
keyof HttpMethodMap['get' & keyof HttpMethodMap]],
|
|
122
|
-
ParametersMap extends HttpMethodMap['get' & keyof HttpMethodMap]['parameters' &
|
|
123
|
-
keyof HttpMethodMap['get' & keyof HttpMethodMap]],
|
|
124
|
-
QueryMap extends ParametersMap['query' & keyof ParametersMap],
|
|
125
|
-
Params extends string[] & ExtractOpenapiParams<Uri>,
|
|
126
|
-
Content extends ResponseMap extends undefined
|
|
127
|
-
? undefined
|
|
128
|
-
: ResponseCode extends undefined
|
|
129
|
-
? undefined
|
|
130
|
-
: ResponseCode extends number
|
|
131
|
-
? ResponseMap[ResponseCode & keyof ResponseMap]['content' &
|
|
132
|
-
keyof ResponseMap[ResponseCode & keyof ResponseMap]]
|
|
133
|
-
: undefined,
|
|
134
|
-
JsonContent extends Content extends undefined
|
|
135
|
-
? undefined
|
|
136
|
-
: Content['application/json' & keyof Content],
|
|
137
|
-
>(
|
|
138
|
-
/**
|
|
139
|
-
* The uri on your background you are trying to hit.
|
|
140
|
-
* This should be a path, like '/users'.
|
|
141
|
-
*
|
|
142
|
-
* ```ts
|
|
143
|
-
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
144
|
-
* const res = await request.get('/user', 200)
|
|
145
|
-
* ```
|
|
146
|
-
*/
|
|
147
|
-
uri: Uri,
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* The response status you are expecting to receive
|
|
151
|
-
* when making this request. It will need to match
|
|
152
|
-
* one of the accepted response statuses for the
|
|
153
|
-
* provided uri in your openapi types
|
|
154
|
-
*
|
|
155
|
-
* ```ts
|
|
156
|
-
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
157
|
-
* const res = await request.get('/user', 200)
|
|
158
|
-
* ```
|
|
159
|
-
*/
|
|
160
|
-
expectedStatus: ResponseCode,
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* Query params, headers, and other options to send with
|
|
164
|
-
* your request.
|
|
165
|
-
*
|
|
166
|
-
* ```ts
|
|
167
|
-
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
168
|
-
* const res = await request.get(
|
|
169
|
-
* '/user',
|
|
170
|
-
* 200,
|
|
171
|
-
* {
|
|
172
|
-
* query: {
|
|
173
|
-
* ...query params here
|
|
174
|
-
* }
|
|
175
|
-
* }
|
|
176
|
-
* )
|
|
177
|
-
* ```
|
|
178
|
-
*
|
|
179
|
-
* @param opts.query - query params you want to send up. Must match the
|
|
180
|
-
* query params in the openapi document for this uri.
|
|
181
|
-
* (Optional)
|
|
182
|
-
*
|
|
183
|
-
* @param opts.headers - headers you would like to send with your request.
|
|
184
|
-
* (Optional)
|
|
185
|
-
*/
|
|
186
|
-
opts?: OpenapiSpecRequestOptsGet<QueryMap>
|
|
187
|
-
): Promise<OpenapiSpecResponse<JsonContent>>
|
|
188
|
-
// final
|
|
189
|
-
public async get<
|
|
190
|
-
const Uri extends RoutesWithHttpMethod<
|
|
191
|
-
OpenapiPaths,
|
|
192
|
-
'get' & keyof OpenapiPaths[keyof OpenapiPaths]
|
|
193
|
-
> &
|
|
194
|
-
string,
|
|
195
|
-
const ResponseCode extends keyof ExcludeNever<ResponseMap> & number,
|
|
196
|
-
HttpMethodMap extends OpenapiPaths[Uri & keyof OpenapiPaths],
|
|
197
|
-
ResponseMap extends HttpMethodMap['get' & keyof HttpMethodMap]['responses' &
|
|
198
|
-
keyof HttpMethodMap['get' & keyof HttpMethodMap]],
|
|
199
|
-
Content extends ResponseMap extends undefined
|
|
200
|
-
? undefined
|
|
201
|
-
: ResponseCode extends undefined
|
|
202
|
-
? undefined
|
|
203
|
-
: ResponseCode extends number
|
|
204
|
-
? ResponseMap[ResponseCode & keyof ResponseMap]['content' &
|
|
205
|
-
keyof ResponseMap[ResponseCode & keyof ResponseMap]]
|
|
206
|
-
: undefined,
|
|
207
|
-
JsonContent extends Content extends undefined
|
|
208
|
-
? undefined
|
|
209
|
-
: Content['application/json' & keyof Content],
|
|
210
|
-
>(
|
|
211
|
-
uri: Uri,
|
|
212
|
-
expectedStatus: ResponseCode,
|
|
213
|
-
opts: unknown
|
|
214
108
|
): Promise<OpenapiSpecResponse<JsonContent>> {
|
|
215
109
|
return (await this.makeRequest(
|
|
216
110
|
'get',
|
|
@@ -220,20 +114,13 @@ export class OpenapiSpecRequest<OpenapiPaths = undefined> {
|
|
|
220
114
|
)) as OpenapiSpecResponse<JsonContent>
|
|
221
115
|
}
|
|
222
116
|
|
|
223
|
-
//
|
|
224
|
-
//
|
|
225
|
-
//
|
|
226
|
-
// begin: POST
|
|
227
|
-
// has Params
|
|
228
117
|
public async post<
|
|
229
118
|
const Uri extends RoutesWithHttpMethod<
|
|
230
119
|
OpenapiPaths,
|
|
231
120
|
'post' & keyof OpenapiPaths[keyof OpenapiPaths]
|
|
232
121
|
> &
|
|
233
122
|
string,
|
|
234
|
-
const ResponseCode extends
|
|
235
|
-
? never
|
|
236
|
-
: keyof ExcludeNever<ResponseMap> & number,
|
|
123
|
+
const ResponseCode extends keyof ResponseMap & number,
|
|
237
124
|
HttpMethodMap extends OpenapiPaths[ResolvedUri & keyof OpenapiPaths],
|
|
238
125
|
ResolvedUri extends First<GetResolvedOpenapiUrl<OpenapiPaths, Uri> & keyof OpenapiPaths>,
|
|
239
126
|
Params extends string[] & ExtractOpenapiParams<Uri>,
|
|
@@ -313,22 +200,24 @@ export class OpenapiSpecRequest<OpenapiPaths = undefined> {
|
|
|
313
200
|
* @param opts.headers - headers you would like to send with your request.
|
|
314
201
|
* (Optional)
|
|
315
202
|
*/
|
|
316
|
-
opts
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
203
|
+
opts?: Params['length'] extends 0
|
|
204
|
+
? OpenapiSpecRequestOptsPost<RequestBodyJsonContent>
|
|
205
|
+
: OpenapiSpecRequestOptsPost<RequestBodyJsonContent> & { [K in Params[number]]: string }
|
|
206
|
+
): Promise<OpenapiSpecResponse<JsonContent>> {
|
|
207
|
+
return await this.makeRequest('post', uri, expectedStatus, opts as SpecRequestOptsAll)
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
public async put<
|
|
320
211
|
const Uri extends RoutesWithHttpMethod<
|
|
321
212
|
OpenapiPaths,
|
|
322
|
-
'
|
|
213
|
+
'put' & keyof OpenapiPaths[keyof OpenapiPaths]
|
|
323
214
|
> &
|
|
324
215
|
string,
|
|
325
|
-
const ResponseCode extends
|
|
326
|
-
? keyof ExcludeNever<ResponseMap> & number
|
|
327
|
-
: never,
|
|
216
|
+
const ResponseCode extends keyof ResponseMap & number,
|
|
328
217
|
HttpMethodMap extends OpenapiPaths[Uri & keyof OpenapiPaths],
|
|
329
218
|
Params extends string[] & ExtractOpenapiParams<Uri>,
|
|
330
|
-
ResponseMap extends HttpMethodMap['
|
|
331
|
-
keyof HttpMethodMap['
|
|
219
|
+
ResponseMap extends HttpMethodMap['put' & keyof HttpMethodMap]['responses' &
|
|
220
|
+
keyof HttpMethodMap['put' & keyof HttpMethodMap]],
|
|
332
221
|
Content extends ResponseMap extends undefined
|
|
333
222
|
? undefined
|
|
334
223
|
: ResponseCode extends undefined
|
|
@@ -340,8 +229,8 @@ export class OpenapiSpecRequest<OpenapiPaths = undefined> {
|
|
|
340
229
|
JsonContent extends Content extends undefined
|
|
341
230
|
? undefined
|
|
342
231
|
: Content['application/json' & keyof Content],
|
|
343
|
-
RequestBodyMap extends HttpMethodMap['
|
|
344
|
-
keyof HttpMethodMap['
|
|
232
|
+
RequestBodyMap extends HttpMethodMap['put' & keyof HttpMethodMap]['requestBody' &
|
|
233
|
+
keyof HttpMethodMap['put' & keyof HttpMethodMap]],
|
|
345
234
|
RequestBodyContent extends RequestBodyMap extends undefined
|
|
346
235
|
? undefined
|
|
347
236
|
: RequestBodyMap['content' & keyof RequestBodyMap],
|
|
@@ -355,7 +244,7 @@ export class OpenapiSpecRequest<OpenapiPaths = undefined> {
|
|
|
355
244
|
*
|
|
356
245
|
* ```ts
|
|
357
246
|
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
358
|
-
* const res = await request.
|
|
247
|
+
* const res = await request.put('/posts/{id}', 200, { id: '123', data: { name: 'new name' }})
|
|
359
248
|
* ```
|
|
360
249
|
*/
|
|
361
250
|
uri: Uri,
|
|
@@ -368,21 +257,25 @@ export class OpenapiSpecRequest<OpenapiPaths = undefined> {
|
|
|
368
257
|
*
|
|
369
258
|
* ```ts
|
|
370
259
|
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
371
|
-
* const res = await request.
|
|
260
|
+
* const res = await request.put('/posts/{id}', 200, { id: '123', data: { name: 'new name' }})
|
|
372
261
|
* ```
|
|
373
262
|
*/
|
|
374
263
|
expectedStatus: ResponseCode,
|
|
375
264
|
|
|
376
265
|
/**
|
|
377
|
-
*
|
|
378
|
-
* your
|
|
266
|
+
* An object containing the path fields required to
|
|
267
|
+
* fill your uri in, as well as any additional PUT
|
|
268
|
+
* arguments, like `data`, for example.
|
|
379
269
|
*
|
|
380
270
|
* ```ts
|
|
381
271
|
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
382
|
-
* const res = await request.
|
|
383
|
-
* '/
|
|
272
|
+
* const res = await request.put(
|
|
273
|
+
* '/posts/{id}/comments/{commentId}',
|
|
384
274
|
* 200,
|
|
385
275
|
* {
|
|
276
|
+
* postId: '123',
|
|
277
|
+
* id: '456',
|
|
278
|
+
*
|
|
386
279
|
* data: {
|
|
387
280
|
* ...request body here
|
|
388
281
|
* },
|
|
@@ -400,56 +293,31 @@ export class OpenapiSpecRequest<OpenapiPaths = undefined> {
|
|
|
400
293
|
* @param opts.headers - headers you would like to send with your request.
|
|
401
294
|
* (Optional)
|
|
402
295
|
*/
|
|
403
|
-
opts?: Params['length'] extends 0
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
OpenapiPaths,
|
|
409
|
-
'post' & keyof OpenapiPaths[keyof OpenapiPaths]
|
|
410
|
-
> &
|
|
411
|
-
string,
|
|
412
|
-
const ResponseCode extends keyof ExcludeNever<ResponseMap> & number,
|
|
413
|
-
HttpMethodMap extends OpenapiPaths[Uri & keyof OpenapiPaths],
|
|
414
|
-
ResponseMap = HttpMethodMap['post' & keyof HttpMethodMap]['responses' &
|
|
415
|
-
keyof HttpMethodMap['post' & keyof HttpMethodMap]],
|
|
416
|
-
Content = ResponseMap extends undefined
|
|
417
|
-
? undefined
|
|
418
|
-
: ResponseCode extends undefined
|
|
419
|
-
? undefined
|
|
420
|
-
: ResponseCode extends number
|
|
421
|
-
? ResponseMap[ResponseCode & keyof ResponseMap]['content' &
|
|
422
|
-
keyof ResponseMap[ResponseCode & keyof ResponseMap]]
|
|
423
|
-
: undefined,
|
|
424
|
-
JsonContent = Content extends undefined
|
|
425
|
-
? undefined
|
|
426
|
-
: Content['application/json' & keyof Content],
|
|
427
|
-
>(
|
|
428
|
-
uri: Uri,
|
|
429
|
-
expectedStatus: ResponseCode,
|
|
430
|
-
opts: unknown = {}
|
|
296
|
+
opts?: Params['length'] extends 0
|
|
297
|
+
? OpenapiSpecRequestOptsPost<RequestBodyJsonContent>
|
|
298
|
+
: OpenapiSpecRequestOptsPost<RequestBodyJsonContent> & {
|
|
299
|
+
[K in Params[number]]: string | IdType
|
|
300
|
+
}
|
|
431
301
|
): Promise<OpenapiSpecResponse<JsonContent>> {
|
|
432
|
-
return await this.makeRequest(
|
|
302
|
+
return await this.makeRequest(
|
|
303
|
+
'put',
|
|
304
|
+
fillOpenapiParams(uri, opts || {}),
|
|
305
|
+
expectedStatus,
|
|
306
|
+
opts as SpecRequestOptsAll
|
|
307
|
+
)
|
|
433
308
|
}
|
|
434
309
|
|
|
435
|
-
|
|
436
|
-
//
|
|
437
|
-
//
|
|
438
|
-
// begin: PUT
|
|
439
|
-
// has Params
|
|
440
|
-
public async put<
|
|
310
|
+
public async patch<
|
|
441
311
|
const Uri extends RoutesWithHttpMethod<
|
|
442
312
|
OpenapiPaths,
|
|
443
|
-
'
|
|
313
|
+
'patch' & keyof OpenapiPaths[keyof OpenapiPaths]
|
|
444
314
|
> &
|
|
445
315
|
string,
|
|
446
|
-
const ResponseCode extends
|
|
447
|
-
? never
|
|
448
|
-
: keyof ExcludeNever<ResponseMap> & number,
|
|
316
|
+
const ResponseCode extends keyof ResponseMap & number,
|
|
449
317
|
HttpMethodMap extends OpenapiPaths[Uri & keyof OpenapiPaths],
|
|
450
318
|
Params extends string[] & ExtractOpenapiParams<Uri>,
|
|
451
|
-
ResponseMap extends HttpMethodMap['
|
|
452
|
-
keyof HttpMethodMap['
|
|
319
|
+
ResponseMap extends HttpMethodMap['patch' & keyof HttpMethodMap]['responses' &
|
|
320
|
+
keyof HttpMethodMap['patch' & keyof HttpMethodMap]],
|
|
453
321
|
Content extends ResponseMap extends undefined
|
|
454
322
|
? undefined
|
|
455
323
|
: ResponseCode extends undefined
|
|
@@ -461,8 +329,8 @@ export class OpenapiSpecRequest<OpenapiPaths = undefined> {
|
|
|
461
329
|
JsonContent extends Content extends undefined
|
|
462
330
|
? undefined
|
|
463
331
|
: Content['application/json' & keyof Content],
|
|
464
|
-
RequestBodyMap extends HttpMethodMap['
|
|
465
|
-
keyof HttpMethodMap['
|
|
332
|
+
RequestBodyMap extends HttpMethodMap['patch' & keyof HttpMethodMap]['requestBody' &
|
|
333
|
+
keyof HttpMethodMap['patch' & keyof HttpMethodMap]],
|
|
466
334
|
RequestBodyContent extends RequestBodyMap extends undefined
|
|
467
335
|
? undefined
|
|
468
336
|
: RequestBodyMap['content' & keyof RequestBodyMap],
|
|
@@ -472,11 +340,11 @@ export class OpenapiSpecRequest<OpenapiPaths = undefined> {
|
|
|
472
340
|
>(
|
|
473
341
|
/**
|
|
474
342
|
* The uri on your background you are trying to hit.
|
|
475
|
-
* This should be a path, like '/
|
|
343
|
+
* This should be a path, like '/posts'.
|
|
476
344
|
*
|
|
477
345
|
* ```ts
|
|
478
346
|
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
479
|
-
* const res = await request.
|
|
347
|
+
* const res = await request.patch('/posts/{id}', 200, { data: { name: 'new name' }})
|
|
480
348
|
* ```
|
|
481
349
|
*/
|
|
482
350
|
uri: Uri,
|
|
@@ -489,25 +357,24 @@ export class OpenapiSpecRequest<OpenapiPaths = undefined> {
|
|
|
489
357
|
*
|
|
490
358
|
* ```ts
|
|
491
359
|
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
492
|
-
* const res = await request.
|
|
360
|
+
* const res = await request.patch('/posts/{id}', 200, { data: { name: 'new name' }})
|
|
493
361
|
* ```
|
|
494
362
|
*/
|
|
495
363
|
expectedStatus: ResponseCode,
|
|
496
364
|
|
|
497
365
|
/**
|
|
498
366
|
* An object containing the path fields required to
|
|
499
|
-
* fill your uri in, as well as any additional
|
|
367
|
+
* fill your uri in, as well as any additional PATCH
|
|
500
368
|
* arguments, like `data`, for example.
|
|
501
369
|
*
|
|
502
370
|
* ```ts
|
|
503
371
|
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
504
|
-
* const res = await request.
|
|
505
|
-
* '/posts/{
|
|
372
|
+
* const res = await request.patch(
|
|
373
|
+
* '/posts/{postId}/comments/{id}',
|
|
506
374
|
* 200,
|
|
507
375
|
* {
|
|
508
376
|
* postId: '123',
|
|
509
|
-
*
|
|
510
|
-
*
|
|
377
|
+
* commentId: '456',
|
|
511
378
|
* data: {
|
|
512
379
|
* ...request body here
|
|
513
380
|
* },
|
|
@@ -525,26 +392,31 @@ export class OpenapiSpecRequest<OpenapiPaths = undefined> {
|
|
|
525
392
|
* @param opts.headers - headers you would like to send with your request.
|
|
526
393
|
* (Optional)
|
|
527
394
|
*/
|
|
528
|
-
opts
|
|
529
|
-
?
|
|
395
|
+
opts?: Params['length'] extends 0
|
|
396
|
+
? OpenapiSpecRequestOptsPost<RequestBodyJsonContent>
|
|
530
397
|
: OpenapiSpecRequestOptsPost<RequestBodyJsonContent> & {
|
|
531
398
|
[K in Params[number]]: string | IdType
|
|
532
399
|
}
|
|
533
|
-
): Promise<OpenapiSpecResponse<JsonContent>>
|
|
534
|
-
|
|
535
|
-
|
|
400
|
+
): Promise<OpenapiSpecResponse<JsonContent>> {
|
|
401
|
+
return await this.makeRequest(
|
|
402
|
+
'patch',
|
|
403
|
+
fillOpenapiParams(uri, opts!),
|
|
404
|
+
expectedStatus,
|
|
405
|
+
opts as SpecRequestOptsAll
|
|
406
|
+
)
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
public async delete<
|
|
536
410
|
const Uri extends RoutesWithHttpMethod<
|
|
537
411
|
OpenapiPaths,
|
|
538
|
-
'
|
|
412
|
+
'delete' & keyof OpenapiPaths[keyof OpenapiPaths]
|
|
539
413
|
> &
|
|
540
414
|
string,
|
|
541
|
-
const ResponseCode extends
|
|
542
|
-
? keyof ExcludeNever<ResponseMap> & number
|
|
543
|
-
: never,
|
|
415
|
+
const ResponseCode extends keyof ResponseMap & number,
|
|
544
416
|
HttpMethodMap extends OpenapiPaths[Uri & keyof OpenapiPaths],
|
|
545
417
|
Params extends string[] & ExtractOpenapiParams<Uri>,
|
|
546
|
-
ResponseMap extends HttpMethodMap['
|
|
547
|
-
keyof HttpMethodMap['
|
|
418
|
+
ResponseMap extends HttpMethodMap['delete' & keyof HttpMethodMap]['responses' &
|
|
419
|
+
keyof HttpMethodMap['delete' & keyof HttpMethodMap]],
|
|
548
420
|
Content extends ResponseMap extends undefined
|
|
549
421
|
? undefined
|
|
550
422
|
: ResponseCode extends undefined
|
|
@@ -556,8 +428,8 @@ export class OpenapiSpecRequest<OpenapiPaths = undefined> {
|
|
|
556
428
|
JsonContent extends Content extends undefined
|
|
557
429
|
? undefined
|
|
558
430
|
: Content['application/json' & keyof Content],
|
|
559
|
-
RequestBodyMap extends HttpMethodMap['
|
|
560
|
-
keyof HttpMethodMap['
|
|
431
|
+
RequestBodyMap extends HttpMethodMap['delete' & keyof HttpMethodMap]['requestBody' &
|
|
432
|
+
keyof HttpMethodMap['delete' & keyof HttpMethodMap]],
|
|
561
433
|
RequestBodyContent extends RequestBodyMap extends undefined
|
|
562
434
|
? undefined
|
|
563
435
|
: RequestBodyMap['content' & keyof RequestBodyMap],
|
|
@@ -571,7 +443,7 @@ export class OpenapiSpecRequest<OpenapiPaths = undefined> {
|
|
|
571
443
|
*
|
|
572
444
|
* ```ts
|
|
573
445
|
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
574
|
-
* const res = await request.
|
|
446
|
+
* const res = await request.delete('/posts/{id}', 200, { id: '123' })
|
|
575
447
|
* ```
|
|
576
448
|
*/
|
|
577
449
|
uri: Uri,
|
|
@@ -584,23 +456,24 @@ export class OpenapiSpecRequest<OpenapiPaths = undefined> {
|
|
|
584
456
|
*
|
|
585
457
|
* ```ts
|
|
586
458
|
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
587
|
-
* const res = await request.
|
|
459
|
+
* const res = await request.delete('/posts/{id}', 200, { id: '123' })
|
|
588
460
|
* ```
|
|
589
461
|
*/
|
|
590
462
|
expectedStatus: ResponseCode,
|
|
591
463
|
|
|
592
464
|
/**
|
|
593
465
|
* An object containing the path fields required to
|
|
594
|
-
* fill your uri in, as well as any additional
|
|
466
|
+
* fill your uri in, as well as any additional DELETE
|
|
595
467
|
* arguments, like `data`, for example.
|
|
596
468
|
*
|
|
597
|
-
*
|
|
598
469
|
* ```ts
|
|
599
470
|
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
600
|
-
* const res = await request.
|
|
601
|
-
* '/
|
|
471
|
+
* const res = await request.delete(
|
|
472
|
+
* '/posts/{postId}/comments/{commentId}',
|
|
602
473
|
* 200,
|
|
603
474
|
* {
|
|
475
|
+
* postId: '123',
|
|
476
|
+
* commentId: '456',
|
|
604
477
|
* data: {
|
|
605
478
|
* ...request body here
|
|
606
479
|
* },
|
|
@@ -618,515 +491,28 @@ export class OpenapiSpecRequest<OpenapiPaths = undefined> {
|
|
|
618
491
|
* @param opts.headers - headers you would like to send with your request.
|
|
619
492
|
* (Optional)
|
|
620
493
|
*/
|
|
621
|
-
opts?: Params['length'] extends 0
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
OpenapiPaths,
|
|
627
|
-
'put' & keyof OpenapiPaths[keyof OpenapiPaths]
|
|
628
|
-
> &
|
|
629
|
-
string,
|
|
630
|
-
const ResponseCode extends keyof ExcludeNever<ResponseMap> & number,
|
|
631
|
-
HttpMethodMap extends OpenapiPaths[Uri & keyof OpenapiPaths],
|
|
632
|
-
ResponseMap = HttpMethodMap['put' & keyof HttpMethodMap]['responses' &
|
|
633
|
-
keyof HttpMethodMap['put' & keyof HttpMethodMap]],
|
|
634
|
-
Content = ResponseMap extends undefined
|
|
635
|
-
? undefined
|
|
636
|
-
: ResponseCode extends undefined
|
|
637
|
-
? undefined
|
|
638
|
-
: ResponseCode extends number
|
|
639
|
-
? ResponseMap[ResponseCode & keyof ResponseMap]['content' &
|
|
640
|
-
keyof ResponseMap[ResponseCode & keyof ResponseMap]]
|
|
641
|
-
: undefined,
|
|
642
|
-
JsonContent = Content extends undefined
|
|
643
|
-
? undefined
|
|
644
|
-
: Content['application/json' & keyof Content],
|
|
645
|
-
>(
|
|
646
|
-
uri: Uri,
|
|
647
|
-
expectedStatus: ResponseCode,
|
|
648
|
-
opts: unknown = {}
|
|
494
|
+
opts?: Params['length'] extends 0
|
|
495
|
+
? OpenapiSpecRequestOptsPost<RequestBodyJsonContent>
|
|
496
|
+
: OpenapiSpecRequestOptsPost<RequestBodyJsonContent> & {
|
|
497
|
+
[K in Params[number]]: string | IdType
|
|
498
|
+
}
|
|
649
499
|
): Promise<OpenapiSpecResponse<JsonContent>> {
|
|
650
500
|
return await this.makeRequest(
|
|
651
|
-
'
|
|
501
|
+
'delete',
|
|
652
502
|
fillOpenapiParams(uri, opts || {}),
|
|
653
503
|
expectedStatus,
|
|
654
504
|
opts as SpecRequestOptsAll
|
|
655
505
|
)
|
|
656
506
|
}
|
|
657
507
|
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
//
|
|
661
|
-
// begin: PATCH
|
|
662
|
-
// has Params
|
|
663
|
-
public async patch<
|
|
508
|
+
public async session<
|
|
509
|
+
const ProvidedHttpMethod extends HttpMethod,
|
|
664
510
|
const Uri extends RoutesWithHttpMethod<
|
|
665
511
|
OpenapiPaths,
|
|
666
|
-
|
|
512
|
+
ProvidedHttpMethod & keyof OpenapiPaths[keyof OpenapiPaths]
|
|
667
513
|
> &
|
|
668
514
|
string,
|
|
669
|
-
const ResponseCode extends Params['length'] extends 0
|
|
670
|
-
? never
|
|
671
|
-
: keyof ExcludeNever<ResponseMap> & number,
|
|
672
|
-
HttpMethodMap extends OpenapiPaths[Uri & keyof OpenapiPaths],
|
|
673
|
-
Params extends string[] & ExtractOpenapiParams<Uri>,
|
|
674
|
-
ResponseMap extends HttpMethodMap['patch' & keyof HttpMethodMap]['responses' &
|
|
675
|
-
keyof HttpMethodMap['patch' & keyof HttpMethodMap]],
|
|
676
|
-
Content extends ResponseMap extends undefined
|
|
677
|
-
? undefined
|
|
678
|
-
: ResponseCode extends undefined
|
|
679
|
-
? undefined
|
|
680
|
-
: ResponseCode extends number
|
|
681
|
-
? ResponseMap[ResponseCode & keyof ResponseMap]['content' &
|
|
682
|
-
keyof ResponseMap[ResponseCode & keyof ResponseMap]]
|
|
683
|
-
: undefined,
|
|
684
|
-
JsonContent extends Content extends undefined
|
|
685
|
-
? undefined
|
|
686
|
-
: Content['application/json' & keyof Content],
|
|
687
|
-
RequestBodyMap extends HttpMethodMap['patch' & keyof HttpMethodMap]['requestBody' &
|
|
688
|
-
keyof HttpMethodMap['patch' & keyof HttpMethodMap]],
|
|
689
|
-
RequestBodyContent extends RequestBodyMap extends undefined
|
|
690
|
-
? undefined
|
|
691
|
-
: RequestBodyMap['content' & keyof RequestBodyMap],
|
|
692
|
-
RequestBodyJsonContent extends RequestBodyContent extends undefined
|
|
693
|
-
? undefined
|
|
694
|
-
: RequestBodyContent['application/json' & keyof RequestBodyContent],
|
|
695
|
-
>(
|
|
696
|
-
/**
|
|
697
|
-
* The uri on your background you are trying to hit.
|
|
698
|
-
* This should be a path, like '/posts'.
|
|
699
|
-
*
|
|
700
|
-
* ```ts
|
|
701
|
-
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
702
|
-
* const res = await request.patch('/posts/{id}', 200, { data: { name: 'new name' }})
|
|
703
|
-
* ```
|
|
704
|
-
*/
|
|
705
|
-
uri: Uri,
|
|
706
|
-
|
|
707
|
-
/**
|
|
708
|
-
* The response status you are expecting to receive
|
|
709
|
-
* when making this request. It will need to match
|
|
710
|
-
* one of the accepted response statuses for the
|
|
711
|
-
* provided uri in your openapi types
|
|
712
|
-
*
|
|
713
|
-
* ```ts
|
|
714
|
-
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
715
|
-
* const res = await request.patch('/posts/{id}', 200, { data: { name: 'new name' }})
|
|
716
|
-
* ```
|
|
717
|
-
*/
|
|
718
|
-
expectedStatus: ResponseCode,
|
|
719
|
-
|
|
720
|
-
/**
|
|
721
|
-
* An object containing the path fields required to
|
|
722
|
-
* fill your uri in, as well as any additional PATCH
|
|
723
|
-
* arguments, like `data`, for example.
|
|
724
|
-
*
|
|
725
|
-
* ```ts
|
|
726
|
-
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
727
|
-
* const res = await request.patch(
|
|
728
|
-
* '/posts/{postId}/comments/{id}',
|
|
729
|
-
* 200,
|
|
730
|
-
* {
|
|
731
|
-
* postId: '123',
|
|
732
|
-
* commentId: '456',
|
|
733
|
-
* data: {
|
|
734
|
-
* ...request body here
|
|
735
|
-
* },
|
|
736
|
-
* headers: {
|
|
737
|
-
* ...headers here
|
|
738
|
-
* },
|
|
739
|
-
* }
|
|
740
|
-
* )
|
|
741
|
-
* ```
|
|
742
|
-
*
|
|
743
|
-
* @param opts.data - request body data you want to send up. Must match the
|
|
744
|
-
* requestBody shape in the openapi document for this uri.
|
|
745
|
-
* (Optional)
|
|
746
|
-
*
|
|
747
|
-
* @param opts.headers - headers you would like to send with your request.
|
|
748
|
-
* (Optional)
|
|
749
|
-
*/
|
|
750
|
-
opts: Params['length'] extends 0
|
|
751
|
-
? never
|
|
752
|
-
: OpenapiSpecRequestOptsPost<RequestBodyJsonContent> & {
|
|
753
|
-
[K in Params[number]]: string | IdType
|
|
754
|
-
}
|
|
755
|
-
): Promise<OpenapiSpecResponse<JsonContent>>
|
|
756
|
-
// DOESNT have params
|
|
757
|
-
public async patch<
|
|
758
|
-
const Uri extends RoutesWithHttpMethod<
|
|
759
|
-
OpenapiPaths,
|
|
760
|
-
'patch' & keyof OpenapiPaths[keyof OpenapiPaths]
|
|
761
|
-
> &
|
|
762
|
-
string,
|
|
763
|
-
const ResponseCode extends Params['length'] extends 0
|
|
764
|
-
? keyof ExcludeNever<ResponseMap> & number
|
|
765
|
-
: never,
|
|
766
|
-
HttpMethodMap extends OpenapiPaths[Uri & keyof OpenapiPaths],
|
|
767
|
-
Params extends string[] & ExtractOpenapiParams<Uri>,
|
|
768
|
-
ResponseMap extends HttpMethodMap['patch' & keyof HttpMethodMap]['responses' &
|
|
769
|
-
keyof HttpMethodMap['patch' & keyof HttpMethodMap]],
|
|
770
|
-
Content extends ResponseMap extends undefined
|
|
771
|
-
? undefined
|
|
772
|
-
: ResponseCode extends undefined
|
|
773
|
-
? undefined
|
|
774
|
-
: ResponseCode extends number
|
|
775
|
-
? ResponseMap[ResponseCode & keyof ResponseMap]['content' &
|
|
776
|
-
keyof ResponseMap[ResponseCode & keyof ResponseMap]]
|
|
777
|
-
: undefined,
|
|
778
|
-
JsonContent extends Content extends undefined
|
|
779
|
-
? undefined
|
|
780
|
-
: Content['application/json' & keyof Content],
|
|
781
|
-
RequestBodyMap extends HttpMethodMap['patch' & keyof HttpMethodMap]['requestBody' &
|
|
782
|
-
keyof HttpMethodMap['patch' & keyof HttpMethodMap]],
|
|
783
|
-
RequestBodyContent extends RequestBodyMap extends undefined
|
|
784
|
-
? undefined
|
|
785
|
-
: RequestBodyMap['content' & keyof RequestBodyMap],
|
|
786
|
-
RequestBodyJsonContent extends RequestBodyContent extends undefined
|
|
787
|
-
? undefined
|
|
788
|
-
: RequestBodyContent['application/json' & keyof RequestBodyContent],
|
|
789
|
-
>(
|
|
790
|
-
/**
|
|
791
|
-
* The uri on your background you are trying to hit.
|
|
792
|
-
* This should be a path, like '/user'.
|
|
793
|
-
*
|
|
794
|
-
* ```ts
|
|
795
|
-
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
796
|
-
* const res = await request.patch('/user', 200, { data: { name: 'new name' }})
|
|
797
|
-
* ```
|
|
798
|
-
*/
|
|
799
|
-
uri: Uri,
|
|
800
|
-
|
|
801
|
-
/**
|
|
802
|
-
* The response status you are expecting to receive
|
|
803
|
-
* when making this request. It will need to match
|
|
804
|
-
* one of the accepted response statuses for the
|
|
805
|
-
* provided uri in your openapi types
|
|
806
|
-
*
|
|
807
|
-
* ```ts
|
|
808
|
-
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
809
|
-
* const res = await request.patch('/user', 200, { data: { name: 'new name' }})
|
|
810
|
-
* ```
|
|
811
|
-
*/
|
|
812
|
-
expectedStatus: ResponseCode,
|
|
813
|
-
|
|
814
|
-
/**
|
|
815
|
-
* Data, headers, and other options to send with
|
|
816
|
-
* your request.
|
|
817
|
-
*
|
|
818
|
-
* ```ts
|
|
819
|
-
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
820
|
-
* const res = await request.patch(
|
|
821
|
-
* '/user',
|
|
822
|
-
* 200,
|
|
823
|
-
* {
|
|
824
|
-
* data: {
|
|
825
|
-
* ...request body here
|
|
826
|
-
* },
|
|
827
|
-
* headers: {
|
|
828
|
-
* ...headers here
|
|
829
|
-
* },
|
|
830
|
-
* }
|
|
831
|
-
* )
|
|
832
|
-
* ```
|
|
833
|
-
*
|
|
834
|
-
* @param opts.data - request body data you want to send up. Must match the
|
|
835
|
-
* requestBody shape in the openapi document for this uri.
|
|
836
|
-
* (Optional)
|
|
837
|
-
*
|
|
838
|
-
* @param opts.headers - headers you would like to send with your request.
|
|
839
|
-
* (Optional)
|
|
840
|
-
*/
|
|
841
|
-
opts?: Params['length'] extends 0 ? OpenapiSpecRequestOptsPost<RequestBodyJsonContent> : never
|
|
842
|
-
): Promise<OpenapiSpecResponse<JsonContent>>
|
|
843
|
-
// final
|
|
844
|
-
public async patch<
|
|
845
|
-
const Uri extends GetOpenapiUrl<OpenapiPaths>,
|
|
846
|
-
const ResponseCode extends keyof ResponseMap & number,
|
|
847
|
-
HttpMethodMap extends OpenapiPaths[ResolvedUri & keyof OpenapiPaths],
|
|
848
|
-
ResolvedUri extends GetResolvedOpenapiUrl<OpenapiPaths, Uri> & keyof OpenapiPaths,
|
|
849
|
-
ResponseMap extends HttpMethodMap['patch' & keyof HttpMethodMap]['responses' &
|
|
850
|
-
keyof HttpMethodMap['patch' & keyof HttpMethodMap]],
|
|
851
|
-
Content extends ResponseMap extends undefined
|
|
852
|
-
? undefined
|
|
853
|
-
: ResponseCode extends undefined
|
|
854
|
-
? undefined
|
|
855
|
-
: ResponseCode extends number
|
|
856
|
-
? ResponseMap[ResponseCode & keyof ResponseMap]['content' &
|
|
857
|
-
keyof ResponseMap[ResponseCode & keyof ResponseMap]]
|
|
858
|
-
: undefined,
|
|
859
|
-
JsonContent extends Content extends undefined
|
|
860
|
-
? undefined
|
|
861
|
-
: Content['application/json' & keyof Content],
|
|
862
|
-
RequestBodyMap extends HttpMethodMap['patch' & keyof HttpMethodMap]['requestBody' &
|
|
863
|
-
keyof HttpMethodMap['patch' & keyof HttpMethodMap]],
|
|
864
|
-
RequestBodyContent extends RequestBodyMap extends undefined
|
|
865
|
-
? undefined
|
|
866
|
-
: RequestBodyMap['content' & keyof RequestBodyMap],
|
|
867
|
-
RequestBodyJsonContent extends RequestBodyContent extends undefined
|
|
868
|
-
? undefined
|
|
869
|
-
: RequestBodyContent['application/json' & keyof RequestBodyContent],
|
|
870
|
-
>(
|
|
871
|
-
uri: Uri,
|
|
872
|
-
expectedStatus: ResponseCode,
|
|
873
|
-
opts: OpenapiSpecRequestOptsPost<RequestBodyJsonContent> = {}
|
|
874
|
-
): Promise<OpenapiSpecResponse<JsonContent>> {
|
|
875
|
-
return await this.makeRequest(
|
|
876
|
-
'patch',
|
|
877
|
-
fillOpenapiParams(uri, opts),
|
|
878
|
-
expectedStatus,
|
|
879
|
-
opts as SpecRequestOptsAll
|
|
880
|
-
)
|
|
881
|
-
}
|
|
882
|
-
|
|
883
|
-
//
|
|
884
|
-
//
|
|
885
|
-
//
|
|
886
|
-
// begin: delete
|
|
887
|
-
// has Params
|
|
888
|
-
public async delete<
|
|
889
|
-
const Uri extends RoutesWithHttpMethod<
|
|
890
|
-
OpenapiPaths,
|
|
891
|
-
'delete' & keyof OpenapiPaths[keyof OpenapiPaths]
|
|
892
|
-
> &
|
|
893
|
-
string,
|
|
894
|
-
const ResponseCode extends Params['length'] extends 0
|
|
895
|
-
? never
|
|
896
|
-
: keyof ExcludeNever<ResponseMap> & number,
|
|
897
|
-
HttpMethodMap extends OpenapiPaths[Uri & keyof OpenapiPaths],
|
|
898
|
-
Params extends string[] & ExtractOpenapiParams<Uri>,
|
|
899
|
-
ResponseMap extends HttpMethodMap['delete' & keyof HttpMethodMap]['responses' &
|
|
900
|
-
keyof HttpMethodMap['delete' & keyof HttpMethodMap]],
|
|
901
|
-
Content extends ResponseMap extends undefined
|
|
902
|
-
? undefined
|
|
903
|
-
: ResponseCode extends undefined
|
|
904
|
-
? undefined
|
|
905
|
-
: ResponseCode extends number
|
|
906
|
-
? ResponseMap[ResponseCode & keyof ResponseMap]['content' &
|
|
907
|
-
keyof ResponseMap[ResponseCode & keyof ResponseMap]]
|
|
908
|
-
: undefined,
|
|
909
|
-
JsonContent extends Content extends undefined
|
|
910
|
-
? undefined
|
|
911
|
-
: Content['application/json' & keyof Content],
|
|
912
|
-
RequestBodyMap extends HttpMethodMap['delete' & keyof HttpMethodMap]['requestBody' &
|
|
913
|
-
keyof HttpMethodMap['delete' & keyof HttpMethodMap]],
|
|
914
|
-
RequestBodyContent extends RequestBodyMap extends undefined
|
|
915
|
-
? undefined
|
|
916
|
-
: RequestBodyMap['content' & keyof RequestBodyMap],
|
|
917
|
-
RequestBodyJsonContent extends RequestBodyContent extends undefined
|
|
918
|
-
? undefined
|
|
919
|
-
: RequestBodyContent['application/json' & keyof RequestBodyContent],
|
|
920
|
-
>(
|
|
921
|
-
/**
|
|
922
|
-
* The uri on your background you are trying to hit.
|
|
923
|
-
* This should be a path, like '/users'.
|
|
924
|
-
*
|
|
925
|
-
* ```ts
|
|
926
|
-
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
927
|
-
* const res = await request.delete('/posts/{id}', 200, { id: '123' })
|
|
928
|
-
* ```
|
|
929
|
-
*/
|
|
930
|
-
uri: Uri,
|
|
931
|
-
|
|
932
|
-
/**
|
|
933
|
-
* The response status you are expecting to receive
|
|
934
|
-
* when making this request. It will need to match
|
|
935
|
-
* one of the accepted response statuses for the
|
|
936
|
-
* provided uri in your openapi types
|
|
937
|
-
*
|
|
938
|
-
* ```ts
|
|
939
|
-
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
940
|
-
* const res = await request.delete('/posts/{id}', 200, { id: '123' })
|
|
941
|
-
* ```
|
|
942
|
-
*/
|
|
943
|
-
expectedStatus: ResponseCode,
|
|
944
|
-
|
|
945
|
-
/**
|
|
946
|
-
* An object containing the path fields required to
|
|
947
|
-
* fill your uri in, as well as any additional DELETE
|
|
948
|
-
* arguments, like `data`, for example.
|
|
949
|
-
*
|
|
950
|
-
* ```ts
|
|
951
|
-
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
952
|
-
* const res = await request.delete(
|
|
953
|
-
* '/posts/{postId}/comments/{commentId}',
|
|
954
|
-
* 200,
|
|
955
|
-
* {
|
|
956
|
-
* postId: '123',
|
|
957
|
-
* commentId: '456',
|
|
958
|
-
* data: {
|
|
959
|
-
* ...request body here
|
|
960
|
-
* },
|
|
961
|
-
* headers: {
|
|
962
|
-
* ...headers here
|
|
963
|
-
* },
|
|
964
|
-
* }
|
|
965
|
-
* )
|
|
966
|
-
* ```
|
|
967
|
-
*
|
|
968
|
-
* @param opts.data - request body data you want to send up. Must match the
|
|
969
|
-
* requestBody shape in the openapi document for this uri.
|
|
970
|
-
* (Optional)
|
|
971
|
-
*
|
|
972
|
-
* @param opts.headers - headers you would like to send with your request.
|
|
973
|
-
* (Optional)
|
|
974
|
-
*/
|
|
975
|
-
opts: Params['length'] extends 0
|
|
976
|
-
? never
|
|
977
|
-
: OpenapiSpecRequestOptsPost<RequestBodyJsonContent> & {
|
|
978
|
-
[K in Params[number]]: string | IdType
|
|
979
|
-
}
|
|
980
|
-
): Promise<OpenapiSpecResponse<JsonContent>>
|
|
981
|
-
// DOESNT have params
|
|
982
|
-
public async delete<
|
|
983
|
-
const Uri extends RoutesWithHttpMethod<
|
|
984
|
-
OpenapiPaths,
|
|
985
|
-
'delete' & keyof OpenapiPaths[keyof OpenapiPaths]
|
|
986
|
-
> &
|
|
987
|
-
string,
|
|
988
|
-
const ResponseCode extends Params['length'] extends 0
|
|
989
|
-
? keyof ExcludeNever<ResponseMap> & number
|
|
990
|
-
: never,
|
|
991
|
-
HttpMethodMap extends OpenapiPaths[Uri & keyof OpenapiPaths],
|
|
992
|
-
Params extends string[] & ExtractOpenapiParams<Uri>,
|
|
993
|
-
ResponseMap extends HttpMethodMap['delete' & keyof HttpMethodMap]['responses' &
|
|
994
|
-
keyof HttpMethodMap['delete' & keyof HttpMethodMap]],
|
|
995
|
-
Content extends ResponseMap extends undefined
|
|
996
|
-
? undefined
|
|
997
|
-
: ResponseCode extends undefined
|
|
998
|
-
? undefined
|
|
999
|
-
: ResponseCode extends number
|
|
1000
|
-
? ResponseMap[ResponseCode & keyof ResponseMap]['content' &
|
|
1001
|
-
keyof ResponseMap[ResponseCode & keyof ResponseMap]]
|
|
1002
|
-
: undefined,
|
|
1003
|
-
JsonContent extends Content extends undefined
|
|
1004
|
-
? undefined
|
|
1005
|
-
: Content['application/json' & keyof Content],
|
|
1006
|
-
RequestBodyMap extends HttpMethodMap['delete' & keyof HttpMethodMap]['requestBody' &
|
|
1007
|
-
keyof HttpMethodMap['delete' & keyof HttpMethodMap]],
|
|
1008
|
-
RequestBodyContent extends RequestBodyMap extends undefined
|
|
1009
|
-
? undefined
|
|
1010
|
-
: RequestBodyMap['content' & keyof RequestBodyMap],
|
|
1011
|
-
RequestBodyJsonContent extends RequestBodyContent extends undefined
|
|
1012
|
-
? undefined
|
|
1013
|
-
: RequestBodyContent['application/json' & keyof RequestBodyContent],
|
|
1014
|
-
>(
|
|
1015
|
-
/**
|
|
1016
|
-
* The uri on your background you are trying to hit.
|
|
1017
|
-
* This should be a path, like '/users'.
|
|
1018
|
-
*
|
|
1019
|
-
* ```ts
|
|
1020
|
-
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
1021
|
-
* const res = await request.delete('/user', 200)
|
|
1022
|
-
* ```
|
|
1023
|
-
*/
|
|
1024
|
-
uri: Uri,
|
|
1025
|
-
|
|
1026
|
-
/**
|
|
1027
|
-
* The response status you are expecting to receive
|
|
1028
|
-
* when making this request. It will need to match
|
|
1029
|
-
* one of the accepted response statuses for the
|
|
1030
|
-
* provided uri in your openapi types
|
|
1031
|
-
*
|
|
1032
|
-
* ```ts
|
|
1033
|
-
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
1034
|
-
* const res = await request.delete('/user', 200)
|
|
1035
|
-
* ```
|
|
1036
|
-
*/
|
|
1037
|
-
expectedStatus: ResponseCode,
|
|
1038
|
-
|
|
1039
|
-
/**
|
|
1040
|
-
* Data, headers, and other options to send with
|
|
1041
|
-
* your request.
|
|
1042
|
-
*
|
|
1043
|
-
* ```ts
|
|
1044
|
-
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
1045
|
-
* const res = await request.delete(
|
|
1046
|
-
* '/user',
|
|
1047
|
-
* 200,
|
|
1048
|
-
* {
|
|
1049
|
-
* data: {
|
|
1050
|
-
* ...request body here
|
|
1051
|
-
* },
|
|
1052
|
-
* headers: {
|
|
1053
|
-
* ...headers here
|
|
1054
|
-
* },
|
|
1055
|
-
* }
|
|
1056
|
-
* )
|
|
1057
|
-
* ```
|
|
1058
|
-
*
|
|
1059
|
-
* @param opts.data - request body data you want to send up. Must match the
|
|
1060
|
-
* requestBody shape in the openapi document for this uri.
|
|
1061
|
-
* (Optional)
|
|
1062
|
-
*
|
|
1063
|
-
* @param opts.headers - headers you would like to send with your request.
|
|
1064
|
-
* (Optional)
|
|
1065
|
-
*/
|
|
1066
|
-
opts?: Params['length'] extends 0 ? OpenapiSpecRequestOptsPost<RequestBodyJsonContent> : never
|
|
1067
|
-
): Promise<OpenapiSpecResponse<JsonContent>>
|
|
1068
|
-
// final
|
|
1069
|
-
public async delete<
|
|
1070
|
-
const Uri extends GetOpenapiUrl<OpenapiPaths>,
|
|
1071
515
|
const ResponseCode extends keyof ResponseMap & number,
|
|
1072
|
-
HttpMethodMap extends OpenapiPaths[ResolvedUri & keyof OpenapiPaths],
|
|
1073
|
-
ResolvedUri extends GetResolvedOpenapiUrl<OpenapiPaths, Uri> & keyof OpenapiPaths,
|
|
1074
|
-
ResponseMap = HttpMethodMap['delete' & keyof HttpMethodMap]['responses' &
|
|
1075
|
-
keyof HttpMethodMap['delete' & keyof HttpMethodMap]],
|
|
1076
|
-
Content = ResponseMap extends undefined
|
|
1077
|
-
? undefined
|
|
1078
|
-
: ResponseCode extends undefined
|
|
1079
|
-
? undefined
|
|
1080
|
-
: ResponseCode extends number
|
|
1081
|
-
? ResponseMap[ResponseCode & keyof ResponseMap]['content' &
|
|
1082
|
-
keyof ResponseMap[ResponseCode & keyof ResponseMap]]
|
|
1083
|
-
: undefined,
|
|
1084
|
-
JsonContent = Content extends undefined
|
|
1085
|
-
? undefined
|
|
1086
|
-
: Content['application/json' & keyof Content],
|
|
1087
|
-
RequestBodyMap = HttpMethodMap['delete' & keyof HttpMethodMap]['requestBody' &
|
|
1088
|
-
keyof HttpMethodMap['delete' & keyof HttpMethodMap]],
|
|
1089
|
-
RequestBodyContent = RequestBodyMap extends undefined
|
|
1090
|
-
? undefined
|
|
1091
|
-
: RequestBodyMap['content' & keyof RequestBodyMap],
|
|
1092
|
-
RequestBodyJsonContent = RequestBodyContent extends undefined
|
|
1093
|
-
? undefined
|
|
1094
|
-
: RequestBodyContent['application/json' & keyof RequestBodyContent],
|
|
1095
|
-
>(
|
|
1096
|
-
uri: Uri,
|
|
1097
|
-
expectedStatus: ResponseCode,
|
|
1098
|
-
opts: OpenapiSpecRequestOptsPost<RequestBodyJsonContent> = {}
|
|
1099
|
-
): Promise<OpenapiSpecResponse<JsonContent>> {
|
|
1100
|
-
return await this.makeRequest(
|
|
1101
|
-
'delete',
|
|
1102
|
-
fillOpenapiParams(uri, opts),
|
|
1103
|
-
expectedStatus,
|
|
1104
|
-
opts as SpecRequestOptsAll
|
|
1105
|
-
)
|
|
1106
|
-
}
|
|
1107
|
-
|
|
1108
|
-
// eslint-disable-next-line
|
|
1109
|
-
public async init(PsychicServer: any) {
|
|
1110
|
-
// eslint-disable-next-line
|
|
1111
|
-
this.PsychicServer = PsychicServer
|
|
1112
|
-
this.server ||= await createPsychicServer(PsychicServer)
|
|
1113
|
-
}
|
|
1114
|
-
|
|
1115
|
-
//
|
|
1116
|
-
//
|
|
1117
|
-
//
|
|
1118
|
-
// begin: SESSION
|
|
1119
|
-
// has Params
|
|
1120
|
-
public async session<
|
|
1121
|
-
const ProvidedHttpMethod extends HttpMethod,
|
|
1122
|
-
const Uri extends RoutesWithHttpMethod<
|
|
1123
|
-
OpenapiPaths,
|
|
1124
|
-
ProvidedHttpMethod & keyof OpenapiPaths[keyof OpenapiPaths]
|
|
1125
|
-
> &
|
|
1126
|
-
string,
|
|
1127
|
-
const ResponseCode extends Params['length'] extends 0
|
|
1128
|
-
? never
|
|
1129
|
-
: keyof ExcludeNever<ResponseMap> & number,
|
|
1130
516
|
HttpMethodMap extends OpenapiPaths[Uri & keyof OpenapiPaths],
|
|
1131
517
|
Params extends string[] & ExtractOpenapiParams<Uri>,
|
|
1132
518
|
ResponseMap extends HttpMethodMap[ProvidedHttpMethod & keyof HttpMethodMap]['responses' &
|
|
@@ -1209,133 +595,14 @@ export class OpenapiSpecRequest<OpenapiPaths = undefined> {
|
|
|
1209
595
|
* @param opts.headers - headers you would like to send with your request.
|
|
1210
596
|
* (Optional)
|
|
1211
597
|
*/
|
|
1212
|
-
opts
|
|
598
|
+
opts?: (ProvidedHttpMethod extends 'get'
|
|
1213
599
|
? OpenapiSpecRequestOptsGet<QueryMap>
|
|
1214
600
|
: OpenapiSpecRequestOptsPost<RequestBodyJsonContent>) & {
|
|
1215
601
|
[K in Params[number]]: string | IdType
|
|
1216
602
|
}
|
|
1217
|
-
): Promise<OpenapiSpecSession<OpenapiPaths>>
|
|
1218
|
-
// DOESNT have params
|
|
1219
|
-
public async session<
|
|
1220
|
-
const ProvidedHttpMethod extends HttpMethod,
|
|
1221
|
-
const Uri extends RoutesWithHttpMethod<
|
|
1222
|
-
OpenapiPaths,
|
|
1223
|
-
ProvidedHttpMethod & keyof OpenapiPaths[keyof OpenapiPaths]
|
|
1224
|
-
> &
|
|
1225
|
-
string,
|
|
1226
|
-
const ResponseCode extends Params['length'] extends 0
|
|
1227
|
-
? keyof ExcludeNever<ResponseMap> & number
|
|
1228
|
-
: never,
|
|
1229
|
-
HttpMethodMap extends OpenapiPaths[Uri & keyof OpenapiPaths],
|
|
1230
|
-
Params extends string[] & ExtractOpenapiParams<Uri>,
|
|
1231
|
-
ResponseMap extends HttpMethodMap[ProvidedHttpMethod & keyof HttpMethodMap]['responses' &
|
|
1232
|
-
keyof HttpMethodMap[ProvidedHttpMethod & keyof HttpMethodMap]],
|
|
1233
|
-
ParametersMap extends HttpMethodMap[ProvidedHttpMethod & keyof HttpMethodMap]['parameters' &
|
|
1234
|
-
keyof HttpMethodMap[ProvidedHttpMethod & keyof HttpMethodMap]],
|
|
1235
|
-
QueryMap extends ParametersMap['query' & keyof ParametersMap],
|
|
1236
|
-
RequestBodyMap extends HttpMethodMap[ProvidedHttpMethod & keyof HttpMethodMap]['requestBody' &
|
|
1237
|
-
keyof HttpMethodMap[ProvidedHttpMethod & keyof HttpMethodMap]],
|
|
1238
|
-
RequestBodyContent extends RequestBodyMap extends undefined
|
|
1239
|
-
? undefined
|
|
1240
|
-
: RequestBodyMap['content' & keyof RequestBodyMap],
|
|
1241
|
-
RequestBodyJsonContent extends RequestBodyContent extends undefined
|
|
1242
|
-
? undefined
|
|
1243
|
-
: RequestBodyContent['application/json' & keyof RequestBodyContent],
|
|
1244
|
-
>(
|
|
1245
|
-
httpMethod: ProvidedHttpMethod,
|
|
1246
|
-
/**
|
|
1247
|
-
* The uri on your background you are trying to hit.
|
|
1248
|
-
* This should be a path, like '/users'.
|
|
1249
|
-
*
|
|
1250
|
-
* ```ts
|
|
1251
|
-
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
1252
|
-
* const session = await request.session('post', '/login', 200)
|
|
1253
|
-
* ```
|
|
1254
|
-
*/
|
|
1255
|
-
uri: Uri,
|
|
1256
|
-
|
|
1257
|
-
/**
|
|
1258
|
-
* The response status you are expecting to receive
|
|
1259
|
-
* when making this request. It will need to match
|
|
1260
|
-
* one of the accepted response statuses for the
|
|
1261
|
-
* provided uri in your openapi types
|
|
1262
|
-
*
|
|
1263
|
-
* ```ts
|
|
1264
|
-
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
1265
|
-
* const session = await request.session('post', '/login', 200)
|
|
1266
|
-
* ```
|
|
1267
|
-
*/
|
|
1268
|
-
expectedStatus: ResponseCode,
|
|
1269
|
-
|
|
1270
|
-
/**
|
|
1271
|
-
* An object containing the path fields required to
|
|
1272
|
-
* fill your uri in, as well as any additional
|
|
1273
|
-
* arguments, for the chosen HTTP verb, like `data`,
|
|
1274
|
-
* for example.
|
|
1275
|
-
*
|
|
1276
|
-
* ```ts
|
|
1277
|
-
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
1278
|
-
* const res = await request.session(
|
|
1279
|
-
* 'post',
|
|
1280
|
-
* '/login',
|
|
1281
|
-
* 200,
|
|
1282
|
-
* {
|
|
1283
|
-
* token: '123',
|
|
1284
|
-
*
|
|
1285
|
-
* // if non-get
|
|
1286
|
-
* data: {
|
|
1287
|
-
* email: 'abc',
|
|
1288
|
-
* password: 'def',
|
|
1289
|
-
* },
|
|
1290
|
-
* // if get
|
|
1291
|
-
* query: {
|
|
1292
|
-
* ...request body here
|
|
1293
|
-
* },
|
|
1294
|
-
* headers: {
|
|
1295
|
-
* ...headers here
|
|
1296
|
-
* },
|
|
1297
|
-
* }
|
|
1298
|
-
* )
|
|
1299
|
-
* ```
|
|
1300
|
-
*
|
|
1301
|
-
* @param opts.data - request body data you want to send up. Must match the
|
|
1302
|
-
* requestBody shape in the openapi document for this uri.
|
|
1303
|
-
* (Optional)
|
|
1304
|
-
*
|
|
1305
|
-
* @param opts.query - query params you want to send up. Must match the
|
|
1306
|
-
* query parameters in the openapi document for this uri.
|
|
1307
|
-
* (Optional)
|
|
1308
|
-
*
|
|
1309
|
-
* @param opts.headers - headers you would like to send with your request.
|
|
1310
|
-
* (Optional)
|
|
1311
|
-
*/
|
|
1312
|
-
opts?: Params['length'] extends 0
|
|
1313
|
-
? ProvidedHttpMethod extends 'get'
|
|
1314
|
-
? OpenapiSpecRequestOptsGet<QueryMap>
|
|
1315
|
-
: OpenapiSpecRequestOptsPost<RequestBodyJsonContent>
|
|
1316
|
-
: never
|
|
1317
|
-
): Promise<OpenapiSpecSession<OpenapiPaths>>
|
|
1318
|
-
// final
|
|
1319
|
-
public async session<
|
|
1320
|
-
const ProvidedHttpMethod extends HttpMethod,
|
|
1321
|
-
const Uri extends RoutesWithHttpMethod<
|
|
1322
|
-
OpenapiPaths,
|
|
1323
|
-
ProvidedHttpMethod & keyof OpenapiPaths[keyof OpenapiPaths]
|
|
1324
|
-
> &
|
|
1325
|
-
string,
|
|
1326
|
-
const ResponseCode extends keyof ResponseMap & number,
|
|
1327
|
-
HttpMethodMap extends OpenapiPaths[ResolvedUri & keyof OpenapiPaths],
|
|
1328
|
-
ResolvedUri extends GetResolvedOpenapiUrl<OpenapiPaths, Uri> & keyof OpenapiPaths,
|
|
1329
|
-
ResponseMap = HttpMethodMap[ProvidedHttpMethod & keyof HttpMethodMap]['responses' &
|
|
1330
|
-
keyof HttpMethodMap[ProvidedHttpMethod & keyof HttpMethodMap]],
|
|
1331
|
-
>(
|
|
1332
|
-
httpMethod: ProvidedHttpMethod,
|
|
1333
|
-
uri: Uri,
|
|
1334
|
-
expectedStatus: ResponseCode,
|
|
1335
|
-
opts: unknown = {}
|
|
1336
603
|
): Promise<OpenapiSpecSession<OpenapiPaths>> {
|
|
1337
|
-
const postOpts = opts as OpenapiSpecRequestOptsPost
|
|
1338
|
-
const getOpts = opts as OpenapiSpecRequestOptsGet
|
|
604
|
+
const postOpts = (opts || {}) as OpenapiSpecRequestOptsPost
|
|
605
|
+
const getOpts = (opts || {}) as OpenapiSpecRequestOptsGet
|
|
1339
606
|
|
|
1340
607
|
uri = fillOpenapiParams(uri, (opts || {}) as object) as Uri
|
|
1341
608
|
|