This repository was archived by the owner on Feb 12, 2026. It is now read-only.
forked from APIDevTools/json-schema-ref-parser
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathbundle.test.ts
More file actions
42 lines (35 loc) · 1.63 KB
/
bundle.test.ts
File metadata and controls
42 lines (35 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import path from "path";
import { describe, expect, it } from "vitest";
import { $RefParser } from "..";
describe("bundle", () => {
it("handles circular reference with description", async () => {
const refParser = new $RefParser();
const pathOrUrlOrSchema = path.resolve("lib", "__tests__", "spec", "circular-ref-with-description.json");
const schema = await refParser.bundle({ pathOrUrlOrSchema });
expect(schema).not.toBeUndefined();
});
it("bundles multiple references to the same file correctly", async () => {
const refParser = new $RefParser();
const pathOrUrlOrSchema = path.resolve("lib", "__tests__", "spec", "multiple-refs.json");
const schema = (await refParser.bundle({ pathOrUrlOrSchema })) as any;
// Both parameters should now be $ref to the same internal definition
const firstParam = schema.paths["/test1/{pathId}"].get.parameters[0];
const secondParam = schema.paths["/test2/{pathId}"].get.parameters[0];
// The $ref should match the output structure in file_context_0
expect(firstParam.$ref).toBe("#/components/parameters/path-parameter_pathId");
expect(secondParam.$ref).toBe("#/components/parameters/path-parameter_pathId");
// The referenced parameter should exist and match the expected structure
expect(schema.components).toBeDefined();
expect(schema.components.parameters).toBeDefined();
expect(schema.components.parameters["path-parameter_pathId"]).toEqual({
name: "pathId",
in: "path",
required: true,
schema: {
type: "string",
format: "uuid",
description: "Unique identifier for the path",
},
});
});
});