@scalar/mock-server 0.1.60 → 0.1.62
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/CHANGELOG.md +488 -0
- package/dist/index.cjs +59 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +41 -127
- package/dist/index.js.map +1 -0
- package/package.json +12 -13
- package/dist/package.json +0 -58
- package/dist/src/createMockServer.d.ts +0 -12
- package/dist/src/createMockServer.js +0 -97
- package/dist/src/createMockServer.test.d.ts +0 -1
- package/dist/src/createMockServer.test.js +0 -299
- package/dist/src/index.d.ts +0 -2
- package/dist/src/index.js +0 -2
- package/dist/src/utils/index.d.ts +0 -2
- package/dist/src/utils/index.js +0 -2
- package/dist/src/utils/normalize.d.ts +0 -4
- package/dist/src/utils/normalize.js +0 -9
- package/dist/src/utils/normalize.test.d.ts +0 -1
- package/dist/src/utils/normalize.test.js +0 -12
- package/dist/src/utils/routeFromPath.d.ts +0 -5
- package/dist/src/utils/routeFromPath.js +0 -7
- package/dist/src/utils/routeFromPath.test.d.ts +0 -1
- package/dist/src/utils/routeFromPath.test.js +0 -10
- package/dist/tests/galaxy.test.d.ts +0 -1
- package/dist/tests/galaxy.test.js +0 -83
- package/dist/tests/onRequest.test.d.ts +0 -1
- package/dist/tests/onRequest.test.js +0 -82
- package/dist/tests/openapi.test.d.ts +0 -1
- package/dist/tests/openapi.test.js +0 -220
- package/dist/tsconfig.tsbuildinfo +0 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,488 @@
|
|
|
1
|
+
# @scalar/mock-server
|
|
2
|
+
|
|
3
|
+
## 0.1.62
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 09b38c4: fix: openapi.json returns yaml string
|
|
8
|
+
- ea0eed3: fix: types not available
|
|
9
|
+
|
|
10
|
+
## 0.1.61
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- 5a2f0c9: fix: release workflow fails
|
|
15
|
+
|
|
16
|
+
## 0.1.60
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- 17841a8: fix: wrong repository URL in the package.json
|
|
21
|
+
|
|
22
|
+
## 0.1.59
|
|
23
|
+
|
|
24
|
+
### Patch Changes
|
|
25
|
+
|
|
26
|
+
- 45dc04b: fix: can’t release packages
|
|
27
|
+
- Updated dependencies [9ba838b]
|
|
28
|
+
- Updated dependencies [45dc04b]
|
|
29
|
+
- @scalar/api-reference@1.22.24
|
|
30
|
+
- @scalar/oas-utils@0.1.10
|
|
31
|
+
- @scalar/galaxy@0.1.2
|
|
32
|
+
|
|
33
|
+
## 0.1.58
|
|
34
|
+
|
|
35
|
+
### Patch Changes
|
|
36
|
+
|
|
37
|
+
- 05e2e27: chore: add provenance statement
|
|
38
|
+
- Updated dependencies [05e2e27]
|
|
39
|
+
- @scalar/api-reference@1.22.23
|
|
40
|
+
- @scalar/galaxy@0.1.1
|
|
41
|
+
- @scalar/oas-utils@0.1.9
|
|
42
|
+
|
|
43
|
+
## 0.1.57
|
|
44
|
+
|
|
45
|
+
### Patch Changes
|
|
46
|
+
|
|
47
|
+
- Updated dependencies [f1bf5bc]
|
|
48
|
+
- Updated dependencies [085a0c2]
|
|
49
|
+
- Updated dependencies [fa10d45]
|
|
50
|
+
- @scalar/api-reference@1.22.22
|
|
51
|
+
- @scalar/oas-utils@0.1.8
|
|
52
|
+
|
|
53
|
+
## 0.1.56
|
|
54
|
+
|
|
55
|
+
### Patch Changes
|
|
56
|
+
|
|
57
|
+
- Updated dependencies [07211ad]
|
|
58
|
+
- Updated dependencies [801ad65]
|
|
59
|
+
- Updated dependencies [d4fa19b]
|
|
60
|
+
- Updated dependencies [b234d1d]
|
|
61
|
+
- @scalar/api-reference@1.22.21
|
|
62
|
+
- @scalar/oas-utils@0.1.7
|
|
63
|
+
|
|
64
|
+
## 0.1.55
|
|
65
|
+
|
|
66
|
+
### Patch Changes
|
|
67
|
+
|
|
68
|
+
- Updated dependencies [a8c3045]
|
|
69
|
+
- Updated dependencies [1324378]
|
|
70
|
+
- Updated dependencies [9201802]
|
|
71
|
+
- @scalar/api-reference@1.22.20
|
|
72
|
+
|
|
73
|
+
## 0.1.54
|
|
74
|
+
|
|
75
|
+
### Patch Changes
|
|
76
|
+
|
|
77
|
+
- @scalar/api-reference@1.22.19
|
|
78
|
+
|
|
79
|
+
## 0.1.53
|
|
80
|
+
|
|
81
|
+
### Patch Changes
|
|
82
|
+
|
|
83
|
+
- Updated dependencies [45dccb0]
|
|
84
|
+
- Updated dependencies [abff1f4]
|
|
85
|
+
- @scalar/api-reference@1.22.18
|
|
86
|
+
|
|
87
|
+
## 0.1.52
|
|
88
|
+
|
|
89
|
+
### Patch Changes
|
|
90
|
+
|
|
91
|
+
- Updated dependencies [53ba90d]
|
|
92
|
+
- Updated dependencies [b42479c]
|
|
93
|
+
- Updated dependencies [4c38ac1]
|
|
94
|
+
- @scalar/galaxy@0.1.0
|
|
95
|
+
- @scalar/api-reference@1.22.17
|
|
96
|
+
|
|
97
|
+
## 0.1.51
|
|
98
|
+
|
|
99
|
+
### Patch Changes
|
|
100
|
+
|
|
101
|
+
- Updated dependencies [7e1d318]
|
|
102
|
+
- @scalar/api-reference@1.22.16
|
|
103
|
+
|
|
104
|
+
## 0.1.50
|
|
105
|
+
|
|
106
|
+
### Patch Changes
|
|
107
|
+
|
|
108
|
+
- Updated dependencies [fc2c90f]
|
|
109
|
+
- @scalar/api-reference@1.22.15
|
|
110
|
+
|
|
111
|
+
## 0.1.49
|
|
112
|
+
|
|
113
|
+
### Patch Changes
|
|
114
|
+
|
|
115
|
+
- Updated dependencies [b8e3f09]
|
|
116
|
+
- @scalar/api-reference@1.22.14
|
|
117
|
+
|
|
118
|
+
## 0.1.48
|
|
119
|
+
|
|
120
|
+
### Patch Changes
|
|
121
|
+
|
|
122
|
+
- Updated dependencies [c05c90e]
|
|
123
|
+
- Updated dependencies [2700c5c]
|
|
124
|
+
- @scalar/api-reference@1.22.13
|
|
125
|
+
|
|
126
|
+
## 0.1.47
|
|
127
|
+
|
|
128
|
+
### Patch Changes
|
|
129
|
+
|
|
130
|
+
- Updated dependencies [55398db]
|
|
131
|
+
- @scalar/api-reference@1.22.12
|
|
132
|
+
|
|
133
|
+
## 0.1.46
|
|
134
|
+
|
|
135
|
+
### Patch Changes
|
|
136
|
+
|
|
137
|
+
- Updated dependencies [b24b455]
|
|
138
|
+
- Updated dependencies [43e1217]
|
|
139
|
+
- @scalar/api-reference@1.22.11
|
|
140
|
+
|
|
141
|
+
## 0.1.45
|
|
142
|
+
|
|
143
|
+
### Patch Changes
|
|
144
|
+
|
|
145
|
+
- @scalar/api-reference@1.22.10
|
|
146
|
+
|
|
147
|
+
## 0.1.44
|
|
148
|
+
|
|
149
|
+
### Patch Changes
|
|
150
|
+
|
|
151
|
+
- Updated dependencies [6f68b40]
|
|
152
|
+
- Updated dependencies [4d31b19]
|
|
153
|
+
- @scalar/api-reference@1.22.9
|
|
154
|
+
|
|
155
|
+
## 0.1.43
|
|
156
|
+
|
|
157
|
+
### Patch Changes
|
|
158
|
+
|
|
159
|
+
- Updated dependencies [24662c3]
|
|
160
|
+
- @scalar/api-reference@1.22.8
|
|
161
|
+
|
|
162
|
+
## 0.1.42
|
|
163
|
+
|
|
164
|
+
### Patch Changes
|
|
165
|
+
|
|
166
|
+
- Updated dependencies [c408cf5]
|
|
167
|
+
- @scalar/api-reference@1.22.7
|
|
168
|
+
|
|
169
|
+
## 0.1.41
|
|
170
|
+
|
|
171
|
+
### Patch Changes
|
|
172
|
+
|
|
173
|
+
- Updated dependencies [cf12a95]
|
|
174
|
+
- Updated dependencies [7b37c63]
|
|
175
|
+
- @scalar/api-reference@1.22.6
|
|
176
|
+
|
|
177
|
+
## 0.1.40
|
|
178
|
+
|
|
179
|
+
### Patch Changes
|
|
180
|
+
|
|
181
|
+
- Updated dependencies [d03ab0f]
|
|
182
|
+
- @scalar/api-reference@1.22.5
|
|
183
|
+
|
|
184
|
+
## 0.1.39
|
|
185
|
+
|
|
186
|
+
### Patch Changes
|
|
187
|
+
|
|
188
|
+
- Updated dependencies [adc0693]
|
|
189
|
+
- @scalar/api-reference@1.22.4
|
|
190
|
+
|
|
191
|
+
## 0.1.38
|
|
192
|
+
|
|
193
|
+
### Patch Changes
|
|
194
|
+
|
|
195
|
+
- @scalar/api-reference@1.22.3
|
|
196
|
+
|
|
197
|
+
## 0.1.37
|
|
198
|
+
|
|
199
|
+
### Patch Changes
|
|
200
|
+
|
|
201
|
+
- @scalar/api-reference@1.22.2
|
|
202
|
+
|
|
203
|
+
## 0.1.36
|
|
204
|
+
|
|
205
|
+
### Patch Changes
|
|
206
|
+
|
|
207
|
+
- Updated dependencies [8dc1640]
|
|
208
|
+
- @scalar/api-reference@1.22.1
|
|
209
|
+
|
|
210
|
+
## 0.1.35
|
|
211
|
+
|
|
212
|
+
### Patch Changes
|
|
213
|
+
|
|
214
|
+
- 22f2858: chore: ran syncpack to update packages
|
|
215
|
+
- Updated dependencies [22f2858]
|
|
216
|
+
- Updated dependencies [ced76e5]
|
|
217
|
+
- Updated dependencies [0e64a36]
|
|
218
|
+
- Updated dependencies [3afec45]
|
|
219
|
+
- @scalar/api-reference@1.22.0
|
|
220
|
+
- @scalar/oas-utils@0.1.6
|
|
221
|
+
|
|
222
|
+
## 0.1.34
|
|
223
|
+
|
|
224
|
+
### Patch Changes
|
|
225
|
+
|
|
226
|
+
- Updated dependencies [851017a]
|
|
227
|
+
- @scalar/api-reference@1.21.2
|
|
228
|
+
|
|
229
|
+
## 0.1.33
|
|
230
|
+
|
|
231
|
+
### Patch Changes
|
|
232
|
+
|
|
233
|
+
- Updated dependencies [b4abb34]
|
|
234
|
+
- @scalar/api-reference@1.21.1
|
|
235
|
+
|
|
236
|
+
## 0.1.32
|
|
237
|
+
|
|
238
|
+
### Patch Changes
|
|
239
|
+
|
|
240
|
+
- Updated dependencies [51d4997]
|
|
241
|
+
- @scalar/api-reference@1.20.32
|
|
242
|
+
|
|
243
|
+
## 0.1.31
|
|
244
|
+
|
|
245
|
+
### Patch Changes
|
|
246
|
+
|
|
247
|
+
- Updated dependencies [b903a2f]
|
|
248
|
+
- @scalar/api-reference@1.20.31
|
|
249
|
+
|
|
250
|
+
## 0.1.30
|
|
251
|
+
|
|
252
|
+
### Patch Changes
|
|
253
|
+
|
|
254
|
+
- Updated dependencies [deabe4c]
|
|
255
|
+
- Updated dependencies [3ba9774]
|
|
256
|
+
- Updated dependencies [a14fc32]
|
|
257
|
+
- Updated dependencies [3d4d83e]
|
|
258
|
+
- @scalar/api-reference@1.20.30
|
|
259
|
+
- @scalar/oas-utils@0.1.5
|
|
260
|
+
|
|
261
|
+
## 0.1.29
|
|
262
|
+
|
|
263
|
+
### Patch Changes
|
|
264
|
+
|
|
265
|
+
- Updated dependencies [24b3c2a]
|
|
266
|
+
- @scalar/oas-utils@0.1.4
|
|
267
|
+
- @scalar/api-reference@1.20.29
|
|
268
|
+
|
|
269
|
+
## 0.1.28
|
|
270
|
+
|
|
271
|
+
### Patch Changes
|
|
272
|
+
|
|
273
|
+
- Updated dependencies [622f31b]
|
|
274
|
+
- Updated dependencies [f2c2ce8]
|
|
275
|
+
- @scalar/api-reference@1.20.28
|
|
276
|
+
|
|
277
|
+
## 0.1.27
|
|
278
|
+
|
|
279
|
+
### Patch Changes
|
|
280
|
+
|
|
281
|
+
- Updated dependencies [605f522]
|
|
282
|
+
- @scalar/api-reference@1.20.27
|
|
283
|
+
|
|
284
|
+
## 0.1.26
|
|
285
|
+
|
|
286
|
+
### Patch Changes
|
|
287
|
+
|
|
288
|
+
- Updated dependencies [050410a]
|
|
289
|
+
- @scalar/api-reference@1.20.26
|
|
290
|
+
|
|
291
|
+
## 0.1.25
|
|
292
|
+
|
|
293
|
+
### Patch Changes
|
|
294
|
+
|
|
295
|
+
- Updated dependencies [1504d3b]
|
|
296
|
+
- @scalar/api-reference@1.20.25
|
|
297
|
+
|
|
298
|
+
## 0.1.24
|
|
299
|
+
|
|
300
|
+
### Patch Changes
|
|
301
|
+
|
|
302
|
+
- Updated dependencies [ab58747]
|
|
303
|
+
- @scalar/api-reference@1.20.24
|
|
304
|
+
|
|
305
|
+
## 0.1.23
|
|
306
|
+
|
|
307
|
+
### Patch Changes
|
|
308
|
+
|
|
309
|
+
- @scalar/api-reference@1.20.23
|
|
310
|
+
|
|
311
|
+
## 0.1.22
|
|
312
|
+
|
|
313
|
+
### Patch Changes
|
|
314
|
+
|
|
315
|
+
- Updated dependencies [4089634]
|
|
316
|
+
- @scalar/api-reference@1.20.22
|
|
317
|
+
|
|
318
|
+
## 0.1.21
|
|
319
|
+
|
|
320
|
+
### Patch Changes
|
|
321
|
+
|
|
322
|
+
- @scalar/api-reference@1.20.21
|
|
323
|
+
|
|
324
|
+
## 0.1.20
|
|
325
|
+
|
|
326
|
+
### Patch Changes
|
|
327
|
+
|
|
328
|
+
- Updated dependencies [c14568f]
|
|
329
|
+
- @scalar/oas-utils@0.1.3
|
|
330
|
+
- @scalar/api-reference@1.20.20
|
|
331
|
+
|
|
332
|
+
## 0.1.19
|
|
333
|
+
|
|
334
|
+
### Patch Changes
|
|
335
|
+
|
|
336
|
+
- Updated dependencies [c99f6ff]
|
|
337
|
+
- @scalar/api-reference@1.20.18
|
|
338
|
+
|
|
339
|
+
## 0.1.18
|
|
340
|
+
|
|
341
|
+
### Patch Changes
|
|
342
|
+
|
|
343
|
+
- Updated dependencies [5b4c8a5]
|
|
344
|
+
- @scalar/api-reference@1.20.17
|
|
345
|
+
|
|
346
|
+
## 0.1.17
|
|
347
|
+
|
|
348
|
+
### Patch Changes
|
|
349
|
+
|
|
350
|
+
- Updated dependencies [5232eab]
|
|
351
|
+
- @scalar/api-reference@1.20.16
|
|
352
|
+
|
|
353
|
+
## 0.1.16
|
|
354
|
+
|
|
355
|
+
### Patch Changes
|
|
356
|
+
|
|
357
|
+
- Updated dependencies [8f03345]
|
|
358
|
+
- @scalar/api-reference@1.20.15
|
|
359
|
+
|
|
360
|
+
## 0.1.15
|
|
361
|
+
|
|
362
|
+
### Patch Changes
|
|
363
|
+
|
|
364
|
+
- Updated dependencies [78f2ab3]
|
|
365
|
+
- @scalar/api-reference@1.20.14
|
|
366
|
+
|
|
367
|
+
## 0.1.14
|
|
368
|
+
|
|
369
|
+
### Patch Changes
|
|
370
|
+
|
|
371
|
+
- Updated dependencies [8b0691b]
|
|
372
|
+
- @scalar/api-reference@1.20.13
|
|
373
|
+
- @scalar/oas-utils@0.1.2
|
|
374
|
+
|
|
375
|
+
## 0.1.13
|
|
376
|
+
|
|
377
|
+
### Patch Changes
|
|
378
|
+
|
|
379
|
+
- Updated dependencies [999dfc9]
|
|
380
|
+
- @scalar/api-reference@1.20.12
|
|
381
|
+
|
|
382
|
+
## 0.1.12
|
|
383
|
+
|
|
384
|
+
### Patch Changes
|
|
385
|
+
|
|
386
|
+
- Updated dependencies [d70bda7]
|
|
387
|
+
- @scalar/api-reference@1.20.11
|
|
388
|
+
|
|
389
|
+
## 0.1.11
|
|
390
|
+
|
|
391
|
+
### Patch Changes
|
|
392
|
+
|
|
393
|
+
- Updated dependencies [ae193a8]
|
|
394
|
+
- Updated dependencies [bec8e52]
|
|
395
|
+
- @scalar/api-reference@1.20.10
|
|
396
|
+
|
|
397
|
+
## 0.1.10
|
|
398
|
+
|
|
399
|
+
### Patch Changes
|
|
400
|
+
|
|
401
|
+
- Updated dependencies [5260d07]
|
|
402
|
+
- Updated dependencies [f861efa]
|
|
403
|
+
- @scalar/api-reference@1.20.9
|
|
404
|
+
|
|
405
|
+
## 0.1.9
|
|
406
|
+
|
|
407
|
+
### Patch Changes
|
|
408
|
+
|
|
409
|
+
- @scalar/api-reference@1.20.8
|
|
410
|
+
|
|
411
|
+
## 0.1.8
|
|
412
|
+
|
|
413
|
+
### Patch Changes
|
|
414
|
+
|
|
415
|
+
- Updated dependencies [1e658b0]
|
|
416
|
+
- Updated dependencies [06c57ca]
|
|
417
|
+
- @scalar/api-reference@1.20.7
|
|
418
|
+
|
|
419
|
+
## 0.1.7
|
|
420
|
+
|
|
421
|
+
### Patch Changes
|
|
422
|
+
|
|
423
|
+
- @scalar/api-reference@1.20.6
|
|
424
|
+
|
|
425
|
+
## 0.1.6
|
|
426
|
+
|
|
427
|
+
### Patch Changes
|
|
428
|
+
|
|
429
|
+
- Updated dependencies [0c5e22c]
|
|
430
|
+
- @scalar/api-reference@1.20.5
|
|
431
|
+
|
|
432
|
+
## 0.1.5
|
|
433
|
+
|
|
434
|
+
### Patch Changes
|
|
435
|
+
|
|
436
|
+
- @scalar/api-reference@1.20.4
|
|
437
|
+
|
|
438
|
+
## 0.1.4
|
|
439
|
+
|
|
440
|
+
### Patch Changes
|
|
441
|
+
|
|
442
|
+
- Updated dependencies [61a97e2]
|
|
443
|
+
- @scalar/api-reference@1.20.3
|
|
444
|
+
|
|
445
|
+
## 0.1.3
|
|
446
|
+
|
|
447
|
+
### Patch Changes
|
|
448
|
+
|
|
449
|
+
- Updated dependencies [9fe930c]
|
|
450
|
+
- @scalar/api-reference@1.20.2
|
|
451
|
+
|
|
452
|
+
## 0.1.2
|
|
453
|
+
|
|
454
|
+
### Patch Changes
|
|
455
|
+
|
|
456
|
+
- Updated dependencies [4b5a136]
|
|
457
|
+
- Updated dependencies [1fb2eac]
|
|
458
|
+
- Updated dependencies [01476a9]
|
|
459
|
+
- Updated dependencies [083e0a1]
|
|
460
|
+
- @scalar/api-reference@1.20.1
|
|
461
|
+
|
|
462
|
+
## 0.1.1
|
|
463
|
+
|
|
464
|
+
### Patch Changes
|
|
465
|
+
|
|
466
|
+
- 31aae5e: chore: moved shared types and methods into oas-utils
|
|
467
|
+
- Updated dependencies [6dc67c1]
|
|
468
|
+
- Updated dependencies [c4500f6]
|
|
469
|
+
- Updated dependencies [41f0d86]
|
|
470
|
+
- Updated dependencies [31aae5e]
|
|
471
|
+
- @scalar/api-reference@1.20.0
|
|
472
|
+
- @scalar/oas-utils@0.1.1
|
|
473
|
+
|
|
474
|
+
## 0.1.0
|
|
475
|
+
|
|
476
|
+
### Minor Changes
|
|
477
|
+
|
|
478
|
+
- a866e91: refactor: switch to @scalar/openapi-parser
|
|
479
|
+
|
|
480
|
+
### Patch Changes
|
|
481
|
+
|
|
482
|
+
- 0399390: chore: update dependencies
|
|
483
|
+
|
|
484
|
+
## 0.0.2
|
|
485
|
+
|
|
486
|
+
### Patch Changes
|
|
487
|
+
|
|
488
|
+
- 96b85ef: feat: new @scalar/mock-server package
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var oasUtils = require('@scalar/oas-utils');
|
|
4
|
+
var openapiParser = require('@scalar/openapi-parser');
|
|
5
|
+
var hono = require('hono');
|
|
6
|
+
|
|
7
|
+
function normalize(openapi) {
|
|
8
|
+
if (typeof openapi === "string") {
|
|
9
|
+
openapi = JSON.parse(openapi);
|
|
10
|
+
}
|
|
11
|
+
return openapi;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function routeFromPath(path) {
|
|
15
|
+
return path.replace(/{/g, ":").replace(/}/g, "");
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async function createMockServer(options) {
|
|
19
|
+
const app = new hono.Hono();
|
|
20
|
+
const result = await openapiParser.openapi().load(options?.specification ?? {}).resolve();
|
|
21
|
+
app.get("/openapi.json", (c) => {
|
|
22
|
+
if (!options?.specification) {
|
|
23
|
+
return c.text("Not found", 404);
|
|
24
|
+
}
|
|
25
|
+
return c.json(openapiParser.openapi().load(options.specification).get());
|
|
26
|
+
});
|
|
27
|
+
app.get("/openapi.yaml", (c) => {
|
|
28
|
+
if (!options?.specification) {
|
|
29
|
+
return c.text("Not found", 404);
|
|
30
|
+
}
|
|
31
|
+
return c.text(openapiParser.openapi().load(options.specification).toYaml());
|
|
32
|
+
});
|
|
33
|
+
Object.keys(result.schema?.paths ?? {}).forEach((path) => {
|
|
34
|
+
Object.keys(result.schema?.paths?.[path] ?? {}).forEach((method) => {
|
|
35
|
+
const route = routeFromPath(path);
|
|
36
|
+
app[method](route, (c) => {
|
|
37
|
+
if (options?.onRequest) {
|
|
38
|
+
options.onRequest({
|
|
39
|
+
context: c,
|
|
40
|
+
// @ts-expect-error Needs a proper type
|
|
41
|
+
operation: result.schema.paths[path][method]
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
const operation = result.schema?.paths?.[path]?.[method];
|
|
45
|
+
const jsonResponseConfiguration = operation.responses?.["200"]?.content["application/json"];
|
|
46
|
+
const response = jsonResponseConfiguration?.example ? jsonResponseConfiguration.example : jsonResponseConfiguration?.schema ? oasUtils.getExampleFromSchema(jsonResponseConfiguration.schema, {
|
|
47
|
+
emptyString: "\u2026"
|
|
48
|
+
}) : null;
|
|
49
|
+
return c.json(response);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
return app;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
exports.createMockServer = createMockServer;
|
|
57
|
+
exports.normalize = normalize;
|
|
58
|
+
exports.routeFromPath = routeFromPath;
|
|
59
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/utils/normalize.ts","../src/utils/routeFromPath.ts","../src/createMockServer.ts"],"sourcesContent":["/**\n * Normalize OpenAPI JSON string, YAML string … to object\n */\nexport function normalize(openapi: string | Record<string, any>) {\n if (typeof openapi === 'string') {\n openapi = JSON.parse(openapi)\n }\n\n return openapi\n}\n","/**\n * Convert path to route\n * Example: /posts/{id} -> /posts/:id\n */\nexport function routeFromPath(path: string) {\n return path.replace(/{/g, ':').replace(/}/g, '')\n}\n","import { type Operation, getExampleFromSchema } from '@scalar/oas-utils'\nimport { openapi } from '@scalar/openapi-parser'\nimport { type Context, Hono } from 'hono'\n\nimport { routeFromPath } from './utils'\n\n/**\n * Create a mock server instance\n */\nexport async function createMockServer(options?: {\n specification: string | Record<string, any>\n onRequest?: (data: { context: Context; operation: Operation }) => void\n}) {\n const app = new Hono()\n\n // Resolve references\n const result = await openapi()\n .load(options?.specification ?? {})\n .resolve()\n\n // OpenAPI JSON file\n app.get('/openapi.json', (c) => {\n if (!options?.specification) {\n return c.text('Not found', 404)\n }\n\n return c.json(openapi().load(options.specification).get())\n })\n\n // OpenAPI YAML file\n app.get('/openapi.yaml', (c) => {\n if (!options?.specification) {\n return c.text('Not found', 404)\n }\n\n return c.text(openapi().load(options.specification).toYaml())\n })\n\n // Paths\n Object.keys(result.schema?.paths ?? {}).forEach((path) => {\n // Request methods\n Object.keys(result.schema?.paths?.[path] ?? {}).forEach((method) => {\n const route = routeFromPath(path)\n\n // Route\n // @ts-expect-error Needs a proper type\n app[method](route, (c: Context) => {\n // Call onRequest callback\n if (options?.onRequest) {\n options.onRequest({\n context: c,\n // @ts-expect-error Needs a proper type\n operation: result.schema.paths[path][method],\n })\n }\n\n // Response\n // @ts-expect-error Needs a proper type\n const operation = result.schema?.paths?.[path]?.[method]\n\n const jsonResponseConfiguration =\n operation.responses?.['200']?.content['application/json']\n\n const response = jsonResponseConfiguration?.example\n ? jsonResponseConfiguration.example\n : jsonResponseConfiguration?.schema\n ? getExampleFromSchema(jsonResponseConfiguration.schema, {\n emptyString: '…',\n })\n : null\n\n return c.json(response)\n })\n })\n })\n\n return app\n}\n"],"names":["Hono","openapi","getExampleFromSchema"],"mappings":";;;;;;AAGO,SAAS,UAAU,OAAuC,EAAA;AAC/D,EAAI,IAAA,OAAO,YAAY,QAAU,EAAA;AAC/B,IAAU,OAAA,GAAA,IAAA,CAAK,MAAM,OAAO,CAAA,CAAA;AAAA,GAC9B;AAEA,EAAO,OAAA,OAAA,CAAA;AACT;;ACLO,SAAS,cAAc,IAAc,EAAA;AAC1C,EAAA,OAAO,KAAK,OAAQ,CAAA,IAAA,EAAM,GAAG,CAAE,CAAA,OAAA,CAAQ,MAAM,EAAE,CAAA,CAAA;AACjD;;ACGA,eAAsB,iBAAiB,OAGpC,EAAA;AACD,EAAM,MAAA,GAAA,GAAM,IAAIA,SAAK,EAAA,CAAA;AAGrB,EAAM,MAAA,MAAA,GAAS,MAAMC,qBAAA,EAClB,CAAA,IAAA,CAAK,SAAS,aAAiB,IAAA,EAAE,CAAA,CACjC,OAAQ,EAAA,CAAA;AAGX,EAAI,GAAA,CAAA,GAAA,CAAI,eAAiB,EAAA,CAAC,CAAM,KAAA;AAC9B,IAAI,IAAA,CAAC,SAAS,aAAe,EAAA;AAC3B,MAAO,OAAA,CAAA,CAAE,IAAK,CAAA,WAAA,EAAa,GAAG,CAAA,CAAA;AAAA,KAChC;AAEA,IAAO,OAAA,CAAA,CAAE,KAAKA,qBAAQ,EAAA,CAAE,KAAK,OAAQ,CAAA,aAAa,CAAE,CAAA,GAAA,EAAK,CAAA,CAAA;AAAA,GAC1D,CAAA,CAAA;AAGD,EAAI,GAAA,CAAA,GAAA,CAAI,eAAiB,EAAA,CAAC,CAAM,KAAA;AAC9B,IAAI,IAAA,CAAC,SAAS,aAAe,EAAA;AAC3B,MAAO,OAAA,CAAA,CAAE,IAAK,CAAA,WAAA,EAAa,GAAG,CAAA,CAAA;AAAA,KAChC;AAEA,IAAO,OAAA,CAAA,CAAE,KAAKA,qBAAQ,EAAA,CAAE,KAAK,OAAQ,CAAA,aAAa,CAAE,CAAA,MAAA,EAAQ,CAAA,CAAA;AAAA,GAC7D,CAAA,CAAA;AAGD,EAAO,MAAA,CAAA,IAAA,CAAK,OAAO,MAAQ,EAAA,KAAA,IAAS,EAAE,CAAA,CAAE,OAAQ,CAAA,CAAC,IAAS,KAAA;AAExD,IAAO,MAAA,CAAA,IAAA,CAAK,MAAO,CAAA,MAAA,EAAQ,KAAQ,GAAA,IAAI,CAAK,IAAA,EAAE,CAAA,CAAE,OAAQ,CAAA,CAAC,MAAW,KAAA;AAClE,MAAM,MAAA,KAAA,GAAQ,cAAc,IAAI,CAAA,CAAA;AAIhC,MAAA,GAAA,CAAI,MAAM,CAAA,CAAE,KAAO,EAAA,CAAC,CAAe,KAAA;AAEjC,QAAA,IAAI,SAAS,SAAW,EAAA;AACtB,UAAA,OAAA,CAAQ,SAAU,CAAA;AAAA,YAChB,OAAS,EAAA,CAAA;AAAA;AAAA,YAET,WAAW,MAAO,CAAA,MAAA,CAAO,KAAM,CAAA,IAAI,EAAE,MAAM,CAAA;AAAA,WAC5C,CAAA,CAAA;AAAA,SACH;AAIA,QAAA,MAAM,YAAY,MAAO,CAAA,MAAA,EAAQ,KAAQ,GAAA,IAAI,IAAI,MAAM,CAAA,CAAA;AAEvD,QAAA,MAAM,4BACJ,SAAU,CAAA,SAAA,GAAY,KAAK,CAAA,EAAG,QAAQ,kBAAkB,CAAA,CAAA;AAE1D,QAAM,MAAA,QAAA,GAAW,2BAA2B,OACxC,GAAA,yBAAA,CAA0B,UAC1B,yBAA2B,EAAA,MAAA,GACzBC,6BAAqB,CAAA,yBAAA,CAA0B,MAAQ,EAAA;AAAA,UACrD,WAAa,EAAA,QAAA;AAAA,SACd,CACD,GAAA,IAAA,CAAA;AAEN,QAAO,OAAA,CAAA,CAAE,KAAK,QAAQ,CAAA,CAAA;AAAA,OACvB,CAAA,CAAA;AAAA,KACF,CAAA,CAAA;AAAA,GACF,CAAA,CAAA;AAED,EAAO,OAAA,GAAA,CAAA;AACT;;;;;;"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import * as hono_types from 'hono/types';
|
|
2
|
+
import * as hono from 'hono';
|
|
3
|
+
import { Context, Hono } from 'hono';
|
|
4
|
+
import { Operation } from '@scalar/oas-utils';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Create a mock server instance
|
|
8
|
+
*/
|
|
9
|
+
declare function createMockServer(options?: {
|
|
10
|
+
specification: string | Record<string, any>;
|
|
11
|
+
onRequest?: (data: {
|
|
12
|
+
context: Context;
|
|
13
|
+
operation: Operation;
|
|
14
|
+
}) => void;
|
|
15
|
+
}): Promise<Hono<hono.Env, hono_types.BlankSchema, "/">>;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Normalize OpenAPI JSON string, YAML string … to object
|
|
19
|
+
*/
|
|
20
|
+
declare function normalize(openapi: string | Record<string, any>): string | Record<string, any>;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Convert path to route
|
|
24
|
+
* Example: /posts/{id} -> /posts/:id
|
|
25
|
+
*/
|
|
26
|
+
declare function routeFromPath(path: string): string;
|
|
27
|
+
|
|
28
|
+
export { createMockServer, normalize, routeFromPath };
|