@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
|
@@ -6,25 +6,303 @@ export class OpenapiSpecSession {
|
|
|
6
6
|
constructor(_session) {
|
|
7
7
|
this._session = _session;
|
|
8
8
|
}
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
async get(
|
|
10
|
+
/**
|
|
11
|
+
* The uri on your background you are trying to hit.
|
|
12
|
+
* This should be a path, like '/users'.
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
16
|
+
* const session = await request.session('post', '/sessions/{token}', 200, { token: 'abc' })
|
|
17
|
+
* const res = await session.get('/posts/{id}', 200, { id: '123' })
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
uri,
|
|
21
|
+
/**
|
|
22
|
+
* The response status you are expecting to receive
|
|
23
|
+
* when making this request. It will need to match
|
|
24
|
+
* one of the accepted response statuses for the
|
|
25
|
+
* provided uri in your openapi types
|
|
26
|
+
*
|
|
27
|
+
* ```ts
|
|
28
|
+
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
29
|
+
* const session = await request.session('post', '/sessions/{token}', 200, { token: 'abc' })
|
|
30
|
+
* const res = await session.get('/posts/{id}', 200, { id: '123' })
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
expectedStatus,
|
|
34
|
+
/**
|
|
35
|
+
* An object containing the path fields required to
|
|
36
|
+
* fill your uri in, as well as any additional GET
|
|
37
|
+
* arguments, like `query`, for example.
|
|
38
|
+
*
|
|
39
|
+
* ```ts
|
|
40
|
+
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
41
|
+
* const session = await request.session('post', '/sessions/{token}', 200, { token: 'abc' })
|
|
42
|
+
* const res = await session.get(
|
|
43
|
+
* '/posts/{postId}/comments/{id}',
|
|
44
|
+
* 200,
|
|
45
|
+
* {
|
|
46
|
+
* postId: '123',
|
|
47
|
+
* id: '456',
|
|
48
|
+
* query: {
|
|
49
|
+
* ...query params here
|
|
50
|
+
* }
|
|
51
|
+
* }
|
|
52
|
+
* )
|
|
53
|
+
* ```
|
|
54
|
+
*
|
|
55
|
+
* @param opts.query - query params you want to send up. Must match the
|
|
56
|
+
* query params in the openapi document for this uri.
|
|
57
|
+
* (Optional)
|
|
58
|
+
*
|
|
59
|
+
* @param opts.headers - headers you would like to send with your request.
|
|
60
|
+
* (Optional)
|
|
61
|
+
*/
|
|
62
|
+
opts) {
|
|
11
63
|
return (await this.makeRequest('get', fillOpenapiParams(uri, (opts || {})), expectedStatus, opts));
|
|
12
64
|
}
|
|
13
|
-
//
|
|
14
|
-
|
|
65
|
+
//
|
|
66
|
+
//
|
|
67
|
+
//
|
|
68
|
+
// begin: POST
|
|
69
|
+
// has Params
|
|
70
|
+
async post(
|
|
71
|
+
/**
|
|
72
|
+
* The uri on your background you are trying to hit.
|
|
73
|
+
* This should be a path, like '/users'.
|
|
74
|
+
*
|
|
75
|
+
* ```ts
|
|
76
|
+
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
77
|
+
* const session = await request.session('post', '/sessions/{token}', 200, { token: 'abc' })
|
|
78
|
+
* const res = await session.post('/posts/{id}', 200, { id: '123' })
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
uri,
|
|
82
|
+
/**
|
|
83
|
+
* The response status you are expecting to receive
|
|
84
|
+
* when making this request. It will need to match
|
|
85
|
+
* one of the accepted response statuses for the
|
|
86
|
+
* provided uri in your openapi types
|
|
87
|
+
*
|
|
88
|
+
* ```ts
|
|
89
|
+
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
90
|
+
* const session = await request.session('post', '/sessions/{token}', 200, { token: 'abc' })
|
|
91
|
+
* const res = await session.post('/posts/{id}', 200, { id: '123' })
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
expectedStatus,
|
|
95
|
+
/**
|
|
96
|
+
* An object containing the path fields required to
|
|
97
|
+
* fill your uri in, as well as any additional POST
|
|
98
|
+
* arguments, like `data`, for example.
|
|
99
|
+
*
|
|
100
|
+
* ```ts
|
|
101
|
+
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
102
|
+
* const session = await request.session('post', '/sessions/{token}', 200, { token: 'abc' })
|
|
103
|
+
* const res = await session.post(
|
|
104
|
+
* '/posts/{postId}/comments/{id}',
|
|
105
|
+
* 200,
|
|
106
|
+
* {
|
|
107
|
+
* postId: '123',
|
|
108
|
+
* commentId: '456',
|
|
109
|
+
* data: {
|
|
110
|
+
* ...request body here
|
|
111
|
+
* },
|
|
112
|
+
* headers: {
|
|
113
|
+
* ...headers here
|
|
114
|
+
* },
|
|
115
|
+
* }
|
|
116
|
+
* )
|
|
117
|
+
* ```
|
|
118
|
+
*
|
|
119
|
+
* @param opts.data - request body data you want to send up. Must match the
|
|
120
|
+
* requestBody shape in the openapi document for this uri.
|
|
121
|
+
* (Optional)
|
|
122
|
+
*
|
|
123
|
+
* @param opts.headers - headers you would like to send with your request.
|
|
124
|
+
* (Optional)
|
|
125
|
+
*/
|
|
126
|
+
opts) {
|
|
15
127
|
return await this.makeRequest('post', uri, expectedStatus, opts);
|
|
16
128
|
}
|
|
17
|
-
|
|
18
|
-
|
|
129
|
+
async put(
|
|
130
|
+
/**
|
|
131
|
+
* The uri on your background you are trying to hit.
|
|
132
|
+
* This should be a path, like '/users'.
|
|
133
|
+
*
|
|
134
|
+
* ```ts
|
|
135
|
+
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
136
|
+
* const session = await request.session('post', '/sessions/{token}', 200, { token: 'abc' })
|
|
137
|
+
* const res = await session.put('/posts/{id}', 200, { id: '123', data: { name: 'new name' }})
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
uri,
|
|
141
|
+
/**
|
|
142
|
+
* The response status you are expecting to receive
|
|
143
|
+
* when making this request. It will need to match
|
|
144
|
+
* one of the accepted response statuses for the
|
|
145
|
+
* provided uri in your openapi types
|
|
146
|
+
*
|
|
147
|
+
* ```ts
|
|
148
|
+
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
149
|
+
* const session = await request.session('post', '/sessions/{token}', 200, { token: 'abc' })
|
|
150
|
+
* const res = await session.put('/posts/{id}', 200, { id: '123', data: { name: 'new name' }})
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
expectedStatus,
|
|
154
|
+
/**
|
|
155
|
+
* An object containing the path fields required to
|
|
156
|
+
* fill your uri in, as well as any additional PUT
|
|
157
|
+
* arguments, like `data`, for example.
|
|
158
|
+
*
|
|
159
|
+
* ```ts
|
|
160
|
+
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
161
|
+
* const session = await request.session('post', '/sessions/{token}', 200, { token: 'abc' })
|
|
162
|
+
* const res = await session.put(
|
|
163
|
+
* '/posts/{id}/comments/{commentId}',
|
|
164
|
+
* 200,
|
|
165
|
+
* {
|
|
166
|
+
* postId: '123',
|
|
167
|
+
* id: '456',
|
|
168
|
+
*
|
|
169
|
+
* data: {
|
|
170
|
+
* ...request body here
|
|
171
|
+
* },
|
|
172
|
+
* headers: {
|
|
173
|
+
* ...headers here
|
|
174
|
+
* },
|
|
175
|
+
* }
|
|
176
|
+
* )
|
|
177
|
+
* ```
|
|
178
|
+
*
|
|
179
|
+
* @param opts.data - request body data you want to send up. Must match the
|
|
180
|
+
* requestBody shape 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) {
|
|
19
187
|
return await this.makeRequest('put', fillOpenapiParams(uri, opts || {}), expectedStatus, opts);
|
|
20
188
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
189
|
+
async patch(
|
|
190
|
+
/**
|
|
191
|
+
* The uri on your background you are trying to hit.
|
|
192
|
+
* This should be a path, like '/posts'.
|
|
193
|
+
*
|
|
194
|
+
* ```ts
|
|
195
|
+
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
196
|
+
* const session = await request.session('post', '/sessions/{token}', 200, { token: 'abc' })
|
|
197
|
+
* const res = await session.patch('/posts/{id}', 200, { data: { name: 'new name' }})
|
|
198
|
+
* ```
|
|
199
|
+
*/
|
|
200
|
+
uri,
|
|
201
|
+
/**
|
|
202
|
+
* The response status you are expecting to receive
|
|
203
|
+
* when making this request. It will need to match
|
|
204
|
+
* one of the accepted response statuses for the
|
|
205
|
+
* provided uri in your openapi types
|
|
206
|
+
*
|
|
207
|
+
* ```ts
|
|
208
|
+
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
209
|
+
* const session = await request.session('post', '/sessions/{token}', 200, { token: 'abc' })
|
|
210
|
+
* const res = await session.patch('/posts/{id}', 200, { data: { name: 'new name' }})
|
|
211
|
+
* ```
|
|
212
|
+
*/
|
|
213
|
+
expectedStatus,
|
|
214
|
+
/**
|
|
215
|
+
* An object containing the path fields required to
|
|
216
|
+
* fill your uri in, as well as any additional PATCH
|
|
217
|
+
* arguments, like `data`, for example.
|
|
218
|
+
*
|
|
219
|
+
* ```ts
|
|
220
|
+
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
221
|
+
* const session = await request.session('post', '/sessions/{token}', 200, { token: 'abc' })
|
|
222
|
+
* const res = await session.patch(
|
|
223
|
+
* '/posts/{postId}/comments/{id}',
|
|
224
|
+
* 200,
|
|
225
|
+
* {
|
|
226
|
+
* postId: '123',
|
|
227
|
+
* commentId: '456',
|
|
228
|
+
* data: {
|
|
229
|
+
* ...request body here
|
|
230
|
+
* },
|
|
231
|
+
* headers: {
|
|
232
|
+
* ...headers here
|
|
233
|
+
* },
|
|
234
|
+
* }
|
|
235
|
+
* )
|
|
236
|
+
* ```
|
|
237
|
+
*
|
|
238
|
+
* @param opts.data - request body data you want to send up. Must match the
|
|
239
|
+
* requestBody shape in the openapi document for this uri.
|
|
240
|
+
* (Optional)
|
|
241
|
+
*
|
|
242
|
+
* @param opts.headers - headers you would like to send with your request.
|
|
243
|
+
* (Optional)
|
|
244
|
+
*/
|
|
245
|
+
opts) {
|
|
246
|
+
return await this.makeRequest('patch', fillOpenapiParams(uri, opts || {}), expectedStatus, opts);
|
|
24
247
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
248
|
+
async delete(
|
|
249
|
+
/**
|
|
250
|
+
* The uri on your background you are trying to hit.
|
|
251
|
+
* This should be a path, like '/users'.
|
|
252
|
+
*
|
|
253
|
+
* ```ts
|
|
254
|
+
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
255
|
+
* const session = await request.session('post', '/sessions/{token}', 200, { token: 'abc' })
|
|
256
|
+
* const res = await session.delete('/posts/{id}', 200, { id: '123' })
|
|
257
|
+
* ```
|
|
258
|
+
*/
|
|
259
|
+
uri,
|
|
260
|
+
/**
|
|
261
|
+
* The response status you are expecting to receive
|
|
262
|
+
* when making this request. It will need to match
|
|
263
|
+
* one of the accepted response statuses for the
|
|
264
|
+
* provided uri in your openapi types
|
|
265
|
+
*
|
|
266
|
+
* ```ts
|
|
267
|
+
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
268
|
+
* const session = await request.session('post', '/sessions/{token}', 200, { token: 'abc' })
|
|
269
|
+
* const res = await session.delete('/posts/{id}', 200, { id: '123' })
|
|
270
|
+
* ```
|
|
271
|
+
*/
|
|
272
|
+
expectedStatus,
|
|
273
|
+
/**
|
|
274
|
+
* An object containing the path fields required to
|
|
275
|
+
* fill your uri in, as well as any additional DELETE
|
|
276
|
+
* arguments, like `data`, for example.
|
|
277
|
+
*
|
|
278
|
+
* ```ts
|
|
279
|
+
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
280
|
+
* const session = await request.session('post', '/sessions/{token}', 200, { token: 'abc' })
|
|
281
|
+
* const res = await session.delete(
|
|
282
|
+
* '/posts/{postId}/comments/{commentId}',
|
|
283
|
+
* 200,
|
|
284
|
+
* {
|
|
285
|
+
* postId: '123',
|
|
286
|
+
* commentId: '456',
|
|
287
|
+
* data: {
|
|
288
|
+
* ...request body here
|
|
289
|
+
* },
|
|
290
|
+
* headers: {
|
|
291
|
+
* ...headers here
|
|
292
|
+
* },
|
|
293
|
+
* }
|
|
294
|
+
* )
|
|
295
|
+
* ```
|
|
296
|
+
*
|
|
297
|
+
* @param opts.data - request body data you want to send up. Must match the
|
|
298
|
+
* requestBody shape in the openapi document for this uri.
|
|
299
|
+
* (Optional)
|
|
300
|
+
*
|
|
301
|
+
* @param opts.headers - headers you would like to send with your request.
|
|
302
|
+
* (Optional)
|
|
303
|
+
*/
|
|
304
|
+
opts) {
|
|
305
|
+
return await this.makeRequest('delete', fillOpenapiParams(uri, opts || {}), expectedStatus, opts);
|
|
28
306
|
}
|
|
29
307
|
async makeRequest(method, uri, expectedStatus, opts = {}) {
|
|
30
308
|
if (expectedStatus === 500) {
|