@scalar/mock-server 0.5.0 → 0.5.1
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 +11 -0
- package/package.json +5 -5
- package/dist/createMockServer.test.js +0 -598
- package/dist/createMockServer.test.js.map +0 -7
- package/dist/utils/findPreferredResponseKey.test.js +0 -20
- package/dist/utils/findPreferredResponseKey.test.js.map +0 -7
- package/dist/utils/getOpenAuthTokenUrls.test.js +0 -127
- package/dist/utils/getOpenAuthTokenUrls.test.js.map +0 -7
- package/dist/utils/honoRouteFromPath.test.js +0 -32
- package/dist/utils/honoRouteFromPath.test.js.map +0 -7
- package/dist/utils/isAuthenticationRequired.test.js +0 -23
- package/dist/utils/isAuthenticationRequired.test.js.map +0 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# @scalar/mock-server
|
|
2
2
|
|
|
3
|
+
## 0.5.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [1e87feb]
|
|
8
|
+
- Updated dependencies [1e87feb]
|
|
9
|
+
- Updated dependencies [cad6277]
|
|
10
|
+
- @scalar/openapi-parser@0.13.0
|
|
11
|
+
- @scalar/oas-utils@0.4.0
|
|
12
|
+
- @scalar/openapi-types@0.3.1
|
|
13
|
+
|
|
3
14
|
## 0.5.0
|
|
4
15
|
|
|
5
16
|
### Minor Changes
|
package/package.json
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"swagger",
|
|
17
17
|
"cli"
|
|
18
18
|
],
|
|
19
|
-
"version": "0.5.
|
|
19
|
+
"version": "0.5.1",
|
|
20
20
|
"engines": {
|
|
21
21
|
"node": ">=20"
|
|
22
22
|
},
|
|
@@ -38,15 +38,15 @@
|
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"hono": "^4.6.5",
|
|
40
40
|
"object-to-xml": "^2.0.0",
|
|
41
|
-
"@scalar/oas-utils": "0.
|
|
42
|
-
"@scalar/openapi-
|
|
43
|
-
"@scalar/openapi-
|
|
41
|
+
"@scalar/oas-utils": "0.4.0",
|
|
42
|
+
"@scalar/openapi-types": "0.3.1",
|
|
43
|
+
"@scalar/openapi-parser": "0.13.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@hono/node-server": "^1.11.0",
|
|
47
47
|
"@types/node": "^20.17.10",
|
|
48
48
|
"vite": "5.4.19",
|
|
49
|
-
"@scalar/build-tooling": "0.2.
|
|
49
|
+
"@scalar/build-tooling": "0.2.1",
|
|
50
50
|
"@scalar/hono-api-reference": "0.9.1"
|
|
51
51
|
},
|
|
52
52
|
"scripts": {
|
|
@@ -1,598 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { createMockServer } from "./createMockServer.js";
|
|
3
|
-
describe("createMockServer", () => {
|
|
4
|
-
it("GET /foobar -> example JSON", async () => {
|
|
5
|
-
const specification = {
|
|
6
|
-
openapi: "3.1.0",
|
|
7
|
-
info: {
|
|
8
|
-
title: "Hello World",
|
|
9
|
-
version: "1.0.0"
|
|
10
|
-
},
|
|
11
|
-
paths: {
|
|
12
|
-
"/foobar": {
|
|
13
|
-
get: {
|
|
14
|
-
responses: {
|
|
15
|
-
"200": {
|
|
16
|
-
description: "OK",
|
|
17
|
-
content: {
|
|
18
|
-
"application/json": {
|
|
19
|
-
example: {
|
|
20
|
-
foo: "bar"
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
const server = await createMockServer({
|
|
31
|
-
specification
|
|
32
|
-
});
|
|
33
|
-
const response = await server.request("/foobar");
|
|
34
|
-
expect(response.status).toBe(200);
|
|
35
|
-
expect(await response.json()).toMatchObject({
|
|
36
|
-
foo: "bar"
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
it("GET /foobar -> omits writeOnly properties in responses", async () => {
|
|
40
|
-
const specification = {
|
|
41
|
-
openapi: "3.1.0",
|
|
42
|
-
info: {
|
|
43
|
-
title: "Hello World",
|
|
44
|
-
version: "1.0.0"
|
|
45
|
-
},
|
|
46
|
-
paths: {
|
|
47
|
-
"/foobar": {
|
|
48
|
-
get: {
|
|
49
|
-
responses: {
|
|
50
|
-
"200": {
|
|
51
|
-
description: "OK",
|
|
52
|
-
content: {
|
|
53
|
-
"application/json": {
|
|
54
|
-
schema: {
|
|
55
|
-
type: "object",
|
|
56
|
-
properties: {
|
|
57
|
-
id: {
|
|
58
|
-
type: "integer",
|
|
59
|
-
format: "int64",
|
|
60
|
-
readOnly: true,
|
|
61
|
-
example: 1
|
|
62
|
-
},
|
|
63
|
-
visible: {
|
|
64
|
-
type: "boolean",
|
|
65
|
-
example: true
|
|
66
|
-
},
|
|
67
|
-
password: {
|
|
68
|
-
type: "string",
|
|
69
|
-
writeOnly: true
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
const server = await createMockServer({
|
|
82
|
-
specification
|
|
83
|
-
});
|
|
84
|
-
const response = await server.request("/foobar");
|
|
85
|
-
expect(response.status).toBe(200);
|
|
86
|
-
const data = await response.json();
|
|
87
|
-
expect(data).not.toHaveProperty("password");
|
|
88
|
-
expect(data).toStrictEqual({
|
|
89
|
-
id: 1,
|
|
90
|
-
visible: true
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
it("GET /foobar -> return HTML if accepted", async () => {
|
|
94
|
-
const specification = {
|
|
95
|
-
openapi: "3.1.0",
|
|
96
|
-
info: {
|
|
97
|
-
title: "Hello World",
|
|
98
|
-
version: "1.0.0"
|
|
99
|
-
},
|
|
100
|
-
paths: {
|
|
101
|
-
"/foobar": {
|
|
102
|
-
get: {
|
|
103
|
-
responses: {
|
|
104
|
-
"200": {
|
|
105
|
-
description: "OK",
|
|
106
|
-
content: {
|
|
107
|
-
"application/json": {
|
|
108
|
-
example: {
|
|
109
|
-
foo: "bar"
|
|
110
|
-
}
|
|
111
|
-
},
|
|
112
|
-
"text/html": {
|
|
113
|
-
example: "foobar"
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
const server = await createMockServer({
|
|
123
|
-
specification
|
|
124
|
-
});
|
|
125
|
-
const response = await server.request("/foobar", {
|
|
126
|
-
headers: {
|
|
127
|
-
Accept: "text/html"
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
expect(response.status).toBe(200);
|
|
131
|
-
expect(await response.text()).toBe("foobar");
|
|
132
|
-
});
|
|
133
|
-
it("GET /foobar -> fall back to JSON", async () => {
|
|
134
|
-
const specification = {
|
|
135
|
-
openapi: "3.1.0",
|
|
136
|
-
info: {
|
|
137
|
-
title: "Hello World",
|
|
138
|
-
version: "1.0.0"
|
|
139
|
-
},
|
|
140
|
-
paths: {
|
|
141
|
-
"/foobar": {
|
|
142
|
-
get: {
|
|
143
|
-
responses: {
|
|
144
|
-
"200": {
|
|
145
|
-
description: "OK",
|
|
146
|
-
content: {
|
|
147
|
-
"application/json": {
|
|
148
|
-
example: {
|
|
149
|
-
foo: "bar"
|
|
150
|
-
}
|
|
151
|
-
},
|
|
152
|
-
"text/html": {
|
|
153
|
-
example: "foobar"
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
};
|
|
162
|
-
const server = await createMockServer({
|
|
163
|
-
specification
|
|
164
|
-
});
|
|
165
|
-
const response = await server.request("/foobar");
|
|
166
|
-
expect(response.status).toBe(200);
|
|
167
|
-
expect(await response.json()).toMatchObject({
|
|
168
|
-
foo: "bar"
|
|
169
|
-
});
|
|
170
|
-
});
|
|
171
|
-
it("GET /foobar -> XML", async () => {
|
|
172
|
-
const specification = {
|
|
173
|
-
openapi: "3.1.0",
|
|
174
|
-
info: {
|
|
175
|
-
title: "Hello World",
|
|
176
|
-
version: "1.0.0"
|
|
177
|
-
},
|
|
178
|
-
paths: {
|
|
179
|
-
"/foobar": {
|
|
180
|
-
get: {
|
|
181
|
-
responses: {
|
|
182
|
-
"200": {
|
|
183
|
-
description: "OK",
|
|
184
|
-
content: {
|
|
185
|
-
"application/xml": {
|
|
186
|
-
example: {
|
|
187
|
-
foo: "bar"
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
};
|
|
197
|
-
const server = await createMockServer({
|
|
198
|
-
specification
|
|
199
|
-
});
|
|
200
|
-
const response = await server.request("/foobar");
|
|
201
|
-
expect(response.status).toBe(200);
|
|
202
|
-
expect(await response.text()).toContain("<foo>bar</foo>");
|
|
203
|
-
});
|
|
204
|
-
it("uses http verbs only to register routes", async () => {
|
|
205
|
-
const specification = {
|
|
206
|
-
openapi: "3.1.0",
|
|
207
|
-
info: {
|
|
208
|
-
title: "Hello World",
|
|
209
|
-
version: "1.0.0"
|
|
210
|
-
},
|
|
211
|
-
paths: {
|
|
212
|
-
"/foobar": {
|
|
213
|
-
summary: "",
|
|
214
|
-
description: "",
|
|
215
|
-
parameters: {},
|
|
216
|
-
servers: {},
|
|
217
|
-
get: {
|
|
218
|
-
responses: {
|
|
219
|
-
"200": {
|
|
220
|
-
description: "OK",
|
|
221
|
-
content: {
|
|
222
|
-
"application/json": {
|
|
223
|
-
example: {
|
|
224
|
-
foo: "bar"
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
};
|
|
234
|
-
const server = await createMockServer({
|
|
235
|
-
specification
|
|
236
|
-
});
|
|
237
|
-
const response = await server.request("/foobar");
|
|
238
|
-
expect(response.status).toBe(200);
|
|
239
|
-
expect(await response.json()).toMatchObject({
|
|
240
|
-
foo: "bar"
|
|
241
|
-
});
|
|
242
|
-
});
|
|
243
|
-
it("POST /foobar -> example JSON", async () => {
|
|
244
|
-
const specification = {
|
|
245
|
-
openapi: "3.1.0",
|
|
246
|
-
info: {
|
|
247
|
-
title: "Hello World",
|
|
248
|
-
version: "1.0.0"
|
|
249
|
-
},
|
|
250
|
-
paths: {
|
|
251
|
-
"/foobar": {
|
|
252
|
-
post: {
|
|
253
|
-
responses: {
|
|
254
|
-
"200": {
|
|
255
|
-
description: "OK",
|
|
256
|
-
content: {
|
|
257
|
-
"application/json": {
|
|
258
|
-
example: {
|
|
259
|
-
foo: "bar"
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
};
|
|
269
|
-
const server = await createMockServer({
|
|
270
|
-
specification
|
|
271
|
-
});
|
|
272
|
-
const response = await server.request("/foobar", {
|
|
273
|
-
method: "POST"
|
|
274
|
-
});
|
|
275
|
-
expect(response.status).toBe(200);
|
|
276
|
-
expect(await response.json()).toMatchObject({
|
|
277
|
-
foo: "bar"
|
|
278
|
-
});
|
|
279
|
-
});
|
|
280
|
-
it("POST /foobar -> return 201", async () => {
|
|
281
|
-
const specification = {
|
|
282
|
-
openapi: "3.1.0",
|
|
283
|
-
info: {
|
|
284
|
-
title: "Hello World",
|
|
285
|
-
version: "1.0.0"
|
|
286
|
-
},
|
|
287
|
-
paths: {
|
|
288
|
-
"/foobar": {
|
|
289
|
-
post: {
|
|
290
|
-
responses: {
|
|
291
|
-
"201": {
|
|
292
|
-
description: "OK",
|
|
293
|
-
content: {
|
|
294
|
-
"application/json": {
|
|
295
|
-
example: {
|
|
296
|
-
foo: "bar"
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
};
|
|
306
|
-
const server = await createMockServer({
|
|
307
|
-
specification
|
|
308
|
-
});
|
|
309
|
-
const response = await server.request("/foobar", {
|
|
310
|
-
method: "POST"
|
|
311
|
-
});
|
|
312
|
-
expect(response.status).toBe(201);
|
|
313
|
-
expect(await response.json()).toMatchObject({
|
|
314
|
-
foo: "bar"
|
|
315
|
-
});
|
|
316
|
-
});
|
|
317
|
-
it("POST /foobar/{id} -> example JSON", async () => {
|
|
318
|
-
const specification = {
|
|
319
|
-
openapi: "3.1.0",
|
|
320
|
-
info: {
|
|
321
|
-
title: "Hello World",
|
|
322
|
-
version: "1.0.0"
|
|
323
|
-
},
|
|
324
|
-
paths: {
|
|
325
|
-
"/foobar/{id}": {
|
|
326
|
-
get: {
|
|
327
|
-
responses: {
|
|
328
|
-
"200": {
|
|
329
|
-
description: "OK",
|
|
330
|
-
content: {
|
|
331
|
-
"application/json": {
|
|
332
|
-
example: {
|
|
333
|
-
foo: "bar"
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
};
|
|
343
|
-
const server = await createMockServer({
|
|
344
|
-
specification
|
|
345
|
-
});
|
|
346
|
-
const response = await server.request("/foobar/123");
|
|
347
|
-
expect(response.status).toBe(200);
|
|
348
|
-
expect(await response.json()).toMatchObject({
|
|
349
|
-
foo: "bar"
|
|
350
|
-
});
|
|
351
|
-
});
|
|
352
|
-
it("POST /foobar/{id} -> uses dynamic ID", async () => {
|
|
353
|
-
const specification = {
|
|
354
|
-
openapi: "3.1.0",
|
|
355
|
-
info: {
|
|
356
|
-
title: "Hello World",
|
|
357
|
-
version: "1.0.0"
|
|
358
|
-
},
|
|
359
|
-
paths: {
|
|
360
|
-
"/foobar/{id}": {
|
|
361
|
-
get: {
|
|
362
|
-
responses: {
|
|
363
|
-
"200": {
|
|
364
|
-
description: "OK",
|
|
365
|
-
content: {
|
|
366
|
-
"application/json": {
|
|
367
|
-
schema: {
|
|
368
|
-
type: "object",
|
|
369
|
-
properties: {
|
|
370
|
-
id: {
|
|
371
|
-
"type": "number",
|
|
372
|
-
"example": "bar",
|
|
373
|
-
"x-variable": "id"
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
};
|
|
385
|
-
const server = await createMockServer({
|
|
386
|
-
specification
|
|
387
|
-
});
|
|
388
|
-
const response = await server.request("/foobar/123");
|
|
389
|
-
expect(await response.json()).toMatchObject({
|
|
390
|
-
id: 123
|
|
391
|
-
});
|
|
392
|
-
expect(response.status).toBe(200);
|
|
393
|
-
});
|
|
394
|
-
it("GET /foobar -> example from schema", async () => {
|
|
395
|
-
const specification = {
|
|
396
|
-
openapi: "3.1.0",
|
|
397
|
-
info: {
|
|
398
|
-
title: "Hello World",
|
|
399
|
-
version: "1.0.0"
|
|
400
|
-
},
|
|
401
|
-
paths: {
|
|
402
|
-
"/foobar": {
|
|
403
|
-
get: {
|
|
404
|
-
responses: {
|
|
405
|
-
"200": {
|
|
406
|
-
description: "OK",
|
|
407
|
-
content: {
|
|
408
|
-
"application/json": {
|
|
409
|
-
schema: {
|
|
410
|
-
type: "object",
|
|
411
|
-
properties: {
|
|
412
|
-
foo: {
|
|
413
|
-
type: "string",
|
|
414
|
-
example: "bar"
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
};
|
|
426
|
-
const server = await createMockServer({
|
|
427
|
-
specification
|
|
428
|
-
});
|
|
429
|
-
const response = await server.request("/foobar");
|
|
430
|
-
expect(response.status).toBe(200);
|
|
431
|
-
expect(await response.json()).toMatchObject({
|
|
432
|
-
foo: "bar"
|
|
433
|
-
});
|
|
434
|
-
});
|
|
435
|
-
it("GET /foobar/{id} -> example from schema", async () => {
|
|
436
|
-
const specification = {
|
|
437
|
-
openapi: "3.1.0",
|
|
438
|
-
info: {
|
|
439
|
-
title: "Hello World",
|
|
440
|
-
version: "1.0.0"
|
|
441
|
-
},
|
|
442
|
-
paths: {
|
|
443
|
-
"/foobar/{id}": {
|
|
444
|
-
get: {
|
|
445
|
-
responses: {
|
|
446
|
-
"200": {
|
|
447
|
-
description: "OK",
|
|
448
|
-
content: {
|
|
449
|
-
"application/json": {
|
|
450
|
-
schema: {
|
|
451
|
-
type: "object",
|
|
452
|
-
properties: {
|
|
453
|
-
foo: {
|
|
454
|
-
type: "string",
|
|
455
|
-
example: "bar"
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
};
|
|
467
|
-
const server = await createMockServer({
|
|
468
|
-
specification
|
|
469
|
-
});
|
|
470
|
-
const response = await server.request("/foobar/123");
|
|
471
|
-
expect(response.status).toBe(200);
|
|
472
|
-
expect(await response.json()).toMatchObject({
|
|
473
|
-
foo: "bar"
|
|
474
|
-
});
|
|
475
|
-
});
|
|
476
|
-
it("has CORS headers", async () => {
|
|
477
|
-
const specification = {
|
|
478
|
-
openapi: "3.1.0",
|
|
479
|
-
info: {
|
|
480
|
-
title: "Hello World",
|
|
481
|
-
version: "1.0.0"
|
|
482
|
-
},
|
|
483
|
-
paths: {
|
|
484
|
-
"/foobar": {
|
|
485
|
-
get: {
|
|
486
|
-
responses: {
|
|
487
|
-
"200": {
|
|
488
|
-
description: "OK",
|
|
489
|
-
content: {
|
|
490
|
-
"application/json": {
|
|
491
|
-
example: {
|
|
492
|
-
foo: "bar"
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
};
|
|
502
|
-
const server = await createMockServer({
|
|
503
|
-
specification
|
|
504
|
-
});
|
|
505
|
-
let response = await server.request("/foobar", {
|
|
506
|
-
method: "OPTIONS",
|
|
507
|
-
headers: {
|
|
508
|
-
origin: "https://example.com"
|
|
509
|
-
}
|
|
510
|
-
});
|
|
511
|
-
expect(response.status).toBe(204);
|
|
512
|
-
expect(response.headers.get("Access-Control-Allow-Origin")).toBe("*");
|
|
513
|
-
const allowMethodsHeader = response.headers.get("Access-Control-Allow-Methods");
|
|
514
|
-
expect(allowMethodsHeader).toBeTypeOf("string");
|
|
515
|
-
expect(allowMethodsHeader?.split(",").sort()).toStrictEqual(
|
|
516
|
-
["GET", "HEAD", "PUT", "POST", "DELETE", "PATCH"].sort()
|
|
517
|
-
);
|
|
518
|
-
response = await server.request("/foobar", {
|
|
519
|
-
headers: {
|
|
520
|
-
origin: "https://example.com"
|
|
521
|
-
}
|
|
522
|
-
});
|
|
523
|
-
expect(response.status).toBe(200);
|
|
524
|
-
expect(response.headers.get("Access-Control-Allow-Origin")).toBe("*");
|
|
525
|
-
expect(await response.json()).toMatchObject({
|
|
526
|
-
foo: "bar"
|
|
527
|
-
});
|
|
528
|
-
});
|
|
529
|
-
it("adds headers", async () => {
|
|
530
|
-
const specification = {
|
|
531
|
-
openapi: "3.1.0",
|
|
532
|
-
info: {
|
|
533
|
-
title: "Hello World",
|
|
534
|
-
version: "1.0.0"
|
|
535
|
-
},
|
|
536
|
-
paths: {
|
|
537
|
-
"/foobar": {
|
|
538
|
-
get: {
|
|
539
|
-
responses: {
|
|
540
|
-
"200": {
|
|
541
|
-
description: "OK",
|
|
542
|
-
headers: {
|
|
543
|
-
"X-Custom": {
|
|
544
|
-
schema: {
|
|
545
|
-
type: "string",
|
|
546
|
-
example: "foobar"
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
};
|
|
556
|
-
const server = await createMockServer({
|
|
557
|
-
specification
|
|
558
|
-
});
|
|
559
|
-
const response = await server.request("/foobar");
|
|
560
|
-
expect(response.status).toBe(200);
|
|
561
|
-
expect(response.headers.get("X-Custom")).toBe("foobar");
|
|
562
|
-
});
|
|
563
|
-
it("handles redirect headers", async () => {
|
|
564
|
-
const specification = {
|
|
565
|
-
openapi: "3.1.0",
|
|
566
|
-
info: {
|
|
567
|
-
title: "Hello World",
|
|
568
|
-
version: "1.0.0"
|
|
569
|
-
},
|
|
570
|
-
paths: {
|
|
571
|
-
"/redirect": {
|
|
572
|
-
get: {
|
|
573
|
-
responses: {
|
|
574
|
-
"301": {
|
|
575
|
-
description: "Moved Permanently",
|
|
576
|
-
headers: {
|
|
577
|
-
Location: {
|
|
578
|
-
schema: {
|
|
579
|
-
type: "string",
|
|
580
|
-
example: "/new-location"
|
|
581
|
-
}
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
|
-
}
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
|
-
};
|
|
590
|
-
const server = await createMockServer({
|
|
591
|
-
specification
|
|
592
|
-
});
|
|
593
|
-
const response = await server.request("/redirect");
|
|
594
|
-
expect(response.status).toBe(301);
|
|
595
|
-
expect(response.headers.get("Location")).toBe("/new-location");
|
|
596
|
-
});
|
|
597
|
-
});
|
|
598
|
-
//# sourceMappingURL=createMockServer.test.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/createMockServer.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { describe, expect, it } from 'vitest'\n\nimport { createMockServer } from './createMockServer'\n\ndescribe('createMockServer', () => {\n it('GET /foobar -> example JSON', async () => {\n const specification = {\n openapi: '3.1.0',\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n paths: {\n '/foobar': {\n get: {\n responses: {\n '200': {\n description: 'OK',\n content: {\n 'application/json': {\n example: {\n foo: 'bar',\n },\n },\n },\n },\n },\n },\n },\n },\n }\n\n const server = await createMockServer({\n specification,\n })\n\n const response = await server.request('/foobar')\n\n expect(response.status).toBe(200)\n expect(await response.json()).toMatchObject({\n foo: 'bar',\n })\n })\n\n it('GET /foobar -> omits writeOnly properties in responses', async () => {\n const specification = {\n openapi: '3.1.0',\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n paths: {\n '/foobar': {\n get: {\n responses: {\n '200': {\n description: 'OK',\n content: {\n 'application/json': {\n schema: {\n type: 'object',\n properties: {\n id: {\n type: 'integer',\n format: 'int64',\n readOnly: true,\n example: 1,\n },\n visible: {\n type: 'boolean',\n example: true,\n },\n password: {\n type: 'string',\n writeOnly: true,\n },\n },\n },\n },\n },\n },\n },\n },\n },\n },\n }\n\n const server = await createMockServer({\n specification,\n })\n\n const response = await server.request('/foobar')\n\n expect(response.status).toBe(200)\n\n const data = await response.json()\n\n expect(data).not.toHaveProperty('password')\n expect(data).toStrictEqual({\n id: 1,\n visible: true,\n })\n })\n\n it('GET /foobar -> return HTML if accepted', async () => {\n const specification = {\n openapi: '3.1.0',\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n paths: {\n '/foobar': {\n get: {\n responses: {\n '200': {\n description: 'OK',\n content: {\n 'application/json': {\n example: {\n foo: 'bar',\n },\n },\n 'text/html': {\n example: 'foobar',\n },\n },\n },\n },\n },\n },\n },\n }\n\n const server = await createMockServer({\n specification,\n })\n\n const response = await server.request('/foobar', {\n headers: {\n Accept: 'text/html',\n },\n })\n\n expect(response.status).toBe(200)\n expect(await response.text()).toBe('foobar')\n })\n\n it('GET /foobar -> fall back to JSON', async () => {\n const specification = {\n openapi: '3.1.0',\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n paths: {\n '/foobar': {\n get: {\n responses: {\n '200': {\n description: 'OK',\n content: {\n 'application/json': {\n example: {\n foo: 'bar',\n },\n },\n 'text/html': {\n example: 'foobar',\n },\n },\n },\n },\n },\n },\n },\n }\n\n const server = await createMockServer({\n specification,\n })\n\n const response = await server.request('/foobar')\n\n expect(response.status).toBe(200)\n expect(await response.json()).toMatchObject({\n foo: 'bar',\n })\n })\n\n it('GET /foobar -> XML', async () => {\n const specification = {\n openapi: '3.1.0',\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n paths: {\n '/foobar': {\n get: {\n responses: {\n '200': {\n description: 'OK',\n content: {\n 'application/xml': {\n example: {\n foo: 'bar',\n },\n },\n },\n },\n },\n },\n },\n },\n }\n\n const server = await createMockServer({\n specification,\n })\n\n const response = await server.request('/foobar')\n\n expect(response.status).toBe(200)\n expect(await response.text()).toContain('<foo>bar</foo>')\n })\n\n it('uses http verbs only to register routes', async () => {\n const specification = {\n openapi: '3.1.0',\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n paths: {\n '/foobar': {\n summary: '',\n description: '',\n parameters: {},\n servers: {},\n get: {\n responses: {\n '200': {\n description: 'OK',\n content: {\n 'application/json': {\n example: {\n foo: 'bar',\n },\n },\n },\n },\n },\n },\n },\n },\n }\n\n const server = await createMockServer({\n specification,\n })\n\n const response = await server.request('/foobar')\n\n expect(response.status).toBe(200)\n expect(await response.json()).toMatchObject({\n foo: 'bar',\n })\n })\n\n it('POST /foobar -> example JSON', async () => {\n const specification = {\n openapi: '3.1.0',\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n paths: {\n '/foobar': {\n post: {\n responses: {\n '200': {\n description: 'OK',\n content: {\n 'application/json': {\n example: {\n foo: 'bar',\n },\n },\n },\n },\n },\n },\n },\n },\n }\n\n const server = await createMockServer({\n specification,\n })\n\n const response = await server.request('/foobar', {\n method: 'POST',\n })\n\n expect(response.status).toBe(200)\n expect(await response.json()).toMatchObject({\n foo: 'bar',\n })\n })\n\n it('POST /foobar -> return 201', async () => {\n const specification = {\n openapi: '3.1.0',\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n paths: {\n '/foobar': {\n post: {\n responses: {\n '201': {\n description: 'OK',\n content: {\n 'application/json': {\n example: {\n foo: 'bar',\n },\n },\n },\n },\n },\n },\n },\n },\n }\n\n const server = await createMockServer({\n specification,\n })\n\n const response = await server.request('/foobar', {\n method: 'POST',\n })\n\n expect(response.status).toBe(201)\n expect(await response.json()).toMatchObject({\n foo: 'bar',\n })\n })\n\n it('POST /foobar/{id} -> example JSON', async () => {\n const specification = {\n openapi: '3.1.0',\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n paths: {\n '/foobar/{id}': {\n get: {\n responses: {\n '200': {\n description: 'OK',\n content: {\n 'application/json': {\n example: {\n foo: 'bar',\n },\n },\n },\n },\n },\n },\n },\n },\n }\n\n const server = await createMockServer({\n specification,\n })\n\n const response = await server.request('/foobar/123')\n\n expect(response.status).toBe(200)\n expect(await response.json()).toMatchObject({\n foo: 'bar',\n })\n })\n\n it('POST /foobar/{id} -> uses dynamic ID', async () => {\n const specification = {\n openapi: '3.1.0',\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n paths: {\n '/foobar/{id}': {\n get: {\n responses: {\n '200': {\n description: 'OK',\n content: {\n 'application/json': {\n schema: {\n type: 'object',\n properties: {\n id: {\n 'type': 'number',\n 'example': 'bar',\n 'x-variable': 'id',\n },\n },\n },\n },\n },\n },\n },\n },\n },\n },\n }\n\n const server = await createMockServer({\n specification,\n })\n\n const response = await server.request('/foobar/123')\n\n expect(await response.json()).toMatchObject({\n id: 123,\n })\n expect(response.status).toBe(200)\n })\n\n it('GET /foobar -> example from schema', async () => {\n const specification = {\n openapi: '3.1.0',\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n paths: {\n '/foobar': {\n get: {\n responses: {\n '200': {\n description: 'OK',\n content: {\n 'application/json': {\n schema: {\n type: 'object',\n properties: {\n foo: {\n type: 'string',\n example: 'bar',\n },\n },\n },\n },\n },\n },\n },\n },\n },\n },\n }\n\n const server = await createMockServer({\n specification,\n })\n\n const response = await server.request('/foobar')\n\n expect(response.status).toBe(200)\n expect(await response.json()).toMatchObject({\n foo: 'bar',\n })\n })\n\n it('GET /foobar/{id} -> example from schema', async () => {\n const specification = {\n openapi: '3.1.0',\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n paths: {\n '/foobar/{id}': {\n get: {\n responses: {\n '200': {\n description: 'OK',\n content: {\n 'application/json': {\n schema: {\n type: 'object',\n properties: {\n foo: {\n type: 'string',\n example: 'bar',\n },\n },\n },\n },\n },\n },\n },\n },\n },\n },\n }\n\n const server = await createMockServer({\n specification,\n })\n\n const response = await server.request('/foobar/123')\n\n expect(response.status).toBe(200)\n expect(await response.json()).toMatchObject({\n foo: 'bar',\n })\n })\n\n it('has CORS headers', async () => {\n const specification = {\n openapi: '3.1.0',\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n paths: {\n '/foobar': {\n get: {\n responses: {\n '200': {\n description: 'OK',\n content: {\n 'application/json': {\n example: {\n foo: 'bar',\n },\n },\n },\n },\n },\n },\n },\n },\n }\n\n const server = await createMockServer({\n specification,\n })\n\n // Options request\n let response = await server.request('/foobar', {\n method: 'OPTIONS',\n headers: {\n origin: 'https://example.com',\n },\n })\n\n expect(response.status).toBe(204)\n\n expect(response.headers.get('Access-Control-Allow-Origin')).toBe('*')\n\n const allowMethodsHeader = response.headers.get('Access-Control-Allow-Methods')\n expect(allowMethodsHeader).toBeTypeOf('string')\n expect(allowMethodsHeader?.split(',').sort()).toStrictEqual(\n ['GET', 'HEAD', 'PUT', 'POST', 'DELETE', 'PATCH'].sort(),\n )\n\n // Get request\n response = await server.request('/foobar', {\n headers: {\n origin: 'https://example.com',\n },\n })\n\n expect(response.status).toBe(200)\n expect(response.headers.get('Access-Control-Allow-Origin')).toBe('*')\n\n expect(await response.json()).toMatchObject({\n foo: 'bar',\n })\n })\n\n it('adds headers', async () => {\n const specification = {\n openapi: '3.1.0',\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n paths: {\n '/foobar': {\n get: {\n responses: {\n '200': {\n description: 'OK',\n headers: {\n 'X-Custom': {\n schema: {\n type: 'string',\n example: 'foobar',\n },\n },\n },\n },\n },\n },\n },\n },\n }\n\n const server = await createMockServer({\n specification,\n })\n\n const response = await server.request('/foobar')\n\n expect(response.status).toBe(200)\n expect(response.headers.get('X-Custom')).toBe('foobar')\n })\n\n it('handles redirect headers', async () => {\n const specification = {\n openapi: '3.1.0',\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n paths: {\n '/redirect': {\n get: {\n responses: {\n '301': {\n description: 'Moved Permanently',\n headers: {\n Location: {\n schema: {\n type: 'string',\n example: '/new-location',\n },\n },\n },\n },\n },\n },\n },\n },\n }\n\n const server = await createMockServer({\n specification,\n })\n\n const response = await server.request('/redirect')\n\n expect(response.status).toBe(301)\n expect(response.headers.get('Location')).toBe('/new-location')\n })\n})\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,UAAU,QAAQ,UAAU;AAErC,SAAS,wBAAwB;AAEjC,SAAS,oBAAoB,MAAM;AACjC,KAAG,+BAA+B,YAAY;AAC5C,UAAM,gBAAgB;AAAA,MACpB,SAAS;AAAA,MACT,MAAM;AAAA,QACJ,OAAO;AAAA,QACP,SAAS;AAAA,MACX;AAAA,MACA,OAAO;AAAA,QACL,WAAW;AAAA,UACT,KAAK;AAAA,YACH,WAAW;AAAA,cACT,OAAO;AAAA,gBACL,aAAa;AAAA,gBACb,SAAS;AAAA,kBACP,oBAAoB;AAAA,oBAClB,SAAS;AAAA,sBACP,KAAK;AAAA,oBACP;AAAA,kBACF;AAAA,gBACF;AAAA,c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A,cACT,OAAO;AAAA,gBACL,aAAa;AAAA,gBACb,SAAS;AAAA,kBACP,YAAY;AAAA,oBACV,QAAQ;AAAA,sBACN,MAAM;AAAA,sBACN,SAAS;AAAA,oBACX;AAAA,kBACF;AAAA,gBACF;AAAA,cACF;AAAA,YACF;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAEA,UAAM,SAAS,MAAM,iBAAiB;AAAA,MACpC;AAAA,IACF,CAAC;AAED,UAAM,WAAW,MAAM,OAAO,QAAQ,SAAS;AAE/C,WAAO,SAAS,MAAM,EAAE,KAAK,GAAG;AAChC,WAAO,SAAS,QAAQ,IAAI,UAAU,CAAC,EAAE,KAAK,QAAQ;AAAA,EACxD,CAAC;AAED,KAAG,4BAA4B,YAAY;AACzC,UAAM,gBAAgB;AAAA,MACpB,SAAS;AAAA,MACT,MAAM;AAAA,QACJ,OAAO;AAAA,QACP,SAAS;AAAA,MACX;AAAA,MACA,OAAO;AAAA,QACL,aAAa;AAAA,UACX,KAAK;AAAA,YACH,WAAW;AAAA,cACT,OAAO;AAAA,gBACL,aAAa;AAAA,gBACb,SAAS;AAAA,kBACP,UAAU;AAAA,oBACR,QAAQ;AAAA,sBACN,MAAM;AAAA,sBACN,SAAS;AAAA,oBACX;AAAA,kBACF;AAAA,gBACF;AAAA,cACF;AAAA,YACF;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAEA,UAAM,SAAS,MAAM,iBAAiB;AAAA,MACpC;AAAA,IACF,CAAC;AAED,UAAM,WAAW,MAAM,OAAO,QAAQ,WAAW;AAEjD,WAAO,SAAS,MAAM,EAAE,KAAK,GAAG;AAChC,WAAO,SAAS,QAAQ,IAAI,UAAU,CAAC,EAAE,KAAK,eAAe;AAAA,EAC/D,CAAC;AACH,CAAC;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { findPreferredResponseKey } from "./findPreferredResponseKey.js";
|
|
3
|
-
describe("findPreferredResponseKey", () => {
|
|
4
|
-
it("returns default over 200", () => {
|
|
5
|
-
expect(findPreferredResponseKey(["default", "200"])).toBe("default");
|
|
6
|
-
});
|
|
7
|
-
it("returns 201 if it\u2019s the only one", () => {
|
|
8
|
-
expect(findPreferredResponseKey(["201"])).toBe("201");
|
|
9
|
-
});
|
|
10
|
-
it("returns 200 over 201", () => {
|
|
11
|
-
expect(findPreferredResponseKey(["200", "201"])).toBe("200");
|
|
12
|
-
});
|
|
13
|
-
it("uses what\u2019s there", () => {
|
|
14
|
-
expect(findPreferredResponseKey(["301"])).toBe("301");
|
|
15
|
-
});
|
|
16
|
-
it("doesn\u2019t return anything if there\u2019s no key at all", () => {
|
|
17
|
-
expect(findPreferredResponseKey([])).toBe(void 0);
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
//# sourceMappingURL=findPreferredResponseKey.test.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/utils/findPreferredResponseKey.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { describe, expect, it } from 'vitest'\n\nimport { findPreferredResponseKey } from './findPreferredResponseKey'\n\ndescribe('findPreferredResponseKey', () => {\n it('returns default over 200', () => {\n expect(findPreferredResponseKey(['default', '200'])).toBe('default')\n })\n\n it('returns 201 if it\u2019s the only one', () => {\n expect(findPreferredResponseKey(['201'])).toBe('201')\n })\n\n it('returns 200 over 201', () => {\n expect(findPreferredResponseKey(['200', '201'])).toBe('200')\n })\n\n it('uses what\u2019s there', () => {\n expect(findPreferredResponseKey(['301'])).toBe('301')\n })\n\n it('doesn\u2019t return anything if there\u2019s no key at all', () => {\n expect(findPreferredResponseKey([])).toBe(undefined)\n })\n})\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,UAAU,QAAQ,UAAU;AAErC,SAAS,gCAAgC;AAEzC,SAAS,4BAA4B,MAAM;AACzC,KAAG,4BAA4B,MAAM;AACnC,WAAO,yBAAyB,CAAC,WAAW,KAAK,CAAC,CAAC,EAAE,KAAK,SAAS;AAAA,EACrE,CAAC;AAED,KAAG,yCAAoC,MAAM;AAC3C,WAAO,yBAAyB,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,KAAK;AAAA,EACtD,CAAC;AAED,KAAG,wBAAwB,MAAM;AAC/B,WAAO,yBAAyB,CAAC,OAAO,KAAK,CAAC,CAAC,EAAE,KAAK,KAAK;AAAA,EAC7D,CAAC;AAED,KAAG,0BAAqB,MAAM;AAC5B,WAAO,yBAAyB,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,KAAK;AAAA,EACtD,CAAC;AAED,KAAG,8DAAoD,MAAM;AAC3D,WAAO,yBAAyB,CAAC,CAAC,CAAC,EAAE,KAAK,MAAS;AAAA,EACrD,CAAC;AACH,CAAC;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { createOpenApiDefinition } from "./createOpenApiDefinition.js";
|
|
3
|
-
import { getOpenAuthTokenUrls, getPathFromUrl } from "./getOpenAuthTokenUrls.js";
|
|
4
|
-
describe("getOpenAuthTokenUrls", () => {
|
|
5
|
-
it("returns an empty array for schema without securitySchemes", () => {
|
|
6
|
-
const schema = createOpenApiDefinition({});
|
|
7
|
-
expect(getOpenAuthTokenUrls(schema)).toEqual([]);
|
|
8
|
-
});
|
|
9
|
-
it("returns token URLs from OAuth2 password flow", () => {
|
|
10
|
-
const schema = createOpenApiDefinition({
|
|
11
|
-
oauth2Password: {
|
|
12
|
-
type: "oauth2",
|
|
13
|
-
flows: {
|
|
14
|
-
password: {
|
|
15
|
-
tokenUrl: "https://api.example.com/oauth/token"
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
expect(getOpenAuthTokenUrls(schema)).toEqual(["/oauth/token"]);
|
|
21
|
-
});
|
|
22
|
-
it("returns token URLs from OAuth2 clientCredentials flow", () => {
|
|
23
|
-
const schema = createOpenApiDefinition({
|
|
24
|
-
oauth2ClientCredentials: {
|
|
25
|
-
type: "oauth2",
|
|
26
|
-
flows: {
|
|
27
|
-
clientCredentials: {
|
|
28
|
-
tokenUrl: "https://api.example.com/oauth/client_token"
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
expect(getOpenAuthTokenUrls(schema)).toEqual(["/oauth/client_token"]);
|
|
34
|
-
});
|
|
35
|
-
it("returns token URLs from OAuth2 authorizationCode flow", () => {
|
|
36
|
-
const schema = createOpenApiDefinition({
|
|
37
|
-
oauth2AuthCode: {
|
|
38
|
-
type: "oauth2",
|
|
39
|
-
flows: {
|
|
40
|
-
authorizationCode: {
|
|
41
|
-
authorizationUrl: "https://api.example.com/oauth/authorize",
|
|
42
|
-
tokenUrl: "https://api.example.com/oauth/token"
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
expect(getOpenAuthTokenUrls(schema)).toEqual(["/oauth/token"]);
|
|
48
|
-
});
|
|
49
|
-
it("returns multiple token URLs from different OAuth2 flows", () => {
|
|
50
|
-
const schema = createOpenApiDefinition({
|
|
51
|
-
oauth2Password: {
|
|
52
|
-
type: "oauth2",
|
|
53
|
-
flows: {
|
|
54
|
-
password: {
|
|
55
|
-
tokenUrl: "https://api.example.com/oauth/password_token"
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
},
|
|
59
|
-
oauth2ClientCredentials: {
|
|
60
|
-
type: "oauth2",
|
|
61
|
-
flows: {
|
|
62
|
-
clientCredentials: {
|
|
63
|
-
tokenUrl: "https://api.example.com/oauth/client_token"
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
expect(getOpenAuthTokenUrls(schema)).toEqual(["/oauth/password_token", "/oauth/client_token"]);
|
|
69
|
-
});
|
|
70
|
-
it("ignores non-OAuth2 security schemes", () => {
|
|
71
|
-
const schema = createOpenApiDefinition({
|
|
72
|
-
basicAuth: {
|
|
73
|
-
type: "http",
|
|
74
|
-
scheme: "basic"
|
|
75
|
-
},
|
|
76
|
-
oauth2Password: {
|
|
77
|
-
type: "oauth2",
|
|
78
|
-
flows: {
|
|
79
|
-
password: {
|
|
80
|
-
tokenUrl: "https://api.example.com/oauth/token"
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
expect(getOpenAuthTokenUrls(schema)).toEqual(["/oauth/token"]);
|
|
86
|
-
});
|
|
87
|
-
it("returns unique token URLs", () => {
|
|
88
|
-
const schema = createOpenApiDefinition({
|
|
89
|
-
oauth2Password: {
|
|
90
|
-
type: "oauth2",
|
|
91
|
-
flows: {
|
|
92
|
-
password: {
|
|
93
|
-
tokenUrl: "https://api.example.com/oauth/token"
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
},
|
|
97
|
-
oauth2ClientCredentials: {
|
|
98
|
-
type: "oauth2",
|
|
99
|
-
flows: {
|
|
100
|
-
clientCredentials: {
|
|
101
|
-
tokenUrl: "https://api.example.com/oauth/token"
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
expect(getOpenAuthTokenUrls(schema)).toEqual(["/oauth/token"]);
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
describe("getPathFromUrl", () => {
|
|
110
|
-
it("returns the path from a valid URL", () => {
|
|
111
|
-
const url = "https://api.example.com/oauth/token";
|
|
112
|
-
expect(getPathFromUrl(url)).toBe("/oauth/token");
|
|
113
|
-
});
|
|
114
|
-
it("handles URLs with query parameters", () => {
|
|
115
|
-
const url = "https://api.example.com/oauth/token?param=value";
|
|
116
|
-
expect(getPathFromUrl(url)).toBe("/oauth/token");
|
|
117
|
-
});
|
|
118
|
-
it("handles URLs with fragments", () => {
|
|
119
|
-
const url = "https://api.example.com/oauth/token#fragment";
|
|
120
|
-
expect(getPathFromUrl(url)).toBe("/oauth/token");
|
|
121
|
-
});
|
|
122
|
-
it("handles URLs without paths", () => {
|
|
123
|
-
const url = "https://api.example.com";
|
|
124
|
-
expect(getPathFromUrl(url)).toBe("/");
|
|
125
|
-
});
|
|
126
|
-
});
|
|
127
|
-
//# sourceMappingURL=getOpenAuthTokenUrls.test.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/utils/getOpenAuthTokenUrls.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { describe, expect, it } from 'vitest'\n\nimport { createOpenApiDefinition } from './createOpenApiDefinition'\nimport { getOpenAuthTokenUrls, getPathFromUrl } from './getOpenAuthTokenUrls'\n\ndescribe('getOpenAuthTokenUrls', () => {\n it('returns an empty array for schema without securitySchemes', () => {\n const schema = createOpenApiDefinition({})\n expect(getOpenAuthTokenUrls(schema)).toEqual([])\n })\n\n it('returns token URLs from OAuth2 password flow', () => {\n const schema = createOpenApiDefinition({\n oauth2Password: {\n type: 'oauth2',\n flows: {\n password: {\n tokenUrl: 'https://api.example.com/oauth/token',\n },\n },\n },\n })\n expect(getOpenAuthTokenUrls(schema)).toEqual(['/oauth/token'])\n })\n\n it('returns token URLs from OAuth2 clientCredentials flow', () => {\n const schema = createOpenApiDefinition({\n oauth2ClientCredentials: {\n type: 'oauth2',\n flows: {\n clientCredentials: {\n tokenUrl: 'https://api.example.com/oauth/client_token',\n },\n },\n },\n })\n expect(getOpenAuthTokenUrls(schema)).toEqual(['/oauth/client_token'])\n })\n\n it('returns token URLs from OAuth2 authorizationCode flow', () => {\n const schema = createOpenApiDefinition({\n oauth2AuthCode: {\n type: 'oauth2',\n flows: {\n authorizationCode: {\n authorizationUrl: 'https://api.example.com/oauth/authorize',\n tokenUrl: 'https://api.example.com/oauth/token',\n },\n },\n },\n })\n expect(getOpenAuthTokenUrls(schema)).toEqual(['/oauth/token'])\n })\n\n it('returns multiple token URLs from different OAuth2 flows', () => {\n const schema = createOpenApiDefinition({\n oauth2Password: {\n type: 'oauth2',\n flows: {\n password: {\n tokenUrl: 'https://api.example.com/oauth/password_token',\n },\n },\n },\n oauth2ClientCredentials: {\n type: 'oauth2',\n flows: {\n clientCredentials: {\n tokenUrl: 'https://api.example.com/oauth/client_token',\n },\n },\n },\n })\n expect(getOpenAuthTokenUrls(schema)).toEqual(['/oauth/password_token', '/oauth/client_token'])\n })\n\n it('ignores non-OAuth2 security schemes', () => {\n const schema = createOpenApiDefinition({\n basicAuth: {\n type: 'http',\n scheme: 'basic',\n },\n oauth2Password: {\n type: 'oauth2',\n flows: {\n password: {\n tokenUrl: 'https://api.example.com/oauth/token',\n },\n },\n },\n })\n expect(getOpenAuthTokenUrls(schema)).toEqual(['/oauth/token'])\n })\n\n it('returns unique token URLs', () => {\n const schema = createOpenApiDefinition({\n oauth2Password: {\n type: 'oauth2',\n flows: {\n password: {\n tokenUrl: 'https://api.example.com/oauth/token',\n },\n },\n },\n oauth2ClientCredentials: {\n type: 'oauth2',\n flows: {\n clientCredentials: {\n tokenUrl: 'https://api.example.com/oauth/token',\n },\n },\n },\n })\n expect(getOpenAuthTokenUrls(schema)).toEqual(['/oauth/token'])\n })\n})\n\ndescribe('getPathFromUrl', () => {\n it('returns the path from a valid URL', () => {\n const url = 'https://api.example.com/oauth/token'\n expect(getPathFromUrl(url)).toBe('/oauth/token')\n })\n\n it('handles URLs with query parameters', () => {\n const url = 'https://api.example.com/oauth/token?param=value'\n expect(getPathFromUrl(url)).toBe('/oauth/token')\n })\n\n it('handles URLs with fragments', () => {\n const url = 'https://api.example.com/oauth/token#fragment'\n expect(getPathFromUrl(url)).toBe('/oauth/token')\n })\n\n it('handles URLs without paths', () => {\n const url = 'https://api.example.com'\n expect(getPathFromUrl(url)).toBe('/')\n })\n})\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,UA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AA,EACjD,CAAC;AAED,KAAG,+BAA+B,MAAM;AACtC,UAAM,MAAM;AACZ,WAAO,eAAe,GAAG,CAAC,EAAE,KAAK,cAAc;AAAA,EACjD,CAAC;AAED,KAAG,8BAA8B,MAAM;AACrC,UAAM,MAAM;AACZ,WAAO,eAAe,GAAG,CAAC,EAAE,KAAK,GAAG;AAAA,EACtC,CAAC;AACH,CAAC;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { honoRouteFromPath } from "./honoRouteFromPath.js";
|
|
3
|
-
describe("honoRouteFromPath", () => {
|
|
4
|
-
it("returns correct route for a simple path", () => {
|
|
5
|
-
expect(honoRouteFromPath("/foobar")).toBe("/foobar");
|
|
6
|
-
});
|
|
7
|
-
it("returns correct route for a path with an ID", () => {
|
|
8
|
-
expect(honoRouteFromPath("/foobar/{id}")).toBe("/foobar/:id");
|
|
9
|
-
});
|
|
10
|
-
it("returns correct route for a path with multiple parameters", () => {
|
|
11
|
-
expect(honoRouteFromPath("/users/{userId}/posts/{postId}")).toBe("/users/:userId/posts/:postId");
|
|
12
|
-
});
|
|
13
|
-
it("returns correct route for a path with a parameter in the middle", () => {
|
|
14
|
-
expect(honoRouteFromPath("/api/{version}/users")).toBe("/api/:version/users");
|
|
15
|
-
});
|
|
16
|
-
it("returns correct route for a path with special characters", () => {
|
|
17
|
-
expect(honoRouteFromPath("/items/{item-id}")).toBe("/items/:item-id");
|
|
18
|
-
});
|
|
19
|
-
it("returns correct route for a path with numbers", () => {
|
|
20
|
-
expect(honoRouteFromPath("/v1/products/{productId}")).toBe("/v1/products/:productId");
|
|
21
|
-
});
|
|
22
|
-
it.skip("handles invalid parameter syntax gracefully", () => {
|
|
23
|
-
expect(() => honoRouteFromPath("/{invalid{}param}")).toThrow();
|
|
24
|
-
});
|
|
25
|
-
it("handles multiple consecutive parameters", () => {
|
|
26
|
-
expect(honoRouteFromPath("/users/{userId}{postId}")).toBe("/users/:userId:postId");
|
|
27
|
-
});
|
|
28
|
-
it("handles parameters with special naming patterns", () => {
|
|
29
|
-
expect(honoRouteFromPath("/api/{api.version}/{user_id}")).toBe("/api/:api.version/:user_id");
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
//# sourceMappingURL=honoRouteFromPath.test.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/utils/honoRouteFromPath.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { describe, expect, it } from 'vitest'\n\nimport { honoRouteFromPath } from './honoRouteFromPath'\n\ndescribe('honoRouteFromPath', () => {\n it('returns correct route for a simple path', () => {\n expect(honoRouteFromPath('/foobar')).toBe('/foobar')\n })\n\n it('returns correct route for a path with an ID', () => {\n expect(honoRouteFromPath('/foobar/{id}')).toBe('/foobar/:id')\n })\n\n it('returns correct route for a path with multiple parameters', () => {\n expect(honoRouteFromPath('/users/{userId}/posts/{postId}')).toBe('/users/:userId/posts/:postId')\n })\n\n it('returns correct route for a path with a parameter in the middle', () => {\n expect(honoRouteFromPath('/api/{version}/users')).toBe('/api/:version/users')\n })\n\n it('returns correct route for a path with special characters', () => {\n expect(honoRouteFromPath('/items/{item-id}')).toBe('/items/:item-id')\n })\n\n it('returns correct route for a path with numbers', () => {\n expect(honoRouteFromPath('/v1/products/{productId}')).toBe('/v1/products/:productId')\n })\n\n it.skip('handles invalid parameter syntax gracefully', () => {\n expect(() => honoRouteFromPath('/{invalid{}param}')).toThrow()\n })\n\n it('handles multiple consecutive parameters', () => {\n expect(honoRouteFromPath('/users/{userId}{postId}')).toBe('/users/:userId:postId')\n })\n\n it('handles parameters with special naming patterns', () => {\n expect(honoRouteFromPath('/api/{api.version}/{user_id}')).toBe('/api/:api.version/:user_id')\n })\n})\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,UAAU,QAAQ,UAAU;AAErC,SAAS,yBAAyB;AAElC,SAAS,qBAAqB,MAAM;AAClC,KAAG,2CAA2C,MAAM;AAClD,WAAO,kBAAkB,SAAS,CAAC,EAAE,KAAK,SAAS;AAAA,EACrD,CAAC;AAED,KAAG,+CAA+C,MAAM;AACtD,WAAO,kBAAkB,cAAc,CAAC,EAAE,KAAK,aAAa;AAAA,EAC9D,CAAC;AAED,KAAG,6DAA6D,MAAM;AACpE,WAAO,kBAAkB,gCAAgC,CAAC,EAAE,KAAK,8BAA8B;AAAA,EACjG,CAAC;AAED,KAAG,mEAAmE,MAAM;AAC1E,WAAO,kBAAkB,sBAAsB,CAAC,EAAE,KAAK,qBAAqB;AAAA,EAC9E,CAAC;AAED,KAAG,4DAA4D,MAAM;AACnE,WAAO,kBAAkB,kBAAkB,CAAC,EAAE,KAAK,iBAAiB;AAAA,EACtE,CAAC;AAED,KAAG,iDAAiD,MAAM;AACxD,WAAO,kBAAkB,0BAA0B,CAAC,EAAE,KAAK,yBAAyB;AAAA,EACtF,CAAC;AAED,KAAG,KAAK,+CAA+C,MAAM;AAC3D,WAAO,MAAM,kBAAkB,mBAAmB,CAAC,EAAE,QAAQ;AAAA,EAC/D,CAAC;AAED,KAAG,2CAA2C,MAAM;AAClD,WAAO,kBAAkB,yBAAyB,CAAC,EAAE,KAAK,uBAAuB;AAAA,EACnF,CAAC;AAED,KAAG,mDAAmD,MAAM;AAC1D,WAAO,kBAAkB,8BAA8B,CAAC,EAAE,KAAK,4BAA4B;AAAA,EAC7F,CAAC;AACH,CAAC;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { isAuthenticationRequired } from "./isAuthenticationRequired.js";
|
|
3
|
-
describe("isAuthenticationRequired", () => {
|
|
4
|
-
it("returns false when security is undefined", () => {
|
|
5
|
-
expect(isAuthenticationRequired(void 0)).toBe(false);
|
|
6
|
-
});
|
|
7
|
-
it("returns false when security is an empty array", () => {
|
|
8
|
-
expect(isAuthenticationRequired([])).toBe(false);
|
|
9
|
-
});
|
|
10
|
-
it("returns false when security includes an empty object", () => {
|
|
11
|
-
expect(isAuthenticationRequired([{}])).toBe(false);
|
|
12
|
-
});
|
|
13
|
-
it("returns true when security is defined and not empty", () => {
|
|
14
|
-
expect(isAuthenticationRequired([{ apiKey: [] }])).toBe(true);
|
|
15
|
-
});
|
|
16
|
-
it("returns true when security has multiple schemes", () => {
|
|
17
|
-
expect(isAuthenticationRequired([{ apiKey: [] }, { oauth2: ["read", "write"] }])).toBe(true);
|
|
18
|
-
});
|
|
19
|
-
it("returns false when security is an array with an empty object among non-empty objects", () => {
|
|
20
|
-
expect(isAuthenticationRequired([{ apiKey: [] }, {}, { oauth2: ["read"] }])).toBe(false);
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
//# sourceMappingURL=isAuthenticationRequired.test.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/utils/isAuthenticationRequired.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { describe, expect, it } from 'vitest'\n\nimport { isAuthenticationRequired } from './isAuthenticationRequired'\n\ndescribe('isAuthenticationRequired', () => {\n it('returns false when security is undefined', () => {\n expect(isAuthenticationRequired(undefined)).toBe(false)\n })\n\n it('returns false when security is an empty array', () => {\n expect(isAuthenticationRequired([])).toBe(false)\n })\n\n it('returns false when security includes an empty object', () => {\n expect(isAuthenticationRequired([{}])).toBe(false)\n })\n\n it('returns true when security is defined and not empty', () => {\n expect(isAuthenticationRequired([{ apiKey: [] }])).toBe(true)\n })\n\n it('returns true when security has multiple schemes', () => {\n expect(isAuthenticationRequired([{ apiKey: [] }, { oauth2: ['read', 'write'] }])).toBe(true)\n })\n\n it('returns false when security is an array with an empty object among non-empty objects', () => {\n expect(isAuthenticationRequired([{ apiKey: [] }, {}, { oauth2: ['read'] }])).toBe(false)\n })\n})\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,UAAU,QAAQ,UAAU;AAErC,SAAS,gCAAgC;AAEzC,SAAS,4BAA4B,MAAM;AACzC,KAAG,4CAA4C,MAAM;AACnD,WAAO,yBAAyB,MAAS,CAAC,EAAE,KAAK,KAAK;AAAA,EACxD,CAAC;AAED,KAAG,iDAAiD,MAAM;AACxD,WAAO,yBAAyB,CAAC,CAAC,CAAC,EAAE,KAAK,KAAK;AAAA,EACjD,CAAC;AAED,KAAG,wDAAwD,MAAM;AAC/D,WAAO,yBAAyB,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,KAAK;AAAA,EACnD,CAAC;AAED,KAAG,uDAAuD,MAAM;AAC9D,WAAO,yBAAyB,CAAC,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,IAAI;AAAA,EAC9D,CAAC;AAED,KAAG,mDAAmD,MAAM;AAC1D,WAAO,yBAAyB,CAAC,EAAE,QAAQ,CAAC,EAAE,GAAG,EAAE,QAAQ,CAAC,QAAQ,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,IAAI;AAAA,EAC7F,CAAC;AAED,KAAG,wFAAwF,MAAM;AAC/F,WAAO,yBAAyB,CAAC,EAAE,QAAQ,CAAC,EAAE,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,KAAK;AAAA,EACzF,CAAC;AACH,CAAC;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|