@rvoh/psychic-spec-helpers 0.7.2 → 0.7.4
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 +16 -336
- package/dist/types/src/unit/OpenapiSpecSession.d.ts +11 -280
- package/dist/types/src/unit/helpers/openapiTypeHelpers.d.ts +4 -0
- package/package.json +1 -1
- package/src/unit/OpenapiSpecRequest.ts +48 -889
- package/src/unit/OpenapiSpecSession.ts +32 -745
- package/src/unit/helpers/openapiTypeHelpers.ts +84 -0
|
@@ -1,18 +1,18 @@
|
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
RequestBody,
|
|
8
|
+
RequestQueryParameters,
|
|
9
|
+
ResponseBody,
|
|
10
|
+
ResponseCodeForUri,
|
|
10
11
|
RoutesWithHttpMethod,
|
|
11
12
|
} from './helpers/openapiTypeHelpers.js'
|
|
12
13
|
import { OpenapiSpecSession } from './OpenapiSpecSession.js'
|
|
13
|
-
import supersession, { HttpMethod } from './supersession.js'
|
|
14
|
-
import { IdType } from '@rvoh/dream'
|
|
15
14
|
import { SpecRequestOpts, SpecRequestOptsAll } from './SpecRequest.js'
|
|
15
|
+
import supersession, { HttpMethod } from './supersession.js'
|
|
16
16
|
|
|
17
17
|
export class OpenapiSpecRequest<OpenapiPaths = undefined> {
|
|
18
18
|
// eslint-disable-next-line
|
|
@@ -20,36 +20,23 @@ export class OpenapiSpecRequest<OpenapiPaths = undefined> {
|
|
|
20
20
|
// eslint-disable-next-line
|
|
21
21
|
private server: any
|
|
22
22
|
|
|
23
|
-
//
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
// eslint-disable-next-line
|
|
24
|
+
public async init(PsychicServer: any) {
|
|
25
|
+
// eslint-disable-next-line
|
|
26
|
+
this.PsychicServer = PsychicServer
|
|
27
|
+
this.server ||= await createPsychicServer(PsychicServer)
|
|
28
|
+
}
|
|
29
|
+
|
|
28
30
|
public async get<
|
|
29
31
|
const Uri extends RoutesWithHttpMethod<
|
|
30
32
|
OpenapiPaths,
|
|
31
33
|
'get' & keyof OpenapiPaths[keyof OpenapiPaths]
|
|
32
34
|
> &
|
|
33
35
|
string,
|
|
34
|
-
const ResponseCode extends
|
|
35
|
-
HttpMethodMap extends OpenapiPaths[Uri & keyof OpenapiPaths],
|
|
36
|
-
ResponseMap extends HttpMethodMap['get' & keyof HttpMethodMap]['responses' &
|
|
37
|
-
keyof HttpMethodMap['get' & keyof HttpMethodMap]],
|
|
38
|
-
ParametersMap extends HttpMethodMap['get' & keyof HttpMethodMap]['parameters' &
|
|
39
|
-
keyof HttpMethodMap['get' & keyof HttpMethodMap]],
|
|
40
|
-
QueryMap extends ParametersMap['query' & keyof ParametersMap],
|
|
36
|
+
const ResponseCode extends ResponseCodeForUri<OpenapiPaths, Uri, 'get'>,
|
|
41
37
|
Params extends string[] & ExtractOpenapiParams<Uri>,
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
: ResponseCode extends undefined
|
|
45
|
-
? undefined
|
|
46
|
-
: ResponseCode extends number
|
|
47
|
-
? ResponseMap[ResponseCode & keyof ResponseMap]['content' &
|
|
48
|
-
keyof ResponseMap[ResponseCode & keyof ResponseMap]]
|
|
49
|
-
: undefined,
|
|
50
|
-
JsonContent extends Content extends undefined
|
|
51
|
-
? undefined
|
|
52
|
-
: Content['application/json' & keyof Content],
|
|
38
|
+
Query extends OpenapiSpecRequestOptsGet<RequestQueryParameters<OpenapiPaths, 'get', Uri>>,
|
|
39
|
+
JsonContent extends ResponseBody<OpenapiPaths, 'get', Uri, ResponseCode>,
|
|
53
40
|
>(
|
|
54
41
|
/**
|
|
55
42
|
* The uri on your background you are trying to hit.
|
|
@@ -102,115 +89,7 @@ export class OpenapiSpecRequest<OpenapiPaths = undefined> {
|
|
|
102
89
|
* @param opts.headers - headers you would like to send with your request.
|
|
103
90
|
* (Optional)
|
|
104
91
|
*/
|
|
105
|
-
opts
|
|
106
|
-
? never
|
|
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
|
|
92
|
+
opts?: Params['length'] extends 0 ? Query : Query & { [K in Params[number]]: string | IdType }
|
|
214
93
|
): Promise<OpenapiSpecResponse<JsonContent>> {
|
|
215
94
|
return (await this.makeRequest(
|
|
216
95
|
'get',
|
|
@@ -220,44 +99,16 @@ export class OpenapiSpecRequest<OpenapiPaths = undefined> {
|
|
|
220
99
|
)) as OpenapiSpecResponse<JsonContent>
|
|
221
100
|
}
|
|
222
101
|
|
|
223
|
-
//
|
|
224
|
-
//
|
|
225
|
-
//
|
|
226
|
-
// begin: POST
|
|
227
|
-
// has Params
|
|
228
102
|
public async post<
|
|
229
103
|
const Uri extends RoutesWithHttpMethod<
|
|
230
104
|
OpenapiPaths,
|
|
231
105
|
'post' & keyof OpenapiPaths[keyof OpenapiPaths]
|
|
232
106
|
> &
|
|
233
107
|
string,
|
|
234
|
-
const ResponseCode extends
|
|
235
|
-
? never
|
|
236
|
-
: keyof ExcludeNever<ResponseMap> & number,
|
|
237
|
-
HttpMethodMap extends OpenapiPaths[ResolvedUri & keyof OpenapiPaths],
|
|
238
|
-
ResolvedUri extends First<GetResolvedOpenapiUrl<OpenapiPaths, Uri> & keyof OpenapiPaths>,
|
|
108
|
+
const ResponseCode extends ResponseCodeForUri<OpenapiPaths, Uri, 'post'>,
|
|
239
109
|
Params extends string[] & ExtractOpenapiParams<Uri>,
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
Content extends ResponseMap extends undefined
|
|
243
|
-
? undefined
|
|
244
|
-
: ResponseCode extends undefined
|
|
245
|
-
? undefined
|
|
246
|
-
: ResponseCode extends number
|
|
247
|
-
? ResponseMap[ResponseCode & keyof ResponseMap]['content' &
|
|
248
|
-
keyof ResponseMap[ResponseCode & keyof ResponseMap]]
|
|
249
|
-
: undefined,
|
|
250
|
-
JsonContent extends Content extends undefined
|
|
251
|
-
? undefined
|
|
252
|
-
: Content['application/json' & keyof Content],
|
|
253
|
-
RequestBodyMap extends HttpMethodMap['post' & keyof HttpMethodMap]['requestBody' &
|
|
254
|
-
keyof HttpMethodMap['post' & keyof HttpMethodMap]],
|
|
255
|
-
RequestBodyContent extends RequestBodyMap extends undefined
|
|
256
|
-
? undefined
|
|
257
|
-
: RequestBodyMap['content' & keyof RequestBodyMap],
|
|
258
|
-
RequestBodyJsonContent extends RequestBodyContent extends undefined
|
|
259
|
-
? undefined
|
|
260
|
-
: RequestBodyContent['application/json' & keyof RequestBodyContent],
|
|
110
|
+
RequestBodyJsonContent extends RequestBody<OpenapiPaths, 'post', Uri>,
|
|
111
|
+
JsonContent extends ResponseBody<OpenapiPaths, 'post', Uri, ResponseCode>,
|
|
261
112
|
>(
|
|
262
113
|
/**
|
|
263
114
|
* The uri on your background you are trying to hit.
|
|
@@ -313,162 +164,23 @@ export class OpenapiSpecRequest<OpenapiPaths = undefined> {
|
|
|
313
164
|
* @param opts.headers - headers you would like to send with your request.
|
|
314
165
|
* (Optional)
|
|
315
166
|
*/
|
|
316
|
-
opts
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
public async post<
|
|
320
|
-
const Uri extends RoutesWithHttpMethod<
|
|
321
|
-
OpenapiPaths,
|
|
322
|
-
'post' & keyof OpenapiPaths[keyof OpenapiPaths]
|
|
323
|
-
> &
|
|
324
|
-
string,
|
|
325
|
-
const ResponseCode extends Params['length'] extends 0
|
|
326
|
-
? keyof ExcludeNever<ResponseMap> & number
|
|
327
|
-
: never,
|
|
328
|
-
HttpMethodMap extends OpenapiPaths[Uri & keyof OpenapiPaths],
|
|
329
|
-
Params extends string[] & ExtractOpenapiParams<Uri>,
|
|
330
|
-
ResponseMap extends HttpMethodMap['post' & keyof HttpMethodMap]['responses' &
|
|
331
|
-
keyof HttpMethodMap['post' & keyof HttpMethodMap]],
|
|
332
|
-
Content extends ResponseMap extends undefined
|
|
333
|
-
? undefined
|
|
334
|
-
: ResponseCode extends undefined
|
|
335
|
-
? undefined
|
|
336
|
-
: ResponseCode extends number
|
|
337
|
-
? ResponseMap[ResponseCode & keyof ResponseMap]['content' &
|
|
338
|
-
keyof ResponseMap[ResponseCode & keyof ResponseMap]]
|
|
339
|
-
: undefined,
|
|
340
|
-
JsonContent extends Content extends undefined
|
|
341
|
-
? undefined
|
|
342
|
-
: Content['application/json' & keyof Content],
|
|
343
|
-
RequestBodyMap extends HttpMethodMap['post' & keyof HttpMethodMap]['requestBody' &
|
|
344
|
-
keyof HttpMethodMap['post' & keyof HttpMethodMap]],
|
|
345
|
-
RequestBodyContent extends RequestBodyMap extends undefined
|
|
346
|
-
? undefined
|
|
347
|
-
: RequestBodyMap['content' & keyof RequestBodyMap],
|
|
348
|
-
RequestBodyJsonContent extends RequestBodyContent extends undefined
|
|
349
|
-
? undefined
|
|
350
|
-
: RequestBodyContent['application/json' & keyof RequestBodyContent],
|
|
351
|
-
>(
|
|
352
|
-
/**
|
|
353
|
-
* The uri on your background you are trying to hit.
|
|
354
|
-
* This should be a path, like '/users'.
|
|
355
|
-
*
|
|
356
|
-
* ```ts
|
|
357
|
-
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
358
|
-
* const res = await request.post('/user', 200)
|
|
359
|
-
* ```
|
|
360
|
-
*/
|
|
361
|
-
uri: Uri,
|
|
362
|
-
|
|
363
|
-
/**
|
|
364
|
-
* The response status you are expecting to receive
|
|
365
|
-
* when making this request. It will need to match
|
|
366
|
-
* one of the accepted response statuses for the
|
|
367
|
-
* provided uri in your openapi types
|
|
368
|
-
*
|
|
369
|
-
* ```ts
|
|
370
|
-
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
371
|
-
* const res = await request.post('/user', 200)
|
|
372
|
-
* ```
|
|
373
|
-
*/
|
|
374
|
-
expectedStatus: ResponseCode,
|
|
375
|
-
|
|
376
|
-
/**
|
|
377
|
-
* Data, headers, and other options to send with
|
|
378
|
-
* your request.
|
|
379
|
-
*
|
|
380
|
-
* ```ts
|
|
381
|
-
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
382
|
-
* const res = await request.post(
|
|
383
|
-
* '/user',
|
|
384
|
-
* 200,
|
|
385
|
-
* {
|
|
386
|
-
* data: {
|
|
387
|
-
* ...request body here
|
|
388
|
-
* },
|
|
389
|
-
* headers: {
|
|
390
|
-
* ...headers here
|
|
391
|
-
* },
|
|
392
|
-
* }
|
|
393
|
-
* )
|
|
394
|
-
* ```
|
|
395
|
-
*
|
|
396
|
-
* @param opts.data - request body data you want to send up. Must match the
|
|
397
|
-
* requestBody shape in the openapi document for this uri.
|
|
398
|
-
* (Optional)
|
|
399
|
-
*
|
|
400
|
-
* @param opts.headers - headers you would like to send with your request.
|
|
401
|
-
* (Optional)
|
|
402
|
-
*/
|
|
403
|
-
opts?: Params['length'] extends 0 ? OpenapiSpecRequestOptsPost<RequestBodyJsonContent> : never
|
|
404
|
-
): Promise<OpenapiSpecResponse<JsonContent>>
|
|
405
|
-
// final
|
|
406
|
-
public async post<
|
|
407
|
-
const Uri extends RoutesWithHttpMethod<
|
|
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 = {}
|
|
167
|
+
opts?: Params['length'] extends 0
|
|
168
|
+
? OpenapiSpecRequestOptsPost<RequestBodyJsonContent>
|
|
169
|
+
: OpenapiSpecRequestOptsPost<RequestBodyJsonContent> & { [K in Params[number]]: string }
|
|
431
170
|
): Promise<OpenapiSpecResponse<JsonContent>> {
|
|
432
171
|
return await this.makeRequest('post', uri, expectedStatus, opts as SpecRequestOptsAll)
|
|
433
172
|
}
|
|
434
173
|
|
|
435
|
-
//
|
|
436
|
-
//
|
|
437
|
-
//
|
|
438
|
-
// begin: PUT
|
|
439
|
-
// has Params
|
|
440
174
|
public async put<
|
|
441
175
|
const Uri extends RoutesWithHttpMethod<
|
|
442
176
|
OpenapiPaths,
|
|
443
177
|
'put' & keyof OpenapiPaths[keyof OpenapiPaths]
|
|
444
178
|
> &
|
|
445
179
|
string,
|
|
446
|
-
const ResponseCode extends
|
|
447
|
-
? never
|
|
448
|
-
: keyof ExcludeNever<ResponseMap> & number,
|
|
449
|
-
HttpMethodMap extends OpenapiPaths[Uri & keyof OpenapiPaths],
|
|
180
|
+
const ResponseCode extends ResponseCodeForUri<OpenapiPaths, Uri, 'put'>,
|
|
450
181
|
Params extends string[] & ExtractOpenapiParams<Uri>,
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
Content extends ResponseMap extends undefined
|
|
454
|
-
? undefined
|
|
455
|
-
: ResponseCode extends undefined
|
|
456
|
-
? undefined
|
|
457
|
-
: ResponseCode extends number
|
|
458
|
-
? ResponseMap[ResponseCode & keyof ResponseMap]['content' &
|
|
459
|
-
keyof ResponseMap[ResponseCode & keyof ResponseMap]]
|
|
460
|
-
: undefined,
|
|
461
|
-
JsonContent extends Content extends undefined
|
|
462
|
-
? undefined
|
|
463
|
-
: Content['application/json' & keyof Content],
|
|
464
|
-
RequestBodyMap extends HttpMethodMap['put' & keyof HttpMethodMap]['requestBody' &
|
|
465
|
-
keyof HttpMethodMap['put' & keyof HttpMethodMap]],
|
|
466
|
-
RequestBodyContent extends RequestBodyMap extends undefined
|
|
467
|
-
? undefined
|
|
468
|
-
: RequestBodyMap['content' & keyof RequestBodyMap],
|
|
469
|
-
RequestBodyJsonContent extends RequestBodyContent extends undefined
|
|
470
|
-
? undefined
|
|
471
|
-
: RequestBodyContent['application/json' & keyof RequestBodyContent],
|
|
182
|
+
JsonContent extends ResponseBody<OpenapiPaths, 'put', Uri, ResponseCode>,
|
|
183
|
+
RequestBodyJsonContent extends RequestBody<OpenapiPaths, 'put', Uri>,
|
|
472
184
|
>(
|
|
473
185
|
/**
|
|
474
186
|
* The uri on your background you are trying to hit.
|
|
@@ -525,127 +237,11 @@ export class OpenapiSpecRequest<OpenapiPaths = undefined> {
|
|
|
525
237
|
* @param opts.headers - headers you would like to send with your request.
|
|
526
238
|
* (Optional)
|
|
527
239
|
*/
|
|
528
|
-
opts
|
|
529
|
-
?
|
|
240
|
+
opts?: Params['length'] extends 0
|
|
241
|
+
? OpenapiSpecRequestOptsPost<RequestBodyJsonContent>
|
|
530
242
|
: OpenapiSpecRequestOptsPost<RequestBodyJsonContent> & {
|
|
531
243
|
[K in Params[number]]: string | IdType
|
|
532
244
|
}
|
|
533
|
-
): Promise<OpenapiSpecResponse<JsonContent>>
|
|
534
|
-
// DOESNT have params
|
|
535
|
-
public async put<
|
|
536
|
-
const Uri extends RoutesWithHttpMethod<
|
|
537
|
-
OpenapiPaths,
|
|
538
|
-
'put' & keyof OpenapiPaths[keyof OpenapiPaths]
|
|
539
|
-
> &
|
|
540
|
-
string,
|
|
541
|
-
const ResponseCode extends Params['length'] extends 0
|
|
542
|
-
? keyof ExcludeNever<ResponseMap> & number
|
|
543
|
-
: never,
|
|
544
|
-
HttpMethodMap extends OpenapiPaths[Uri & keyof OpenapiPaths],
|
|
545
|
-
Params extends string[] & ExtractOpenapiParams<Uri>,
|
|
546
|
-
ResponseMap extends HttpMethodMap['put' & keyof HttpMethodMap]['responses' &
|
|
547
|
-
keyof HttpMethodMap['put' & keyof HttpMethodMap]],
|
|
548
|
-
Content extends ResponseMap extends undefined
|
|
549
|
-
? undefined
|
|
550
|
-
: ResponseCode extends undefined
|
|
551
|
-
? undefined
|
|
552
|
-
: ResponseCode extends number
|
|
553
|
-
? ResponseMap[ResponseCode & keyof ResponseMap]['content' &
|
|
554
|
-
keyof ResponseMap[ResponseCode & keyof ResponseMap]]
|
|
555
|
-
: undefined,
|
|
556
|
-
JsonContent extends Content extends undefined
|
|
557
|
-
? undefined
|
|
558
|
-
: Content['application/json' & keyof Content],
|
|
559
|
-
RequestBodyMap extends HttpMethodMap['put' & keyof HttpMethodMap]['requestBody' &
|
|
560
|
-
keyof HttpMethodMap['put' & keyof HttpMethodMap]],
|
|
561
|
-
RequestBodyContent extends RequestBodyMap extends undefined
|
|
562
|
-
? undefined
|
|
563
|
-
: RequestBodyMap['content' & keyof RequestBodyMap],
|
|
564
|
-
RequestBodyJsonContent extends RequestBodyContent extends undefined
|
|
565
|
-
? undefined
|
|
566
|
-
: RequestBodyContent['application/json' & keyof RequestBodyContent],
|
|
567
|
-
>(
|
|
568
|
-
/**
|
|
569
|
-
* The uri on your background you are trying to hit.
|
|
570
|
-
* This should be a path, like '/users'.
|
|
571
|
-
*
|
|
572
|
-
* ```ts
|
|
573
|
-
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
574
|
-
* const res = await request.put('/user', 200, { data: { name: 'new name' })
|
|
575
|
-
* ```
|
|
576
|
-
*/
|
|
577
|
-
uri: Uri,
|
|
578
|
-
|
|
579
|
-
/**
|
|
580
|
-
* The response status you are expecting to receive
|
|
581
|
-
* when making this request. It will need to match
|
|
582
|
-
* one of the accepted response statuses for the
|
|
583
|
-
* provided uri in your openapi types
|
|
584
|
-
*
|
|
585
|
-
* ```ts
|
|
586
|
-
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
587
|
-
* const res = await request.put('/user', 200, { data: { name: 'new name' })
|
|
588
|
-
* ```
|
|
589
|
-
*/
|
|
590
|
-
expectedStatus: ResponseCode,
|
|
591
|
-
|
|
592
|
-
/**
|
|
593
|
-
* An object containing the path fields required to
|
|
594
|
-
* fill your uri in, as well as any additional PUT
|
|
595
|
-
* arguments, like `data`, for example.
|
|
596
|
-
*
|
|
597
|
-
*
|
|
598
|
-
* ```ts
|
|
599
|
-
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
600
|
-
* const res = await request.put(
|
|
601
|
-
* '/user',
|
|
602
|
-
* 200,
|
|
603
|
-
* {
|
|
604
|
-
* data: {
|
|
605
|
-
* ...request body here
|
|
606
|
-
* },
|
|
607
|
-
* headers: {
|
|
608
|
-
* ...headers here
|
|
609
|
-
* },
|
|
610
|
-
* }
|
|
611
|
-
* )
|
|
612
|
-
* ```
|
|
613
|
-
*
|
|
614
|
-
* @param opts.data - request body data you want to send up. Must match the
|
|
615
|
-
* requestBody shape in the openapi document for this uri.
|
|
616
|
-
* (Optional)
|
|
617
|
-
*
|
|
618
|
-
* @param opts.headers - headers you would like to send with your request.
|
|
619
|
-
* (Optional)
|
|
620
|
-
*/
|
|
621
|
-
opts?: Params['length'] extends 0 ? OpenapiSpecRequestOptsPost<RequestBodyJsonContent> : never
|
|
622
|
-
): Promise<OpenapiSpecResponse<JsonContent>>
|
|
623
|
-
// final
|
|
624
|
-
public async put<
|
|
625
|
-
const Uri extends RoutesWithHttpMethod<
|
|
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 = {}
|
|
649
245
|
): Promise<OpenapiSpecResponse<JsonContent>> {
|
|
650
246
|
return await this.makeRequest(
|
|
651
247
|
'put',
|
|
@@ -655,43 +251,16 @@ export class OpenapiSpecRequest<OpenapiPaths = undefined> {
|
|
|
655
251
|
)
|
|
656
252
|
}
|
|
657
253
|
|
|
658
|
-
//
|
|
659
|
-
//
|
|
660
|
-
//
|
|
661
|
-
// begin: PATCH
|
|
662
|
-
// has Params
|
|
663
254
|
public async patch<
|
|
664
255
|
const Uri extends RoutesWithHttpMethod<
|
|
665
256
|
OpenapiPaths,
|
|
666
257
|
'patch' & keyof OpenapiPaths[keyof OpenapiPaths]
|
|
667
258
|
> &
|
|
668
259
|
string,
|
|
669
|
-
const ResponseCode extends
|
|
670
|
-
? never
|
|
671
|
-
: keyof ExcludeNever<ResponseMap> & number,
|
|
672
|
-
HttpMethodMap extends OpenapiPaths[Uri & keyof OpenapiPaths],
|
|
260
|
+
const ResponseCode extends ResponseCodeForUri<OpenapiPaths, Uri, 'patch'>,
|
|
673
261
|
Params extends string[] & ExtractOpenapiParams<Uri>,
|
|
674
|
-
|
|
675
|
-
|
|
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],
|
|
262
|
+
JsonContent extends ResponseBody<OpenapiPaths, 'patch', Uri, ResponseCode>,
|
|
263
|
+
RequestBodyJsonContent extends RequestBody<OpenapiPaths, 'patch', Uri>,
|
|
695
264
|
>(
|
|
696
265
|
/**
|
|
697
266
|
* The uri on your background you are trying to hit.
|
|
@@ -747,176 +316,30 @@ export class OpenapiSpecRequest<OpenapiPaths = undefined> {
|
|
|
747
316
|
* @param opts.headers - headers you would like to send with your request.
|
|
748
317
|
* (Optional)
|
|
749
318
|
*/
|
|
750
|
-
opts
|
|
751
|
-
?
|
|
319
|
+
opts?: Params['length'] extends 0
|
|
320
|
+
? OpenapiSpecRequestOptsPost<RequestBodyJsonContent>
|
|
752
321
|
: OpenapiSpecRequestOptsPost<RequestBodyJsonContent> & {
|
|
753
322
|
[K in Params[number]]: string | IdType
|
|
754
323
|
}
|
|
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
324
|
): Promise<OpenapiSpecResponse<JsonContent>> {
|
|
875
325
|
return await this.makeRequest(
|
|
876
326
|
'patch',
|
|
877
|
-
fillOpenapiParams(uri, opts),
|
|
327
|
+
fillOpenapiParams(uri, opts!),
|
|
878
328
|
expectedStatus,
|
|
879
329
|
opts as SpecRequestOptsAll
|
|
880
330
|
)
|
|
881
331
|
}
|
|
882
332
|
|
|
883
|
-
//
|
|
884
|
-
//
|
|
885
|
-
//
|
|
886
|
-
// begin: delete
|
|
887
|
-
// has Params
|
|
888
333
|
public async delete<
|
|
889
334
|
const Uri extends RoutesWithHttpMethod<
|
|
890
335
|
OpenapiPaths,
|
|
891
336
|
'delete' & keyof OpenapiPaths[keyof OpenapiPaths]
|
|
892
337
|
> &
|
|
893
338
|
string,
|
|
894
|
-
const ResponseCode extends
|
|
895
|
-
? never
|
|
896
|
-
: keyof ExcludeNever<ResponseMap> & number,
|
|
897
|
-
HttpMethodMap extends OpenapiPaths[Uri & keyof OpenapiPaths],
|
|
339
|
+
const ResponseCode extends ResponseCodeForUri<OpenapiPaths, Uri, 'delete'>,
|
|
898
340
|
Params extends string[] & ExtractOpenapiParams<Uri>,
|
|
899
|
-
|
|
900
|
-
|
|
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],
|
|
341
|
+
JsonContent extends ResponseBody<OpenapiPaths, 'delete', Uri, ResponseCode>,
|
|
342
|
+
RequestBodyJsonContent extends RequestBody<OpenapiPaths, 'delete', Uri>,
|
|
920
343
|
>(
|
|
921
344
|
/**
|
|
922
345
|
* The uri on your background you are trying to hit.
|
|
@@ -972,151 +395,20 @@ export class OpenapiSpecRequest<OpenapiPaths = undefined> {
|
|
|
972
395
|
* @param opts.headers - headers you would like to send with your request.
|
|
973
396
|
* (Optional)
|
|
974
397
|
*/
|
|
975
|
-
opts
|
|
976
|
-
?
|
|
398
|
+
opts?: Params['length'] extends 0
|
|
399
|
+
? OpenapiSpecRequestOptsPost<RequestBodyJsonContent>
|
|
977
400
|
: OpenapiSpecRequestOptsPost<RequestBodyJsonContent> & {
|
|
978
401
|
[K in Params[number]]: string | IdType
|
|
979
402
|
}
|
|
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
|
-
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
403
|
): Promise<OpenapiSpecResponse<JsonContent>> {
|
|
1100
404
|
return await this.makeRequest(
|
|
1101
405
|
'delete',
|
|
1102
|
-
fillOpenapiParams(uri, opts),
|
|
406
|
+
fillOpenapiParams(uri, opts || {}),
|
|
1103
407
|
expectedStatus,
|
|
1104
408
|
opts as SpecRequestOptsAll
|
|
1105
409
|
)
|
|
1106
410
|
}
|
|
1107
411
|
|
|
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
412
|
public async session<
|
|
1121
413
|
const ProvidedHttpMethod extends HttpMethod,
|
|
1122
414
|
const Uri extends RoutesWithHttpMethod<
|
|
@@ -1124,24 +416,10 @@ export class OpenapiSpecRequest<OpenapiPaths = undefined> {
|
|
|
1124
416
|
ProvidedHttpMethod & keyof OpenapiPaths[keyof OpenapiPaths]
|
|
1125
417
|
> &
|
|
1126
418
|
string,
|
|
1127
|
-
const ResponseCode extends
|
|
1128
|
-
? never
|
|
1129
|
-
: keyof ExcludeNever<ResponseMap> & number,
|
|
1130
|
-
HttpMethodMap extends OpenapiPaths[Uri & keyof OpenapiPaths],
|
|
419
|
+
const ResponseCode extends ResponseCodeForUri<OpenapiPaths, Uri, ProvidedHttpMethod>,
|
|
1131
420
|
Params extends string[] & ExtractOpenapiParams<Uri>,
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
ParametersMap extends HttpMethodMap[ProvidedHttpMethod & keyof HttpMethodMap]['parameters' &
|
|
1135
|
-
keyof HttpMethodMap[ProvidedHttpMethod & keyof HttpMethodMap]],
|
|
1136
|
-
QueryMap extends ParametersMap['query' & keyof ParametersMap],
|
|
1137
|
-
RequestBodyMap extends HttpMethodMap[ProvidedHttpMethod & keyof HttpMethodMap]['requestBody' &
|
|
1138
|
-
keyof HttpMethodMap[ProvidedHttpMethod & keyof HttpMethodMap]],
|
|
1139
|
-
RequestBodyContent extends RequestBodyMap extends undefined
|
|
1140
|
-
? undefined
|
|
1141
|
-
: RequestBodyMap['content' & keyof RequestBodyMap],
|
|
1142
|
-
RequestBodyJsonContent extends RequestBodyContent extends undefined
|
|
1143
|
-
? undefined
|
|
1144
|
-
: RequestBodyContent['application/json' & keyof RequestBodyContent],
|
|
421
|
+
JsonContent extends RequestBody<OpenapiPaths, ProvidedHttpMethod, Uri>,
|
|
422
|
+
Query extends OpenapiSpecRequestOptsGet<RequestQueryParameters<OpenapiPaths, 'get', Uri>>,
|
|
1145
423
|
>(
|
|
1146
424
|
httpMethod: ProvidedHttpMethod,
|
|
1147
425
|
/**
|
|
@@ -1209,133 +487,14 @@ export class OpenapiSpecRequest<OpenapiPaths = undefined> {
|
|
|
1209
487
|
* @param opts.headers - headers you would like to send with your request.
|
|
1210
488
|
* (Optional)
|
|
1211
489
|
*/
|
|
1212
|
-
opts
|
|
1213
|
-
? OpenapiSpecRequestOptsGet<
|
|
1214
|
-
: OpenapiSpecRequestOptsPost<
|
|
490
|
+
opts?: (ProvidedHttpMethod extends 'get'
|
|
491
|
+
? OpenapiSpecRequestOptsGet<Query>
|
|
492
|
+
: OpenapiSpecRequestOptsPost<JsonContent>) & {
|
|
1215
493
|
[K in Params[number]]: string | IdType
|
|
1216
494
|
}
|
|
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
495
|
): Promise<OpenapiSpecSession<OpenapiPaths>> {
|
|
1337
|
-
const postOpts = opts as OpenapiSpecRequestOptsPost
|
|
1338
|
-
const getOpts = opts as OpenapiSpecRequestOptsGet
|
|
496
|
+
const postOpts = (opts || {}) as OpenapiSpecRequestOptsPost
|
|
497
|
+
const getOpts = (opts || {}) as OpenapiSpecRequestOptsGet
|
|
1339
498
|
|
|
1340
499
|
uri = fillOpenapiParams(uri, (opts || {}) as object) as Uri
|
|
1341
500
|
|