@scalar/openapi-parser 0.12.0 → 0.13.0
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 +6 -0
- package/dist/configuration/index.d.ts +2 -2
- package/dist/configuration/index.js +2 -2
- package/dist/configuration/index.js.map +1 -1
- package/dist/utils/details.d.ts +1 -2
- package/dist/utils/details.d.ts.map +1 -1
- package/dist/utils/details.js +12 -9
- package/dist/utils/details.js.map +2 -2
- package/dist/utils/normalize.d.ts +1 -1
- package/dist/utils/normalize.d.ts.map +1 -1
- package/dist/utils/normalize.js +16 -11
- package/dist/utils/normalize.js.map +2 -2
- package/dist/utils/resolve-references.d.ts.map +1 -1
- package/dist/utils/resolve-references.js +11 -0
- package/dist/utils/resolve-references.js.map +2 -2
- package/package.json +2 -2
- package/dist/lib/Validator/Validator.test.js +0 -8
- package/dist/lib/Validator/Validator.test.js.map +0 -7
- package/dist/plugins/fetch-urls/fetch-urls.test.js +0 -50
- package/dist/plugins/fetch-urls/fetch-urls.test.js.map +0 -7
- package/dist/plugins/read-files/read-files.test.js +0 -20
- package/dist/plugins/read-files/read-files.test.js.map +0 -7
- package/dist/utils/dereference.test.js +0 -300
- package/dist/utils/dereference.test.js.map +0 -7
- package/dist/utils/errors.test.js +0 -48
- package/dist/utils/errors.test.js.map +0 -7
- package/dist/utils/escape-json-pointer.test.js +0 -11
- package/dist/utils/escape-json-pointer.test.js.map +0 -7
- package/dist/utils/get-entrypoint.test.js +0 -18
- package/dist/utils/get-entrypoint.test.js.map +0 -7
- package/dist/utils/get-segments-from-path.test.js +0 -13
- package/dist/utils/get-segments-from-path.test.js.map +0 -7
- package/dist/utils/is-filesystem.test.js +0 -15
- package/dist/utils/is-filesystem.test.js.map +0 -7
- package/dist/utils/is-object.test.js +0 -23
- package/dist/utils/is-object.test.js.map +0 -7
- package/dist/utils/load/load.test.js +0 -361
- package/dist/utils/load/load.test.js.map +0 -7
- package/dist/utils/normalize.test.js +0 -88
- package/dist/utils/normalize.test.js.map +0 -7
- package/dist/utils/resolve-references.test.js +0 -567
- package/dist/utils/resolve-references.test.js.map +0 -7
- package/dist/utils/transform/sanitize.test.js +0 -148
- package/dist/utils/transform/sanitize.test.js.map +0 -7
- package/dist/utils/transform-errors.test.js +0 -17
- package/dist/utils/transform-errors.test.js.map +0 -7
- package/dist/utils/traverse.test.js +0 -68
- package/dist/utils/traverse.test.js.map +0 -7
- package/dist/utils/unescape-json-pointer.test.js +0 -19
- package/dist/utils/unescape-json-pointer.test.js.map +0 -7
- package/dist/utils/upgrade-from-three-to-three-one.test.js +0 -462
- package/dist/utils/upgrade-from-three-to-three-one.test.js.map +0 -7
- package/dist/utils/upgrade-from-two-to-three.test.js +0 -589
- package/dist/utils/upgrade-from-two-to-three.test.js.map +0 -7
- package/dist/utils/upgrade.test.js +0 -57
- package/dist/utils/upgrade.test.js.map +0 -7
- package/dist/utils/validate.test.js +0 -64
- package/dist/utils/validate.test.js.map +0 -7
|
@@ -1,361 +0,0 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
3
|
-
import { stringify } from "yaml";
|
|
4
|
-
import { fetchUrls } from "../../plugins/fetch-urls/fetch-urls.js";
|
|
5
|
-
import { readFiles } from "../../plugins/read-files/read-files.js";
|
|
6
|
-
import { getEntrypoint } from "../../utils/get-entrypoint.js";
|
|
7
|
-
import { load } from "./load.js";
|
|
8
|
-
global.fetch = vi.fn();
|
|
9
|
-
describe("load", async () => {
|
|
10
|
-
beforeEach(() => {
|
|
11
|
-
global.fetch.mockReset();
|
|
12
|
-
});
|
|
13
|
-
it("loads JS object", async () => {
|
|
14
|
-
const { filesystem } = await load(
|
|
15
|
-
{
|
|
16
|
-
openapi: "3.1.0",
|
|
17
|
-
info: {
|
|
18
|
-
title: "Hello World",
|
|
19
|
-
version: "1.0.0"
|
|
20
|
-
},
|
|
21
|
-
paths: {}
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
plugins: [readFiles(), fetchUrls()]
|
|
25
|
-
}
|
|
26
|
-
);
|
|
27
|
-
expect(getEntrypoint(filesystem).specification).toMatchObject({
|
|
28
|
-
openapi: "3.1.0",
|
|
29
|
-
info: {
|
|
30
|
-
title: "Hello World",
|
|
31
|
-
version: "1.0.0"
|
|
32
|
-
},
|
|
33
|
-
paths: {}
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
it("loads JSON string", async () => {
|
|
37
|
-
const { filesystem } = await load(
|
|
38
|
-
JSON.stringify({
|
|
39
|
-
openapi: "3.1.0",
|
|
40
|
-
info: {
|
|
41
|
-
title: "Hello World",
|
|
42
|
-
version: "1.0.0"
|
|
43
|
-
},
|
|
44
|
-
paths: {}
|
|
45
|
-
}),
|
|
46
|
-
{
|
|
47
|
-
plugins: [readFiles(), fetchUrls()]
|
|
48
|
-
}
|
|
49
|
-
);
|
|
50
|
-
expect(getEntrypoint(filesystem).specification).toMatchObject({
|
|
51
|
-
openapi: "3.1.0",
|
|
52
|
-
info: {
|
|
53
|
-
title: "Hello World",
|
|
54
|
-
version: "1.0.0"
|
|
55
|
-
},
|
|
56
|
-
paths: {}
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
it("loads YAML string", async () => {
|
|
60
|
-
const { filesystem } = await load(
|
|
61
|
-
stringify({
|
|
62
|
-
openapi: "3.1.0",
|
|
63
|
-
info: {
|
|
64
|
-
title: "Hello World",
|
|
65
|
-
version: "1.0.0"
|
|
66
|
-
},
|
|
67
|
-
paths: {}
|
|
68
|
-
}),
|
|
69
|
-
{
|
|
70
|
-
plugins: [readFiles(), fetchUrls()]
|
|
71
|
-
}
|
|
72
|
-
);
|
|
73
|
-
expect(getEntrypoint(filesystem).specification).toMatchObject({
|
|
74
|
-
openapi: "3.1.0",
|
|
75
|
-
info: {
|
|
76
|
-
title: "Hello World",
|
|
77
|
-
version: "1.0.0"
|
|
78
|
-
},
|
|
79
|
-
paths: {}
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
it("loads file", async () => {
|
|
83
|
-
const EXAMPLE_FILE = path.join(new URL(import.meta.url).pathname, "../../examples/openapi.yaml");
|
|
84
|
-
const { filesystem } = await load(EXAMPLE_FILE, {
|
|
85
|
-
plugins: [readFiles(), fetchUrls()]
|
|
86
|
-
});
|
|
87
|
-
expect(getEntrypoint(filesystem).specification).toMatchObject({
|
|
88
|
-
openapi: "3.1.0",
|
|
89
|
-
info: {
|
|
90
|
-
title: "Hello World",
|
|
91
|
-
version: "1.0.0"
|
|
92
|
-
},
|
|
93
|
-
paths: {}
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
it("loads referenced files in files", async () => {
|
|
97
|
-
const EXAMPLE_FILE = path.join(new URL(import.meta.url).pathname, "../../../../tests/filesystem/api/openapi.yaml");
|
|
98
|
-
const { filesystem } = await load(EXAMPLE_FILE, {
|
|
99
|
-
plugins: [readFiles()]
|
|
100
|
-
});
|
|
101
|
-
expect(filesystem.map((entry) => entry.filename)).toStrictEqual([
|
|
102
|
-
null,
|
|
103
|
-
"schemas/problem.yaml",
|
|
104
|
-
"schemas/upload.yaml",
|
|
105
|
-
"./components/coordinates.yaml"
|
|
106
|
-
]);
|
|
107
|
-
expect(filesystem[0].specification).toBeTypeOf("object");
|
|
108
|
-
expect(filesystem.filter((entry) => entry.isEntrypoint).length).toBe(1);
|
|
109
|
-
});
|
|
110
|
-
it("loads url", async () => {
|
|
111
|
-
fetch.mockResolvedValue({
|
|
112
|
-
text: async () => stringify({
|
|
113
|
-
openapi: "3.1.0",
|
|
114
|
-
info: {
|
|
115
|
-
title: "Hello World",
|
|
116
|
-
version: "1.0.0"
|
|
117
|
-
},
|
|
118
|
-
paths: {}
|
|
119
|
-
})
|
|
120
|
-
});
|
|
121
|
-
const { filesystem } = await load("https://example.com/openapi.yaml", {
|
|
122
|
-
plugins: [readFiles(), fetchUrls()]
|
|
123
|
-
});
|
|
124
|
-
expect(getEntrypoint(filesystem).specification).toMatchObject({
|
|
125
|
-
openapi: "3.1.0",
|
|
126
|
-
info: {
|
|
127
|
-
title: "Hello World",
|
|
128
|
-
version: "1.0.0"
|
|
129
|
-
},
|
|
130
|
-
paths: {}
|
|
131
|
-
});
|
|
132
|
-
});
|
|
133
|
-
it("handles failed requests", async () => {
|
|
134
|
-
fetch.mockImplementation(() => {
|
|
135
|
-
throw new TypeError("[load.test.ts] fetch failed");
|
|
136
|
-
});
|
|
137
|
-
const { filesystem } = await load(
|
|
138
|
-
{
|
|
139
|
-
openapi: "3.1.0",
|
|
140
|
-
info: {
|
|
141
|
-
title: "Hello World",
|
|
142
|
-
version: "1.0.0"
|
|
143
|
-
},
|
|
144
|
-
paths: {
|
|
145
|
-
"/foobar": {
|
|
146
|
-
post: {
|
|
147
|
-
requestBody: {
|
|
148
|
-
content: {
|
|
149
|
-
"application/json": {
|
|
150
|
-
schema: {
|
|
151
|
-
$ref: "https://DOES_NOT_EXIST"
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
},
|
|
160
|
-
{
|
|
161
|
-
plugins: [readFiles(), fetchUrls()]
|
|
162
|
-
}
|
|
163
|
-
);
|
|
164
|
-
expect(getEntrypoint(filesystem).specification).toMatchObject({
|
|
165
|
-
openapi: "3.1.0",
|
|
166
|
-
info: {
|
|
167
|
-
title: "Hello World",
|
|
168
|
-
version: "1.0.0"
|
|
169
|
-
},
|
|
170
|
-
paths: {}
|
|
171
|
-
});
|
|
172
|
-
});
|
|
173
|
-
it("limits the number of requests", async () => {
|
|
174
|
-
fetch.mockResolvedValue({
|
|
175
|
-
text: async () => "FOOBAR"
|
|
176
|
-
});
|
|
177
|
-
const { filesystem } = await load(
|
|
178
|
-
{
|
|
179
|
-
openapi: "3.1.0",
|
|
180
|
-
info: {
|
|
181
|
-
title: "Hello World",
|
|
182
|
-
version: "1.0.0"
|
|
183
|
-
},
|
|
184
|
-
paths: {
|
|
185
|
-
"/foobar": {
|
|
186
|
-
post: {
|
|
187
|
-
requestBody: {
|
|
188
|
-
content: {
|
|
189
|
-
"application/json": {
|
|
190
|
-
schema: {
|
|
191
|
-
$ref: "https://DOES_NOT_EXIST"
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
},
|
|
200
|
-
{
|
|
201
|
-
plugins: [
|
|
202
|
-
fetchUrls({
|
|
203
|
-
limit: 0
|
|
204
|
-
})
|
|
205
|
-
]
|
|
206
|
-
}
|
|
207
|
-
);
|
|
208
|
-
expect(filesystem.length).toBe(1);
|
|
209
|
-
});
|
|
210
|
-
it("loads referenced urls", async () => {
|
|
211
|
-
fetch.mockImplementation((url) => {
|
|
212
|
-
if (url === "https://example.com/openapi.yaml") {
|
|
213
|
-
return Promise.resolve({
|
|
214
|
-
text: () => Promise.resolve(
|
|
215
|
-
stringify({
|
|
216
|
-
openapi: "3.1.0",
|
|
217
|
-
info: {
|
|
218
|
-
title: "Hello World",
|
|
219
|
-
version: "1.0.0"
|
|
220
|
-
},
|
|
221
|
-
paths: {
|
|
222
|
-
"/foobar": {
|
|
223
|
-
post: {
|
|
224
|
-
requestBody: {
|
|
225
|
-
$ref: "https://example.com/foobar.json"
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
})
|
|
231
|
-
)
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
if (url === "https://example.com/foobar.json") {
|
|
235
|
-
return {
|
|
236
|
-
text: async () => JSON.stringify({
|
|
237
|
-
content: {
|
|
238
|
-
"application/json": {
|
|
239
|
-
schema: {
|
|
240
|
-
type: "string",
|
|
241
|
-
example: "foobar"
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
})
|
|
246
|
-
};
|
|
247
|
-
}
|
|
248
|
-
});
|
|
249
|
-
const { filesystem } = await load("https://example.com/openapi.yaml", {
|
|
250
|
-
plugins: [readFiles(), fetchUrls()]
|
|
251
|
-
});
|
|
252
|
-
expect(filesystem[0].specification).toMatchObject({
|
|
253
|
-
openapi: "3.1.0",
|
|
254
|
-
info: {
|
|
255
|
-
title: "Hello World",
|
|
256
|
-
version: "1.0.0"
|
|
257
|
-
},
|
|
258
|
-
paths: {
|
|
259
|
-
"/foobar": {
|
|
260
|
-
post: {
|
|
261
|
-
requestBody: {
|
|
262
|
-
$ref: "https://example.com/foobar.json"
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
});
|
|
268
|
-
expect(filesystem[1].specification).toMatchObject({
|
|
269
|
-
content: {
|
|
270
|
-
"application/json": {
|
|
271
|
-
schema: {
|
|
272
|
-
type: "string",
|
|
273
|
-
example: "foobar"
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
});
|
|
278
|
-
});
|
|
279
|
-
it("loads string with url reference", async () => {
|
|
280
|
-
fetch.mockResolvedValue({
|
|
281
|
-
text: async () => JSON.stringify({
|
|
282
|
-
content: {
|
|
283
|
-
"application/json": {
|
|
284
|
-
schema: {
|
|
285
|
-
type: "string",
|
|
286
|
-
example: "foobar"
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
})
|
|
291
|
-
});
|
|
292
|
-
const { filesystem } = await load(
|
|
293
|
-
stringify({
|
|
294
|
-
openapi: "3.1.0",
|
|
295
|
-
info: {
|
|
296
|
-
title: "Hello World",
|
|
297
|
-
version: "1.0.0"
|
|
298
|
-
},
|
|
299
|
-
paths: {
|
|
300
|
-
"/foobar": {
|
|
301
|
-
post: {
|
|
302
|
-
requestBody: {
|
|
303
|
-
$ref: "https://example.com/foobar.json"
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
}),
|
|
309
|
-
{
|
|
310
|
-
plugins: [readFiles(), fetchUrls()]
|
|
311
|
-
}
|
|
312
|
-
);
|
|
313
|
-
expect(filesystem.map((entry) => entry.filename)).toStrictEqual([null, "https://example.com/foobar.json"]);
|
|
314
|
-
expect(filesystem[0].specification).toMatchObject({
|
|
315
|
-
openapi: "3.1.0",
|
|
316
|
-
info: {
|
|
317
|
-
title: "Hello World",
|
|
318
|
-
version: "1.0.0"
|
|
319
|
-
},
|
|
320
|
-
paths: {
|
|
321
|
-
"/foobar": {
|
|
322
|
-
post: {
|
|
323
|
-
requestBody: {
|
|
324
|
-
$ref: "https://example.com/foobar.json"
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
});
|
|
330
|
-
expect(filesystem[1].specification).toMatchObject({
|
|
331
|
-
content: {
|
|
332
|
-
"application/json": {
|
|
333
|
-
schema: {
|
|
334
|
-
type: "string",
|
|
335
|
-
example: "foobar"
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
});
|
|
340
|
-
});
|
|
341
|
-
it("returns an error", async () => {
|
|
342
|
-
const { errors } = await load("INVALID", {
|
|
343
|
-
plugins: [readFiles(), fetchUrls()]
|
|
344
|
-
});
|
|
345
|
-
expect(errors).toMatchObject([
|
|
346
|
-
{
|
|
347
|
-
code: "EXTERNAL_REFERENCE_NOT_FOUND",
|
|
348
|
-
message: "Can\u2019t resolve external reference: INVALID"
|
|
349
|
-
}
|
|
350
|
-
]);
|
|
351
|
-
});
|
|
352
|
-
it("throws an error", async () => {
|
|
353
|
-
expect(async () => {
|
|
354
|
-
await load("INVALID", {
|
|
355
|
-
plugins: [readFiles(), fetchUrls()],
|
|
356
|
-
throwOnError: true
|
|
357
|
-
});
|
|
358
|
-
}).rejects.toThrowError("Can\u2019t resolve external reference: INVALID");
|
|
359
|
-
});
|
|
360
|
-
});
|
|
361
|
-
//# sourceMappingURL=load.test.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/utils/load/load.test.ts"],
|
|
4
|
-
"sourcesContent": ["import path from 'node:path'\nimport { beforeEach, describe, expect, it, vi } from 'vitest'\nimport { stringify } from 'yaml'\n\nimport { fetchUrls } from '@/plugins/fetch-urls/fetch-urls'\nimport { readFiles } from '@/plugins/read-files/read-files'\nimport { getEntrypoint } from '@/utils/get-entrypoint'\nimport { load } from './load'\n\nglobal.fetch = vi.fn()\n\ndescribe('load', async () => {\n beforeEach(() => {\n // @ts-expect-error\n global.fetch.mockReset()\n })\n\n it('loads JS object', async () => {\n const { filesystem } = await load(\n {\n openapi: '3.1.0',\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n paths: {},\n },\n {\n plugins: [readFiles(), fetchUrls()],\n },\n )\n\n expect(getEntrypoint(filesystem).specification).toMatchObject({\n openapi: '3.1.0',\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n paths: {},\n })\n })\n\n it('loads JSON string', async () => {\n const { filesystem } = await load(\n JSON.stringify({\n openapi: '3.1.0',\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n paths: {},\n }),\n {\n plugins: [readFiles(), fetchUrls()],\n },\n )\n\n expect(getEntrypoint(filesystem).specification).toMatchObject({\n openapi: '3.1.0',\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n paths: {},\n })\n })\n\n it('loads YAML string', async () => {\n const { filesystem } = await load(\n stringify({\n openapi: '3.1.0',\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n paths: {},\n }),\n {\n plugins: [readFiles(), fetchUrls()],\n },\n )\n\n expect(getEntrypoint(filesystem).specification).toMatchObject({\n openapi: '3.1.0',\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n paths: {},\n })\n })\n\n it('loads file', async () => {\n const EXAMPLE_FILE = path.join(new URL(import.meta.url).pathname, '../../examples/openapi.yaml')\n\n const { filesystem } = await load(EXAMPLE_FILE, {\n plugins: [readFiles(), fetchUrls()],\n })\n\n expect(getEntrypoint(filesystem).specification).toMatchObject({\n openapi: '3.1.0',\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n paths: {},\n })\n })\n\n it('loads referenced files in files', async () => {\n const EXAMPLE_FILE = path.join(new URL(import.meta.url).pathname, '../../../../tests/filesystem/api/openapi.yaml')\n\n const { filesystem } = await load(EXAMPLE_FILE, {\n plugins: [readFiles()],\n })\n\n // filenames\n expect(filesystem.map((entry) => entry.filename)).toStrictEqual([\n null,\n 'schemas/problem.yaml',\n 'schemas/upload.yaml',\n './components/coordinates.yaml',\n ])\n\n // specification\n expect(filesystem[0].specification).toBeTypeOf('object')\n\n // only one entrypoint\n expect(filesystem.filter((entry) => entry.isEntrypoint).length).toBe(1)\n })\n\n it('loads url', async () => {\n // @ts-expect-error\n fetch.mockResolvedValue({\n text: async () =>\n stringify({\n openapi: '3.1.0',\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n paths: {},\n }),\n })\n\n const { filesystem } = await load('https://example.com/openapi.yaml', {\n plugins: [readFiles(), fetchUrls()],\n })\n\n expect(getEntrypoint(filesystem).specification).toMatchObject({\n openapi: '3.1.0',\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n paths: {},\n })\n })\n\n it('handles failed requests', async () => {\n // Failed request\n // @ts-expect-error\n fetch.mockImplementation(() => {\n throw new TypeError('[load.test.ts] fetch failed')\n })\n\n const { filesystem } = await load(\n {\n openapi: '3.1.0',\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n paths: {\n '/foobar': {\n post: {\n requestBody: {\n content: {\n 'application/json': {\n schema: {\n $ref: 'https://DOES_NOT_EXIST',\n },\n },\n },\n },\n },\n },\n },\n },\n {\n plugins: [readFiles(), fetchUrls()],\n },\n )\n\n expect(getEntrypoint(filesystem).specification).toMatchObject({\n openapi: '3.1.0',\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n paths: {},\n })\n })\n\n it('limits the number of requests', async () => {\n // @ts-expect-error\n fetch.mockResolvedValue({\n text: async () => 'FOOBAR',\n })\n\n const { filesystem } = await load(\n {\n openapi: '3.1.0',\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n paths: {\n '/foobar': {\n post: {\n requestBody: {\n content: {\n 'application/json': {\n schema: {\n $ref: 'https://DOES_NOT_EXIST',\n },\n },\n },\n },\n },\n },\n },\n },\n {\n plugins: [\n fetchUrls({\n limit: 0,\n }),\n ],\n },\n )\n\n expect(filesystem.length).toBe(1)\n })\n\n it('loads referenced urls', async () => {\n // @ts-expect-error\n fetch.mockImplementation((url: string) => {\n if (url === 'https://example.com/openapi.yaml') {\n return Promise.resolve({\n text: () =>\n Promise.resolve(\n stringify({\n openapi: '3.1.0',\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n paths: {\n '/foobar': {\n post: {\n requestBody: {\n $ref: 'https://example.com/foobar.json',\n },\n },\n },\n },\n }),\n ),\n } as Response)\n }\n\n if (url === 'https://example.com/foobar.json') {\n return {\n text: async () =>\n JSON.stringify({\n content: {\n 'application/json': {\n schema: {\n type: 'string',\n example: 'foobar',\n },\n },\n },\n }),\n } as Response\n }\n })\n\n const { filesystem } = await load('https://example.com/openapi.yaml', {\n plugins: [readFiles(), fetchUrls()],\n })\n\n expect(filesystem[0].specification).toMatchObject({\n openapi: '3.1.0',\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n paths: {\n '/foobar': {\n post: {\n requestBody: {\n $ref: 'https://example.com/foobar.json',\n },\n },\n },\n },\n })\n\n expect(filesystem[1].specification).toMatchObject({\n content: {\n 'application/json': {\n schema: {\n type: 'string',\n example: 'foobar',\n },\n },\n },\n })\n })\n\n it('loads string with url reference', async () => {\n // @ts-expect-error\n fetch.mockResolvedValue({\n text: async () =>\n JSON.stringify({\n content: {\n 'application/json': {\n schema: {\n type: 'string',\n example: 'foobar',\n },\n },\n },\n }),\n })\n\n const { filesystem } = await load(\n stringify({\n openapi: '3.1.0',\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n paths: {\n '/foobar': {\n post: {\n requestBody: {\n $ref: 'https://example.com/foobar.json',\n },\n },\n },\n },\n }),\n {\n plugins: [readFiles(), fetchUrls()],\n },\n )\n\n expect(filesystem.map((entry) => entry.filename)).toStrictEqual([null, 'https://example.com/foobar.json'])\n\n expect(filesystem[0].specification).toMatchObject({\n openapi: '3.1.0',\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n paths: {\n '/foobar': {\n post: {\n requestBody: {\n $ref: 'https://example.com/foobar.json',\n },\n },\n },\n },\n })\n\n expect(filesystem[1].specification).toMatchObject({\n content: {\n 'application/json': {\n schema: {\n type: 'string',\n example: 'foobar',\n },\n },\n },\n })\n })\n\n it('returns an error', async () => {\n const { errors } = await load('INVALID', {\n plugins: [readFiles(), fetchUrls()],\n })\n\n expect(errors).toMatchObject([\n {\n code: 'EXTERNAL_REFERENCE_NOT_FOUND',\n message: 'Can\u2019t resolve external reference: INVALID',\n },\n ])\n })\n\n it('throws an error', async () => {\n expect(async () => {\n await load('INVALID', {\n plugins: [readFiles(), fetchUrls()],\n throwOnError: true,\n })\n }).rejects.toThrowError('Can\u2019t resolve external reference: INVALID')\n })\n})\n"],
|
|
5
|
-
"mappings": "AAAA,OAAO,UAAU;AACjB,SAAS,YAAY,UAAU,QAAQ,IAAI,UAAU;AACrD,SAAS,iBAAiB;AAE1B,SAAS,iBAAiB;AAC1B,SAAS,iBAAiB;AAC1B,SAAS,qBAAqB;AAC9B,SAAS,YAAY;AAErB,OAAO,QAAQ,GAAG,GAAG;AAErB,SAAS,QAAQ,YAAY;AAC3B,aAAW,MAAM;AAEf,WAAO,MAAM,UAAU;AAAA,EACzB,CAAC;AAED,KAAG,mBAAmB,YAAY;AAChC,UAAM,EAAE,WAAW,IAAI,MAAM;AAAA,MAC3B;AAAA,QACE,SAAS;AAAA,QACT,MAAM;AAAA,UACJ,OAAO;AAAA,UACP,SAAS;AAAA,QACX;AAAA,QACA,OAAO,CAAC;AAA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X,MAAM;AAAA,YACR;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF,CAAC;AAED,WAAO,WAAW,CAAC,EAAE,aAAa,EAAE,cAAc;AAAA,MAChD,SAAS;AAAA,QACP,oBAAoB;AAAA,UAClB,QAAQ;AAAA,YACN,MAAM;AAAA,YACN,SAAS;AAAA,UACX;AAAA,QACF;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AAED,KAAG,oBAAoB,YAAY;AACjC,UAAM,EAAE,OAAO,IAAI,MAAM,KAAK,WAAW;AAAA,MACvC,SAAS,CAAC,UAAU,GAAG,UAAU,CAAC;AAAA,IACpC,CAAC;AAED,WAAO,MAAM,EAAE,cAAc;AAAA,MAC3B;AAAA,QACE,MAAM;AAAA,QACN,SAAS;AAAA,MACX;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AAED,KAAG,mBAAmB,YAAY;AAChC,WAAO,YAAY;AACjB,YAAM,KAAK,WAAW;AAAA,QACpB,SAAS,CAAC,UAAU,GAAG,UAAU,CAAC;AAAA,QAClC,cAAc;AAAA,MAChB,CAAC;AAAA,IACH,CAAC,EAAE,QAAQ,aAAa,gDAA2C;AAAA,EACrE,CAAC;AACH,CAAC;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { normalize } from "./normalize.js";
|
|
3
|
-
describe("normalize", () => {
|
|
4
|
-
it("should return an empty object if the specification is null", () => {
|
|
5
|
-
expect(normalize(null)).toEqual({});
|
|
6
|
-
});
|
|
7
|
-
it("should return the same filesystem if the specification is already a filesystem", () => {
|
|
8
|
-
const filesystem = [
|
|
9
|
-
{
|
|
10
|
-
isEntrypoint: true,
|
|
11
|
-
specification: {},
|
|
12
|
-
filename: null,
|
|
13
|
-
dir: "./",
|
|
14
|
-
references: []
|
|
15
|
-
}
|
|
16
|
-
];
|
|
17
|
-
expect(normalize(filesystem)).toBe(filesystem);
|
|
18
|
-
});
|
|
19
|
-
it("should parse JSON string specifications", () => {
|
|
20
|
-
const jsonString = '{"foo": "bar"}';
|
|
21
|
-
expect(normalize(jsonString)).toEqual({ foo: "bar" });
|
|
22
|
-
});
|
|
23
|
-
it("should parse YAML string specifications", () => {
|
|
24
|
-
const yamlString = "foo: bar";
|
|
25
|
-
expect(normalize(yamlString)).toEqual({ foo: "bar" });
|
|
26
|
-
});
|
|
27
|
-
it("should handle invalid YAML with custom maxAliasCount", () => {
|
|
28
|
-
const yamlString = `
|
|
29
|
-
aliases: &ref
|
|
30
|
-
- item1
|
|
31
|
-
- item2
|
|
32
|
-
items: *ref
|
|
33
|
-
`;
|
|
34
|
-
expect(() => normalize(yamlString)).not.toThrow();
|
|
35
|
-
});
|
|
36
|
-
it("should return the same object if specification is already an object", () => {
|
|
37
|
-
const obj = { foo: "bar" };
|
|
38
|
-
expect(normalize(obj)).toBe(obj);
|
|
39
|
-
});
|
|
40
|
-
it("should handle malformed JSON strings by falling back to YAML parsing", () => {
|
|
41
|
-
const malformedJson = '{ foo: "bar" }';
|
|
42
|
-
expect(normalize(malformedJson)).toEqual({ foo: "bar" });
|
|
43
|
-
});
|
|
44
|
-
it("should handle empty string input", () => {
|
|
45
|
-
expect(normalize("")).toEqual({});
|
|
46
|
-
});
|
|
47
|
-
it("should handle whitespace-only string input", () => {
|
|
48
|
-
expect(normalize(" ")).toEqual({});
|
|
49
|
-
});
|
|
50
|
-
it("should handle complex nested structures", () => {
|
|
51
|
-
const complex = {
|
|
52
|
-
nested: {
|
|
53
|
-
array: [1, 2, 3],
|
|
54
|
-
object: {
|
|
55
|
-
foo: "bar"
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
expect(normalize(complex)).toEqual(complex);
|
|
60
|
-
});
|
|
61
|
-
it("should handle invalid JSON and YAML strings gracefully", () => {
|
|
62
|
-
const invalidString = "not a valid json or yaml";
|
|
63
|
-
expect(() => normalize(invalidString)).not.toThrow();
|
|
64
|
-
});
|
|
65
|
-
it("should handle non-string, non-object inputs", () => {
|
|
66
|
-
expect(normalize(42)).toEqual(42);
|
|
67
|
-
expect(normalize(true)).toEqual(true);
|
|
68
|
-
expect(normalize([1, 2, 3])).toEqual([1, 2, 3]);
|
|
69
|
-
});
|
|
70
|
-
it("should handle deeply nested structures", () => {
|
|
71
|
-
const nested = { a: { b: { c: { d: { e: "deep" } } } } };
|
|
72
|
-
expect(normalize(nested)).toEqual(nested);
|
|
73
|
-
});
|
|
74
|
-
it("should handle large input strings", () => {
|
|
75
|
-
const largeJson = JSON.stringify({ foo: "bar".repeat(1e4) });
|
|
76
|
-
expect(normalize(largeJson)).toEqual({ foo: "bar".repeat(1e4) });
|
|
77
|
-
});
|
|
78
|
-
it("should handle circular references", () => {
|
|
79
|
-
const circularObj = {};
|
|
80
|
-
circularObj.self = circularObj;
|
|
81
|
-
expect(() => normalize(circularObj)).not.toThrow();
|
|
82
|
-
});
|
|
83
|
-
it("should handle special characters in strings", () => {
|
|
84
|
-
const specialCharJson = '{"foo": "bar\\n"}';
|
|
85
|
-
expect(normalize(specialCharJson)).toEqual({ foo: "bar\n" });
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
//# sourceMappingURL=normalize.test.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/utils/normalize.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { describe, expect, it } from 'vitest'\n\nimport { normalize } from './normalize'\n\ndescribe('normalize', () => {\n it('should return an empty object if the specification is null', () => {\n expect(normalize(null)).toEqual({})\n })\n\n it('should return the same filesystem if the specification is already a filesystem', () => {\n const filesystem = [\n {\n isEntrypoint: true,\n specification: {},\n filename: null,\n dir: './',\n references: [],\n },\n ]\n expect(normalize(filesystem)).toBe(filesystem)\n })\n\n it('should parse JSON string specifications', () => {\n const jsonString = '{\"foo\": \"bar\"}'\n expect(normalize(jsonString)).toEqual({ foo: 'bar' })\n })\n\n it('should parse YAML string specifications', () => {\n const yamlString = 'foo: bar'\n expect(normalize(yamlString)).toEqual({ foo: 'bar' })\n })\n\n it('should handle invalid YAML with custom maxAliasCount', () => {\n const yamlString = `\n aliases: &ref\n - item1\n - item2\n items: *ref\n `\n expect(() => normalize(yamlString)).not.toThrow()\n })\n\n it('should return the same object if specification is already an object', () => {\n const obj = { foo: 'bar' }\n expect(normalize(obj)).toBe(obj)\n })\n\n it('should handle malformed JSON strings by falling back to YAML parsing', () => {\n const malformedJson = '{ foo: \"bar\" }' // Missing quotes around property name\n expect(normalize(malformedJson)).toEqual({ foo: 'bar' })\n })\n\n it('should handle empty string input', () => {\n expect(normalize('')).toEqual({})\n })\n\n it('should handle whitespace-only string input', () => {\n expect(normalize(' ')).toEqual({})\n })\n\n it('should handle complex nested structures', () => {\n const complex = {\n nested: {\n array: [1, 2, 3],\n object: {\n foo: 'bar',\n },\n },\n }\n expect(normalize(complex)).toEqual(complex)\n })\n\n it('should handle invalid JSON and YAML strings gracefully', () => {\n const invalidString = 'not a valid json or yaml'\n expect(() => normalize(invalidString)).not.toThrow()\n })\n\n it('should handle non-string, non-object inputs', () => {\n // @ts-expect-error testing bad input\n expect(normalize(42)).toEqual(42)\n // @ts-expect-error testing bad input\n expect(normalize(true)).toEqual(true)\n // @ts-expect-error testing bad input\n expect(normalize([1, 2, 3])).toEqual([1, 2, 3])\n })\n\n it('should handle deeply nested structures', () => {\n const nested = { a: { b: { c: { d: { e: 'deep' } } } } }\n expect(normalize(nested)).toEqual(nested)\n })\n\n it('should handle large input strings', () => {\n const largeJson = JSON.stringify({ foo: 'bar'.repeat(10000) })\n expect(normalize(largeJson)).toEqual({ foo: 'bar'.repeat(10000) })\n })\n\n it('should handle circular references', () => {\n const circularObj: any = {}\n circularObj.self = circularObj\n expect(() => normalize(circularObj)).not.toThrow()\n })\n\n it('should handle special characters in strings', () => {\n const specialCharJson = '{\"foo\": \"bar\\\\n\"}'\n expect(normal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