@scalar/openapi-parser 0.13.0 → 0.15.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.
Files changed (89) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/README.md +157 -0
  3. package/dist/index.d.ts +2 -0
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.js +4 -0
  6. package/dist/index.js.map +2 -2
  7. package/dist/types/index.d.ts +1 -0
  8. package/dist/types/index.d.ts.map +1 -1
  9. package/dist/utils/bundle/bundle.d.ts +279 -0
  10. package/dist/utils/bundle/bundle.d.ts.map +1 -0
  11. package/dist/utils/bundle/bundle.js +215 -0
  12. package/dist/utils/bundle/bundle.js.map +7 -0
  13. package/dist/utils/bundle/create-limiter.d.ts +21 -0
  14. package/dist/utils/bundle/create-limiter.d.ts.map +1 -0
  15. package/dist/utils/bundle/create-limiter.js +31 -0
  16. package/dist/utils/bundle/create-limiter.js.map +7 -0
  17. package/dist/utils/bundle/index.d.ts +4 -0
  18. package/dist/utils/bundle/index.d.ts.map +1 -0
  19. package/dist/utils/bundle/index.js +9 -0
  20. package/dist/utils/bundle/index.js.map +7 -0
  21. package/dist/utils/bundle/plugins/fetch-urls/index.d.ts +39 -0
  22. package/dist/utils/bundle/plugins/fetch-urls/index.d.ts.map +1 -0
  23. package/dist/utils/bundle/plugins/fetch-urls/index.js +41 -0
  24. package/dist/utils/bundle/plugins/fetch-urls/index.js.map +7 -0
  25. package/dist/utils/bundle/plugins/read-files/index.d.ts +29 -0
  26. package/dist/utils/bundle/plugins/read-files/index.d.ts.map +1 -0
  27. package/dist/utils/bundle/plugins/read-files/index.js +30 -0
  28. package/dist/utils/bundle/plugins/read-files/index.js.map +7 -0
  29. package/dist/utils/normalize.js +2 -2
  30. package/dist/utils/normalize.js.map +2 -2
  31. package/dist/utils/openapi/actions/details.d.ts +7 -0
  32. package/dist/utils/openapi/actions/details.d.ts.map +1 -0
  33. package/dist/utils/openapi/actions/details.js +11 -0
  34. package/dist/utils/openapi/actions/details.js.map +7 -0
  35. package/dist/utils/openapi/actions/files.d.ts +6 -0
  36. package/dist/utils/openapi/actions/files.d.ts.map +1 -0
  37. package/dist/utils/openapi/actions/files.js +9 -0
  38. package/dist/utils/openapi/actions/files.js.map +7 -0
  39. package/dist/utils/openapi/actions/get.d.ts +6 -0
  40. package/dist/utils/openapi/actions/get.d.ts.map +1 -0
  41. package/dist/utils/openapi/actions/get.js +11 -0
  42. package/dist/utils/openapi/actions/get.js.map +7 -0
  43. package/dist/utils/openapi/actions/toJson.d.ts +6 -0
  44. package/dist/utils/openapi/actions/toJson.d.ts.map +1 -0
  45. package/dist/utils/openapi/actions/toJson.js +11 -0
  46. package/dist/utils/openapi/actions/toJson.js.map +7 -0
  47. package/dist/utils/openapi/actions/toYaml.d.ts +6 -0
  48. package/dist/utils/openapi/actions/toYaml.d.ts.map +1 -0
  49. package/dist/utils/openapi/actions/toYaml.js +11 -0
  50. package/dist/utils/openapi/actions/toYaml.js.map +7 -0
  51. package/dist/utils/openapi/commands/dereferenceCommand.d.ts +27 -0
  52. package/dist/utils/openapi/commands/dereferenceCommand.d.ts.map +1 -0
  53. package/dist/utils/openapi/commands/dereferenceCommand.js +27 -0
  54. package/dist/utils/openapi/commands/dereferenceCommand.js.map +7 -0
  55. package/dist/utils/openapi/commands/filterCommand.d.ts +41 -0
  56. package/dist/utils/openapi/commands/filterCommand.d.ts.map +1 -0
  57. package/dist/utils/openapi/commands/filterCommand.js +26 -0
  58. package/dist/utils/openapi/commands/filterCommand.js.map +7 -0
  59. package/dist/utils/openapi/commands/loadCommand.d.ts +8321 -0
  60. package/dist/utils/openapi/commands/loadCommand.d.ts.map +1 -0
  61. package/dist/utils/openapi/commands/loadCommand.js +42 -0
  62. package/dist/utils/openapi/commands/loadCommand.js.map +7 -0
  63. package/dist/utils/openapi/commands/upgradeCommand.d.ts +3406 -0
  64. package/dist/utils/openapi/commands/upgradeCommand.d.ts.map +1 -0
  65. package/dist/utils/openapi/commands/upgradeCommand.js +29 -0
  66. package/dist/utils/openapi/commands/upgradeCommand.js.map +7 -0
  67. package/dist/utils/openapi/commands/validateCommand.d.ts +3451 -0
  68. package/dist/utils/openapi/commands/validateCommand.d.ts.map +1 -0
  69. package/dist/utils/openapi/commands/validateCommand.js +33 -0
  70. package/dist/utils/openapi/commands/validateCommand.js.map +7 -0
  71. package/dist/utils/openapi/openapi.d.ts +1272 -0
  72. package/dist/utils/openapi/openapi.d.ts.map +1 -0
  73. package/dist/utils/openapi/openapi.js +15 -0
  74. package/dist/utils/openapi/openapi.js.map +7 -0
  75. package/dist/utils/openapi/openapi.test-d.d.ts +2 -0
  76. package/dist/utils/openapi/openapi.test-d.d.ts.map +1 -0
  77. package/dist/utils/openapi/openapi.test-d.js +14 -0
  78. package/dist/utils/openapi/openapi.test-d.js.map +7 -0
  79. package/dist/utils/openapi/utils/queueTask.d.ts +6 -0
  80. package/dist/utils/openapi/utils/queueTask.d.ts.map +1 -0
  81. package/dist/utils/openapi/utils/queueTask.js +10 -0
  82. package/dist/utils/openapi/utils/queueTask.js.map +7 -0
  83. package/dist/utils/openapi/utils/workThroughQueue.d.ts +6 -0
  84. package/dist/utils/openapi/utils/workThroughQueue.d.ts.map +1 -0
  85. package/dist/utils/openapi/utils/workThroughQueue.js +52 -0
  86. package/dist/utils/openapi/utils/workThroughQueue.js.map +7 -0
  87. package/dist/utils/upgrade-from-two-to-three.js +45 -1
  88. package/dist/utils/upgrade-from-two-to-three.js.map +2 -2
  89. package/package.json +16 -6
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openapi.d.ts","sourceRoot":"","sources":["../../../src/utils/openapi/openapi.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,cAAc,EAAS,MAAM,eAAe,CAAA;AAClF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAGpD;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,aAAa,CAAC,EAAE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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAE9D"}
@@ -0,0 +1,15 @@
1
+ import { loadCommand } from "./commands/loadCommand.js";
2
+ function openapi(globalOptions) {
3
+ const queue = {
4
+ input: null,
5
+ options: globalOptions,
6
+ tasks: []
7
+ };
8
+ return {
9
+ load: (input, options) => loadCommand(queue, input, options)
10
+ };
11
+ }
12
+ export {
13
+ openapi
14
+ };
15
+ //# sourceMappingURL=openapi.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/utils/openapi/openapi.ts"],
4
+ "sourcesContent": ["import type { AnyApiDefinitionFormat, OpenApiOptions, Queue } from '@/types/index'\nimport type { LoadOptions } from '@/utils/load/load'\nimport { loadCommand } from './commands/loadCommand'\n\n/**\n * Creates a fluent OpenAPI pipeline\n *\n * @deprecated We are about to drop the pipeline syntax. Use the individual utilities instead.\n */\nexport function openapi(globalOptions?: OpenApiOptions) {\n // Create a new queue\n const queue = {\n input: null,\n options: globalOptions,\n tasks: [],\n } as Queue<[]>\n\n return {\n load: (input: AnyApiDefinitionFormat, options?: LoadOptions) => loadCommand(queue, input, options),\n }\n}\n"],
5
+ "mappings": "AAEA,SAAS,mBAAmB;AAOrB,SAAS,QAAQ,eAAgC;AAEtD,QAAM,QAAQ;AAAA,IACZ,OAAO;AAAA,IACP,SAAS;AAAA,IACT,OAAO,CAAC;AAAA,EACV;AAEA,SAAO;AAAA,IACL,MAAM,CAAC,OAA+B,YAA0B,YAAY,OAAO,OAAO,OAAO;AAAA,EACnG;AACF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=openapi.test-d.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openapi.test-d.d.ts","sourceRoot":"","sources":["../../../src/utils/openapi/openapi.test-d.ts"],"names":[],"mappings":""}
@@ -0,0 +1,14 @@
1
+ import { describe, expectTypeOf, it } from "vitest";
2
+ import { openapi } from "./openapi.js";
3
+ describe("openapi", () => {
4
+ it("returns the correct type for load()", async () => {
5
+ const result = await openapi().load({}).get();
6
+ expectTypeOf(result.filesystem).toMatchTypeOf();
7
+ expectTypeOf(result.valid).toMatchTypeOf();
8
+ });
9
+ it("returns the correct type for validate()", async () => {
10
+ const result = await openapi().load({}).validate().get();
11
+ expectTypeOf(result.valid).toMatchTypeOf();
12
+ });
13
+ });
14
+ //# sourceMappingURL=openapi.test-d.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/utils/openapi/openapi.test-d.ts"],
4
+ "sourcesContent": ["import { describe, expectTypeOf, it } from 'vitest'\n\nimport type { Filesystem } from '../../types/index'\nimport { openapi } from './openapi'\n\ndescribe('openapi', () => {\n it('returns the correct type for load()', async () => {\n const result = await openapi().load({}).get()\n\n expectTypeOf(result.filesystem).toMatchTypeOf<Filesystem>()\n\n // @ts-expect-error `valid` should be undefined\n expectTypeOf(result.valid).toMatchTypeOf<boolean>()\n })\n\n it('returns the correct type for validate()', async () => {\n const result = await openapi().load({}).validate().get()\n\n expectTypeOf(result.valid).toMatchTypeOf<boolean>()\n })\n})\n"],
5
+ "mappings": "AAAA,SAAS,UAAU,cAAc,UAAU;AAG3C,SAAS,eAAe;AAExB,SAAS,WAAW,MAAM;AACxB,KAAG,uCAAuC,YAAY;AACpD,UAAM,SAAS,MAAM,QAAQ,EAAE,KAAK,CAAC,CAAC,EAAE,IAAI;AAE5C,iBAAa,OAAO,UAAU,EAAE,cAA0B;AAG1D,iBAAa,OAAO,KAAK,EAAE,cAAuB;AAAA,EACpD,CAAC;AAED,KAAG,2CAA2C,YAAY;AACxD,UAAM,SAAS,MAAM,QAAQ,EAAE,KAAK,CAAC,CAAC,EAAE,SAAS,EAAE,IAAI;AAEvD,iBAAa,OAAO,KAAK,EAAE,cAAuB;AAAA,EACpD,CAAC;AACH,CAAC;",
6
+ "names": []
7
+ }
@@ -0,0 +1,6 @@
1
+ import type { Queue, Task } from '../../../types/index.js';
2
+ /**
3
+ * Add a new task to the existing queue
4
+ */
5
+ export declare function queueTask<T extends Task[]>(queue: Queue, task: Task): Queue<T>;
6
+ //# sourceMappingURL=queueTask.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queueTask.d.ts","sourceRoot":"","sources":["../../../../src/utils/openapi/utils/queueTask.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAA;AAEhD;;GAEG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,IAAI,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,GAI7D,KAAK,CAAC,CAAC,CAAC,CACd"}
@@ -0,0 +1,10 @@
1
+ function queueTask(queue, task) {
2
+ return {
3
+ ...queue,
4
+ tasks: [...queue.tasks, task]
5
+ };
6
+ }
7
+ export {
8
+ queueTask
9
+ };
10
+ //# sourceMappingURL=queueTask.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/utils/openapi/utils/queueTask.ts"],
4
+ "sourcesContent": ["import type { Queue, Task } from '@/types/index'\n\n/**\n * Add a new task to the existing queue\n */\nexport function queueTask<T extends Task[]>(queue: Queue, task: Task) {\n return {\n ...queue,\n tasks: [...queue.tasks, task],\n } as Queue<T>\n}\n"],
5
+ "mappings": "AAKO,SAAS,UAA4B,OAAc,MAAY;AACpE,SAAO;AAAA,IACL,GAAG;AAAA,IACH,OAAO,CAAC,GAAG,MAAM,OAAO,IAAI;AAAA,EAC9B;AACF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,6 @@
1
+ import type { CommandChain, Queue, Task } from '../../../types/index.js';
2
+ /**
3
+ * Takes a queue of tasks and works through them
4
+ */
5
+ export declare function workThroughQueue<T extends Task[]>(queue: Queue<T>): Promise<CommandChain<T>>;
6
+ //# sourceMappingURL=workThroughQueue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workThroughQueue.d.ts","sourceRoot":"","sources":["../../../../src/utils/openapi/utils/workThroughQueue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAS,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAA;AAOrE;;GAEG;AACH,wBAAsB,gBAAgB,CAAC,CAAC,SAAS,IAAI,EAAE,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAkElG"}
@@ -0,0 +1,52 @@
1
+ import { dereference } from "../../../utils/dereference.js";
2
+ import { filter } from "../../../utils/filter.js";
3
+ import { load } from "../../../utils/load/load.js";
4
+ import { upgrade } from "../../../utils/upgrade.js";
5
+ import { validate } from "../../../utils/validate.js";
6
+ async function workThroughQueue(queue) {
7
+ const { input } = {
8
+ ...queue
9
+ };
10
+ let result = {};
11
+ for (const task of queue.tasks) {
12
+ const name = task.name;
13
+ const options = "options" in task ? task.options : void 0;
14
+ const currentSpecification = result.specification ? result.specification : typeof input === "object" ? (
15
+ // Detach from the original object
16
+ structuredClone(input)
17
+ ) : input;
18
+ if (name === "load") {
19
+ result = {
20
+ ...result,
21
+ ...await load(input, options)
22
+ };
23
+ } else if (name === "filter") {
24
+ result = {
25
+ ...result,
26
+ ...filter(currentSpecification, options)
27
+ };
28
+ } else if (name === "dereference") {
29
+ result = {
30
+ ...result,
31
+ ...await dereference(currentSpecification, options)
32
+ };
33
+ } else if (name === "upgrade") {
34
+ result = {
35
+ ...result,
36
+ ...upgrade(currentSpecification)
37
+ };
38
+ } else if (name === "validate") {
39
+ result = {
40
+ ...result,
41
+ ...await validate(currentSpecification, options)
42
+ };
43
+ } else {
44
+ const _ = name;
45
+ }
46
+ }
47
+ return result;
48
+ }
49
+ export {
50
+ workThroughQueue
51
+ };
52
+ //# sourceMappingURL=workThroughQueue.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/utils/openapi/utils/workThroughQueue.ts"],
4
+ "sourcesContent": ["import type { CommandChain, Merge, Queue, Task } from '@/types/index'\nimport { dereference } from '@/utils/dereference'\nimport { filter } from '@/utils/filter'\nimport { load } from '@/utils/load/load'\nimport { upgrade } from '@/utils/upgrade'\nimport { validate } from '@/utils/validate'\n\n/**\n * Takes a queue of tasks and works through them\n */\nexport async function workThroughQueue<T extends Task[]>(queue: Queue<T>): Promise<CommandChain<T>> {\n const { input } = {\n ...queue,\n }\n let result = {} as CommandChain<T>\n\n // Work through the whole queue\n for (const task of queue.tasks) {\n const name: keyof Commands = task.name\n const options: any = 'options' in task ? task.options : undefined\n\n // Use the result of the previous task, or fall back to the original input\n const currentSpecification = result.specification\n ? result.specification\n : typeof input === 'object'\n ? // Detach from the original object\n structuredClone(input)\n : input\n\n // load\n if (name === 'load') {\n result = {\n ...result,\n ...(await load(input, options as Commands['load']['task']['options'])),\n } as Merge<typeof result, Awaited<typeof load>>\n }\n\n // validate\n else if (name === 'filter') {\n result = {\n ...result,\n ...filter(currentSpecification, options as Commands['filter']['task']['options']),\n } as Merge<typeof result, ReturnType<typeof filter>>\n }\n\n // dereference\n else if (name === 'dereference') {\n result = {\n ...result,\n ...(await dereference(currentSpecification, options as Commands['dereference']['task']['options'])),\n } as Merge<typeof result, Awaited<typeof dereference>>\n }\n\n // upgrade\n else if (name === 'upgrade') {\n result = {\n ...result,\n ...upgrade(currentSpecification),\n } as Merge<typeof result, ReturnType<typeof upgrade>>\n }\n\n // validate\n else if (name === 'validate') {\n result = {\n ...result,\n ...(await validate(currentSpecification, options as Commands['validate']['task']['options'])),\n } as Merge<typeof result, Awaited<typeof validate>>\n }\n\n // Make TS complain when we forgot to handle a command.\n else {\n const _: never = name\n }\n }\n\n return result\n}\n"],
5
+ "mappings": "AACA,SAAS,mBAAmB;AAC5B,SAAS,cAAc;AACvB,SAAS,YAAY;AACrB,SAAS,eAAe;AACxB,SAAS,gBAAgB;AAKzB,eAAsB,iBAAmC,OAA2C;AAClG,QAAM,EAAE,MAAM,IAAI;AAAA,IAChB,GAAG;AAAA,EACL;AACA,MAAI,SAAS,CAAC;AAGd,aAAW,QAAQ,MAAM,OAAO;AAC9B,UAAM,OAAuB,KAAK;AAClC,UAAM,UAAe,aAAa,OAAO,KAAK,UAAU;AAGxD,UAAM,uBAAuB,OAAO,gBAChC,OAAO,gBACP,OAAO,UAAU;AAAA;AAAA,MAEf,gBAAgB,KAAK;AAAA,QACrB;AAGN,QAAI,SAAS,QAAQ;AACnB,eAAS;AAAA,QACP,GAAG;AAAA,QACH,GAAI,MAAM,KAAK,OAAO,OAA8C;AAAA,MACtE;AAAA,IACF,WAGS,SAAS,UAAU;AAC1B,eAAS;AAAA,QACP,GAAG;AAAA,QACH,GAAG,OAAO,sBAAsB,OAAgD;AAAA,MAClF;AAAA,IACF,WAGS,SAAS,eAAe;AAC/B,eAAS;AAAA,QACP,GAAG;AAAA,QACH,GAAI,MAAM,YAAY,sBAAsB,OAAqD;AAAA,MACnG;AAAA,IACF,WAGS,SAAS,WAAW;AAC3B,eAAS;AAAA,QACP,GAAG;AAAA,QACH,GAAG,QAAQ,oBAAoB;AAAA,MACjC;AAAA,IACF,WAGS,SAAS,YAAY;AAC5B,eAAS;AAAA,QACP,GAAG;AAAA,QACH,GAAI,MAAM,SAAS,sBAAsB,OAAkD;AAAA,MAC7F;AAAA,IACF,OAGK;AACH,YAAM,IAAW;AAAA,IACnB;AAAA,EACF;AAEA,SAAO;AACT;",
6
+ "names": []
7
+ }
@@ -215,13 +215,57 @@ function transformItemsObject(obj) {
215
215
  }, {});
216
216
  }
217
217
  function transformParameterObject(parameter) {
218
+ const serializationStyle = getParameterSerializationStyle(parameter);
219
+ const schema = transformItemsObject(parameter);
218
220
  delete parameter.collectionFormat;
219
221
  delete parameter.default;
220
222
  return {
221
- schema: transformItemsObject(parameter),
223
+ schema,
224
+ ...serializationStyle,
222
225
  ...parameter
223
226
  };
224
227
  }
228
+ const querySerialization = {
229
+ ssv: {
230
+ style: "spaceDelimited",
231
+ explode: false
232
+ },
233
+ pipes: {
234
+ style: "pipeDelimited",
235
+ explode: false
236
+ },
237
+ multi: {
238
+ style: "form",
239
+ explode: true
240
+ },
241
+ csv: {
242
+ style: "form",
243
+ explode: false
244
+ },
245
+ tsv: {}
246
+ };
247
+ const pathAndHeaderSerialization = {
248
+ ssv: {},
249
+ pipes: {},
250
+ multi: {},
251
+ csv: {
252
+ style: "simple",
253
+ explode: false
254
+ },
255
+ tsv: {}
256
+ };
257
+ const serializationStyles = {
258
+ header: pathAndHeaderSerialization,
259
+ query: querySerialization,
260
+ path: pathAndHeaderSerialization
261
+ };
262
+ function getParameterSerializationStyle(parameter) {
263
+ if (parameter.type !== "array" || !(parameter.in === "query" || parameter.in === "path" || parameter.in === "header")) {
264
+ return {};
265
+ }
266
+ const collectionFormat = parameter.collectionFormat ?? "csv";
267
+ return serializationStyles[parameter.in][collectionFormat];
268
+ }
225
269
  export {
226
270
  upgradeFromTwoToThree
227
271
  };
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/utils/upgrade-from-two-to-three.ts"],
4
- "sourcesContent": ["import type { OpenAPIV2, OpenAPIV3 } from '@scalar/openapi-types'\nimport type { UnknownObject } from '@scalar/types/utils'\n\nimport { traverse } from './traverse'\n\n/**\n * Upgrade Swagger 2.0 to OpenAPI 3.0\n *\n * https://swagger.io/blog/news/whats-new-in-openapi-3-0/\n */\nexport function upgradeFromTwoToThree(originalSpecification: UnknownObject) {\n let specification = originalSpecification\n\n // Version\n if (\n specification !== null &&\n typeof specification === 'object' &&\n typeof specification.swagger === 'string' &&\n specification.swagger?.startsWith('2.0')\n ) {\n specification.openapi = '3.0.4'\n delete specification.swagger\n } else {\n // Skip if it\u2019s something else than 3.0.x\n return specification\n }\n\n // Servers\n if (specification.host) {\n const schemes =\n Array.isArray(specification.schemes) && specification.schemes?.length ? specification.schemes : ['http']\n\n specification.servers = schemes.map((scheme: string[]) => ({\n url: `${scheme}://${specification.host}${specification.basePath ?? ''}`,\n }))\n\n delete specification.basePath\n delete specification.schemes\n delete specification.host\n } else if (specification.basePath) {\n specification.servers = [{ url: specification.basePath }]\n delete specification.basePath\n }\n\n // Schemas\n if (specification.definitions) {\n specification.components = Object.assign({}, specification.components, {\n schemas: specification.definitions,\n })\n\n delete specification.definitions\n\n // Rewrite $refs to definitions\n specification = traverse(specification, (schema) => {\n // Rewrite $refs to components\n if (typeof schema.$ref === 'string' && schema.$ref.startsWith('#/definitions/')) {\n schema.$ref = schema.$ref.replace(/^#\\/definitions\\//, '#/components/schemas/')\n }\n\n return schema\n })\n }\n\n // Transform file type to string with binary format\n specification = traverse(specification, (schema) => {\n if (schema.type === 'file') {\n schema.type = 'string'\n schema.format = 'binary'\n }\n\n return schema\n })\n\n // Paths\n if (typeof specification.paths === 'object') {\n for (const path in specification.paths) {\n if (Object.hasOwn(specification.paths, path)) {\n const pathItem = specification.paths[path]\n\n for (const method in pathItem) {\n if (Object.hasOwn(pathItem, method)) {\n const operationItem = pathItem[method]\n\n // Request bodies\n if (operationItem.parameters) {\n const bodyParameter = structuredClone(\n operationItem.parameters.find((parameter: OpenAPIV3.ParameterObject) => parameter.in === 'body') ?? {},\n )\n\n if (bodyParameter && Object.keys(bodyParameter).length) {\n delete bodyParameter.name\n delete bodyParameter.in\n\n const consumes = specification.consumes ?? operationItem.consumes ?? ['application/json']\n\n if (typeof operationItem.requestBody !== 'object') {\n operationItem.requestBody = {}\n }\n\n if (typeof operationItem.requestBody.content !== 'object') {\n operationItem.requestBody.content = {}\n }\n\n const { schema, ...requestBody } = bodyParameter\n\n operationItem.requestBody = {\n ...operationItem.requestBody,\n ...requestBody,\n }\n\n for (const type of consumes) {\n operationItem.requestBody.content[type] = {\n schema: schema,\n }\n }\n }\n\n // Delete body parameter\n operationItem.parameters = operationItem.parameters.filter(\n (parameter: OpenAPIV2.ParameterObject) => parameter.in !== 'body',\n )\n\n delete operationItem.consumes\n\n // formData parameters\n const formDataParameters = operationItem.parameters.filter(\n (parameter: OpenAPIV2.ParameterObject) => parameter.in === 'formData',\n )\n\n if (formDataParameters.length > 0) {\n if (typeof operationItem.requestBody !== 'object') {\n operationItem.requestBody = {}\n }\n\n if (typeof operationItem.requestBody.content !== 'object') {\n operationItem.requestBody.content = {}\n }\n\n operationItem.requestBody.content['application/x-www-form-urlencoded'] = {\n schema: {\n type: 'object',\n properties: {},\n required: [], // Initialize required array\n },\n }\n\n for (const param of formDataParameters) {\n operationItem.requestBody.content['application/x-www-form-urlencoded'].schema.properties[param.name] =\n {\n type: param.type,\n description: param.description,\n }\n\n // Add to required array if param is required\n if (param.required) {\n operationItem.requestBody.content['application/x-www-form-urlencoded'].schema.required.push(\n param.name,\n )\n }\n }\n\n // Remove formData parameters from the parameters array\n operationItem.parameters = operationItem.parameters.filter(\n (parameter: OpenAPIV2.ParameterObject) => parameter.in !== 'formData',\n )\n }\n\n operationItem.parameters = operationItem.parameters.map((parameter) =>\n transformParameterObject(parameter),\n )\n }\n\n // Responses\n if (operationItem.responses) {\n for (const response in operationItem.responses) {\n if (Object.hasOwn(operationItem.responses, response)) {\n const responseItem = operationItem.responses[response]\n\n if (responseItem.headers) {\n responseItem.headers = Object.entries(responseItem.headers).reduce((acc, [name, header]) => {\n return {\n [name]: transformParameterObject(header),\n ...acc,\n }\n }, {})\n }\n if (responseItem.schema) {\n const produces = specification.produces ?? operationItem.produces ?? ['application/json']\n\n if (typeof responseItem.content !== 'object') {\n responseItem.content = {}\n }\n\n for (const type of produces) {\n responseItem.content[type] = {\n schema: responseItem.schema,\n }\n }\n\n delete responseItem.schema\n }\n }\n }\n }\n\n delete operationItem.produces\n\n // Delete empty parameters\n if (operationItem.parameters?.length === 0) {\n delete operationItem.parameters\n }\n }\n }\n }\n }\n }\n\n // Upgrade securityDefinitions\n if (specification.securityDefinitions) {\n if (typeof specification.components !== 'object') {\n specification.components = {}\n }\n\n // Assert that components is of type OpenAPIV3.ComponentsObject\n specification.components = specification.components as OpenAPIV3.ComponentsObject\n\n Object.assign(specification.components, { securitySchemes: {} })\n\n for (const [key, securityScheme] of Object.entries(specification.securityDefinitions)) {\n if (typeof securityScheme === 'object') {\n if ('type' in securityScheme && securityScheme.type === 'oauth2') {\n const { flow, authorizationUrl, tokenUrl, scopes } = securityScheme as {\n type: 'oauth2'\n flow?: string\n authorizationUrl?: string\n tokenUrl?: string\n scopes?: Record<string, string>\n }\n\n // Assert that securitySchemes is of type OpenAPIV3.SecuritySchemeObject\n Object.assign((specification.components as OpenAPIV3.ComponentsObject).securitySchemes, {\n [key]: {\n type: 'oauth2',\n flows: {\n [flow as string]: Object.assign(\n {},\n authorizationUrl && { authorizationUrl },\n tokenUrl && { tokenUrl },\n scopes && { scopes },\n ),\n },\n },\n })\n } else if ('type' in securityScheme && securityScheme.type === 'basic') {\n Object.assign((specification.components as OpenAPIV3.ComponentsObject).securitySchemes, {\n [key]: {\n type: 'http',\n scheme: 'basic',\n },\n })\n } else {\n Object.assign((specification.components as OpenAPIV3.ComponentsObject).securitySchemes, {\n [key]: securityScheme,\n })\n }\n }\n }\n\n delete specification.securityDefinitions\n }\n\n return specification as OpenAPIV3.Document\n}\n\nfunction transformItemsObject<T extends Record<PropertyKey, unknown>>(obj: T): OpenAPIV3.SchemaObject {\n const schemaProperties = [\n 'type',\n 'format',\n 'items',\n 'maximum',\n 'exclusiveMaximum',\n 'minimum',\n 'exclusiveMinimum',\n 'maxLength',\n 'minLength',\n 'pattern',\n 'maxItems',\n 'minItems',\n 'uniqueItems',\n 'enum',\n 'multipleOf',\n ]\n\n return schemaProperties.reduce((acc, property) => {\n if (Object.hasOwn(obj, property)) {\n acc[property] = obj[property]\n delete obj[property]\n }\n\n return acc\n }, {} as OpenAPIV3.SchemaObject)\n}\n\nfunction transformParameterObject(parameter: OpenAPIV2.ParameterObject): OpenAPIV3.ParameterObject {\n delete parameter.collectionFormat\n delete parameter.default\n\n return {\n schema: transformItemsObject(parameter),\n ...parameter,\n }\n}\n"],
5
- "mappings": "AAGA,SAAS,gBAAgB;AAOlB,SAAS,sBAAsB,uBAAsC;AAC1E,MAAI,gBAAgB;AAGpB,MACE,kBAAkB,QAClB,OAAO,kBAAkB,YACzB,OAAO,cAAc,YAAY,YACjC,cAAc,SAAS,WAAW,KAAK,GACvC;AACA,kBAAc,UAAU;AACxB,WAAO,cAAc;AAAA,EACvB,OAAO;AAEL,WAAO;AAAA,EACT;AAGA,MAAI,cAAc,MAAM;AACtB,UAAM,UACJ,MAAM,QAAQ,cAAc,OAAO,KAAK,cAAc,SAAS,SAAS,cAAc,UAAU,CAAC,MAAM;AAEzG,kBAAc,UAAU,QAAQ,IAAI,CAAC,YAAsB;AAAA,MACzD,KAAK,GAAG,MAAM,MAAM,cAAc,IAAI,GAAG,cAAc,YAAY,EAAE;AAAA,IACvE,EAAE;AAEF,WAAO,cAAc;AACrB,WAAO,cAAc;AACrB,WAAO,cAAc;AAAA,EACvB,WAAW,cAAc,UAAU;AACjC,kBAAc,UAAU,CAAC,EAAE,KAAK,cAAc,SAAS,CAAC;AACxD,WAAO,cAAc;AAAA,EACvB;AAGA,MAAI,cAAc,aAAa;AAC7B,kBAAc,aAAa,OAAO,OAAO,CAAC,GAAG,cAAc,YAAY;AAAA,MACrE,SAAS,cAAc;AAAA,IACzB,CAAC;AAED,WAAO,cAAc;AAGrB,oBAAgB,SAAS,eAAe,CAAC,WAAW;AAElD,UAAI,OAAO,OAAO,SAAS,YAAY,OAAO,KAAK,WAAW,gBAAgB,GAAG;AAC/E,eAAO,OAAO,OAAO,KAAK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SAAS;AAAA,kBACvB,UAAU,EAAE,OAAO;AAAA,gBACrB;AAAA,cACF;AAAA,YACF;AAAA,UACF,CAAC;AAAA,QACH,WAAW,UAAU,kBAAkB,eAAe,SAAS,SAAS;AACtE,iBAAO,OAAQ,cAAc,WAA0C,iBAAiB;AAAA,YACtF,CAAC,GAAG,GAAG;AAAA,cACL,MAAM;AAAA,cACN,QAAQ;AAAA,YACV;AAAA,UACF,CAAC;AAAA,QACH,OAAO;AACL,iBAAO,OAAQ,cAAc,WAA0C,iBAAiB;AAAA,YACtF,CAAC,GAAG,GAAG;AAAA,UACT,CAAC;AAAA,QACH;AAAA,MACF;AAAA,IACF;AAEA,WAAO,cAAc;AAAA,EACvB;AAEA,SAAO;AACT;AAEA,SAAS,qBAA6D,KAAgC;AACpG,QAAM,mBAAmB;AAAA,IACvB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAEA,SAAO,iBAAiB,OAAO,CAAC,KAAK,aAAa;AAChD,QAAI,OAAO,OAAO,KAAK,QAAQ,GAAG;AAChC,UAAI,QAAQ,IAAI,IAAI,QAAQ;AAC5B,aAAO,IAAI,QAAQ;AAAA,IACrB;AAEA,WAAO;AAAA,EACT,GAAG,CAAC,CAA2B;AACjC;AAEA,SAAS,yBAAyB,WAAiE;AACjG,SAAO,UAAU;AACjB,SAAO,UAAU;AAEjB,SAAO;AAAA,IACL,QAAQ,qBAAqB,SAAS;AAAA,IACtC,GAAG;AAAA,EACL;AACF;",
4
+ "sourcesContent": ["import type { OpenAPIV2, OpenAPIV3 } from '@scalar/openapi-types'\nimport type { UnknownObject } from '@scalar/types/utils'\n\nimport { traverse } from './traverse'\n\n/**\n * Upgrade Swagger 2.0 to OpenAPI 3.0\n *\n * https://swagger.io/blog/news/whats-new-in-openapi-3-0/\n */\nexport function upgradeFromTwoToThree(originalSpecification: UnknownObject) {\n let specification = originalSpecification\n\n // Version\n if (\n specification !== null &&\n typeof specification === 'object' &&\n typeof specification.swagger === 'string' &&\n specification.swagger?.startsWith('2.0')\n ) {\n specification.openapi = '3.0.4'\n delete specification.swagger\n } else {\n // Skip if it\u2019s something else than 3.0.x\n return specification\n }\n\n // Servers\n if (specification.host) {\n const schemes =\n Array.isArray(specification.schemes) && specification.schemes?.length ? specification.schemes : ['http']\n\n specification.servers = schemes.map((scheme: string[]) => ({\n url: `${scheme}://${specification.host}${specification.basePath ?? ''}`,\n }))\n\n delete specification.basePath\n delete specification.schemes\n delete specification.host\n } else if (specification.basePath) {\n specification.servers = [{ url: specification.basePath }]\n delete specification.basePath\n }\n\n // Schemas\n if (specification.definitions) {\n specification.components = Object.assign({}, specification.components, {\n schemas: specification.definitions,\n })\n\n delete specification.definitions\n\n // Rewrite $refs to definitions\n specification = traverse(specification, (schema) => {\n // Rewrite $refs to components\n if (typeof schema.$ref === 'string' && schema.$ref.startsWith('#/definitions/')) {\n schema.$ref = schema.$ref.replace(/^#\\/definitions\\//, '#/components/schemas/')\n }\n\n return schema\n })\n }\n\n // Transform file type to string with binary format\n specification = traverse(specification, (schema) => {\n if (schema.type === 'file') {\n schema.type = 'string'\n schema.format = 'binary'\n }\n\n return schema\n })\n\n // Paths\n if (typeof specification.paths === 'object') {\n for (const path in specification.paths) {\n if (Object.hasOwn(specification.paths, path)) {\n const pathItem = specification.paths[path]\n\n for (const method in pathItem) {\n if (Object.hasOwn(pathItem, method)) {\n const operationItem = pathItem[method]\n\n // Request bodies\n if (operationItem.parameters) {\n const bodyParameter = structuredClone(\n operationItem.parameters.find((parameter: OpenAPIV3.ParameterObject) => parameter.in === 'body') ?? {},\n )\n\n if (bodyParameter && Object.keys(bodyParameter).length) {\n delete bodyParameter.name\n delete bodyParameter.in\n\n const consumes = specification.consumes ?? operationItem.consumes ?? ['application/json']\n\n if (typeof operationItem.requestBody !== 'object') {\n operationItem.requestBody = {}\n }\n\n if (typeof operationItem.requestBody.content !== 'object') {\n operationItem.requestBody.content = {}\n }\n\n const { schema, ...requestBody } = bodyParameter\n\n operationItem.requestBody = {\n ...operationItem.requestBody,\n ...requestBody,\n }\n\n for (const type of consumes) {\n operationItem.requestBody.content[type] = {\n schema: schema,\n }\n }\n }\n\n // Delete body parameter\n operationItem.parameters = operationItem.parameters.filter(\n (parameter: OpenAPIV2.ParameterObject) => parameter.in !== 'body',\n )\n\n delete operationItem.consumes\n\n // formData parameters\n const formDataParameters = operationItem.parameters.filter(\n (parameter: OpenAPIV2.ParameterObject) => parameter.in === 'formData',\n )\n\n if (formDataParameters.length > 0) {\n if (typeof operationItem.requestBody !== 'object') {\n operationItem.requestBody = {}\n }\n\n if (typeof operationItem.requestBody.content !== 'object') {\n operationItem.requestBody.content = {}\n }\n\n operationItem.requestBody.content['application/x-www-form-urlencoded'] = {\n schema: {\n type: 'object',\n properties: {},\n required: [], // Initialize required array\n },\n }\n\n for (const param of formDataParameters) {\n operationItem.requestBody.content['application/x-www-form-urlencoded'].schema.properties[param.name] =\n {\n type: param.type,\n description: param.description,\n }\n\n // Add to required array if param is required\n if (param.required) {\n operationItem.requestBody.content['application/x-www-form-urlencoded'].schema.required.push(\n param.name,\n )\n }\n }\n\n // Remove formData parameters from the parameters array\n operationItem.parameters = operationItem.parameters.filter(\n (parameter: OpenAPIV2.ParameterObject) => parameter.in !== 'formData',\n )\n }\n\n operationItem.parameters = operationItem.parameters.map((parameter) =>\n transformParameterObject(parameter),\n )\n }\n\n // Responses\n if (operationItem.responses) {\n for (const response in operationItem.responses) {\n if (Object.hasOwn(operationItem.responses, response)) {\n const responseItem = operationItem.responses[response]\n\n if (responseItem.headers) {\n responseItem.headers = Object.entries(responseItem.headers).reduce((acc, [name, header]) => {\n return {\n [name]: transformParameterObject(header),\n ...acc,\n }\n }, {})\n }\n if (responseItem.schema) {\n const produces = specification.produces ?? operationItem.produces ?? ['application/json']\n\n if (typeof responseItem.content !== 'object') {\n responseItem.content = {}\n }\n\n for (const type of produces) {\n responseItem.content[type] = {\n schema: responseItem.schema,\n }\n }\n\n delete responseItem.schema\n }\n }\n }\n }\n\n delete operationItem.produces\n\n // Delete empty parameters\n if (operationItem.parameters?.length === 0) {\n delete operationItem.parameters\n }\n }\n }\n }\n }\n }\n\n // Upgrade securityDefinitions\n if (specification.securityDefinitions) {\n if (typeof specification.components !== 'object') {\n specification.components = {}\n }\n\n // Assert that components is of type OpenAPIV3.ComponentsObject\n specification.components = specification.components as OpenAPIV3.ComponentsObject\n\n Object.assign(specification.components, { securitySchemes: {} })\n\n for (const [key, securityScheme] of Object.entries(specification.securityDefinitions)) {\n if (typeof securityScheme === 'object') {\n if ('type' in securityScheme && securityScheme.type === 'oauth2') {\n const { flow, authorizationUrl, tokenUrl, scopes } = securityScheme as {\n type: 'oauth2'\n flow?: string\n authorizationUrl?: string\n tokenUrl?: string\n scopes?: Record<string, string>\n }\n\n // Assert that securitySchemes is of type OpenAPIV3.SecuritySchemeObject\n Object.assign((specification.components as OpenAPIV3.ComponentsObject).securitySchemes, {\n [key]: {\n type: 'oauth2',\n flows: {\n [flow as string]: Object.assign(\n {},\n authorizationUrl && { authorizationUrl },\n tokenUrl && { tokenUrl },\n scopes && { scopes },\n ),\n },\n },\n })\n } else if ('type' in securityScheme && securityScheme.type === 'basic') {\n Object.assign((specification.components as OpenAPIV3.ComponentsObject).securitySchemes, {\n [key]: {\n type: 'http',\n scheme: 'basic',\n },\n })\n } else {\n Object.assign((specification.components as OpenAPIV3.ComponentsObject).securitySchemes, {\n [key]: securityScheme,\n })\n }\n }\n }\n\n delete specification.securityDefinitions\n }\n\n return specification as OpenAPIV3.Document\n}\n\nfunction transformItemsObject<T extends Record<PropertyKey, unknown>>(obj: T): OpenAPIV3.SchemaObject {\n const schemaProperties = [\n 'type',\n 'format',\n 'items',\n 'maximum',\n 'exclusiveMaximum',\n 'minimum',\n 'exclusiveMinimum',\n 'maxLength',\n 'minLength',\n 'pattern',\n 'maxItems',\n 'minItems',\n 'uniqueItems',\n 'enum',\n 'multipleOf',\n ]\n\n return schemaProperties.reduce((acc, property) => {\n if (Object.hasOwn(obj, property)) {\n acc[property] = obj[property]\n delete obj[property]\n }\n\n return acc\n }, {} as OpenAPIV3.SchemaObject)\n}\n\nfunction transformParameterObject(parameter: OpenAPIV2.ParameterObject): OpenAPIV3.ParameterObject {\n // it is important to call getParameterSerializationStyle first because transformItemsObject modifies properties on which getParameterSerializationStyle rely on\n const serializationStyle = getParameterSerializationStyle(parameter)\n const schema = transformItemsObject(parameter)\n\n delete parameter.collectionFormat\n delete parameter.default\n\n return {\n schema,\n ...serializationStyle,\n ...parameter,\n }\n}\n\ntype CollectionFormat = 'csv' | 'ssv' | 'tsv' | 'pipes' | 'multi'\n\ntype ParameterSerializationStyle = { style?: string; explode?: boolean }\n\nconst querySerialization: Record<CollectionFormat, ParameterSerializationStyle> = {\n ssv: {\n style: 'spaceDelimited',\n explode: false,\n },\n pipes: {\n style: 'pipeDelimited',\n explode: false,\n },\n multi: {\n style: 'form',\n explode: true,\n },\n csv: {\n style: 'form',\n explode: false,\n },\n tsv: {},\n}\n\nconst pathAndHeaderSerialization: Record<CollectionFormat, ParameterSerializationStyle> = {\n ssv: {},\n pipes: {},\n multi: {},\n csv: {\n style: 'simple',\n explode: false,\n },\n tsv: {},\n}\n\nconst serializationStyles = {\n header: pathAndHeaderSerialization,\n query: querySerialization,\n path: pathAndHeaderSerialization,\n} as const\n\nfunction getParameterSerializationStyle(parameter: OpenAPIV2.ParameterObject): ParameterSerializationStyle {\n if (\n parameter.type !== 'array' ||\n !(parameter.in === 'query' || parameter.in === 'path' || parameter.in === 'header')\n ) {\n return {}\n }\n\n const collectionFormat = parameter.collectionFormat ?? 'csv'\n\n return serializationStyles[parameter.in][collectionFormat]\n}\n"],
5
+ "mappings": "AAGA,SAAS,gBAAgB;AAOlB,SAAS,sBAAsB,uBAAsC;AAC1E,MAAI,gBAAgB;AAGpB,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;AAAA,EAC1B,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,MAAM;AACR;AAEA,SAAS,+BAA+B,WAAmE;AACzG,MACE,UAAU,SAAS,WACnB,EAAE,UAAU,OAAO,WAAW,UAAU,OAAO,UAAU,UAAU,OAAO,WAC1E;AACA,WAAO,CAAC;AAAA,EACV;AAEA,QAAM,mBAAmB,UAAU,oBAAoB;AAEvD,SAAO,oBAAoB,UAAU,EAAE,EAAE,gBAAgB;AAC3D;",
6
6
  "names": []
7
7
  }
package/package.json CHANGED
@@ -17,7 +17,7 @@
17
17
  "parser",
18
18
  "typescript"
19
19
  ],
20
- "version": "0.13.0",
20
+ "version": "0.15.0",
21
21
  "engines": {
22
22
  "node": ">=20"
23
23
  },
@@ -39,6 +39,16 @@
39
39
  "import": "./dist/plugins/read-files/index.js",
40
40
  "types": "./dist/plugins/read-files/index.d.ts",
41
41
  "default": "./dist/plugins/read-files/index.js"
42
+ },
43
+ "./utils/bundle/plugins/fetch-urls": {
44
+ "import": "./dist/utils/bundle/plugins/fetch-urls/index.js",
45
+ "types": "./dist/utils/bundle/plugins/fetch-urls/index.d.ts",
46
+ "default": "./dist/utils/bundle/plugins/fetch-urls/index.js"
47
+ },
48
+ "./utils/bundle/plugins/read-files": {
49
+ "import": "./dist/utils/bundle/plugins/read-files/index.js",
50
+ "types": "./dist/utils/bundle/plugins/read-files/index.d.ts",
51
+ "default": "./dist/utils/bundle/plugins/read-files/index.js"
42
52
  }
43
53
  },
44
54
  "files": [
@@ -58,14 +68,14 @@
58
68
  "devDependencies": {
59
69
  "@apidevtools/swagger-parser": "^10.1.0",
60
70
  "@types/node": "^20.17.10",
61
- "glob": "^10.3.10",
71
+ "fastify": "^5.3.3",
62
72
  "json-to-ast": "^2.1.0",
63
73
  "just-diff": "^6.0.2",
64
74
  "tinybench": "^2.8.0",
65
75
  "vite": "5.4.19",
66
- "@scalar/openapi-types": "0.3.1",
67
- "@scalar/build-tooling": "0.2.1",
68
- "@scalar/types": "0.2.1"
76
+ "@scalar/build-tooling": "0.2.2",
77
+ "@scalar/types": "0.2.2",
78
+ "@scalar/openapi-types": "0.3.2"
69
79
  },
70
80
  "scripts": {
71
81
  "build": "scalar-build-esbuild",
@@ -74,7 +84,7 @@
74
84
  "lint:fix": "eslint . --fix",
75
85
  "test": "NODE_OPTIONS=--max_old_space_size=8192 vitest",
76
86
  "test:prepare": "vite-node scripts/load-files.ts",
77
- "test:unit": "vite-node scripts/load-files.ts && vitest",
87
+ "test:unit": "vitest",
78
88
  "types:build": "scalar-types-build",
79
89
  "types:check": "scalar-types-check"
80
90
  }