Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion lib/__tests__/bundle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,17 @@ describe("bundle", () => {
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();
expect(schema).toEqual({
schemas: {
Bar: {
$ref: '#/schemas/Foo',
description: 'ok',
},
Foo: {
$ref: '#/schemas/Bar',
},
},
});
});

it("bundles multiple references to the same file correctly", async () => {
Expand Down
1 change: 0 additions & 1 deletion lib/__tests__/pointer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ describe("pointer", () => {
const refParser = new $RefParser();
const pathOrUrlOrSchema = path.resolve("lib", "__tests__", "spec", "openapi-paths-ref.json");
const schema = (await refParser.bundle({ pathOrUrlOrSchema })) as any;
console.log(JSON.stringify(schema, null, 2));

// The GET endpoint should have its schema defined inline
const getSchema = schema.paths["/foo"].get.responses["200"].content["application/json"].schema;
Expand Down
6 changes: 4 additions & 2 deletions lib/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -579,9 +579,11 @@ function remap(parser: $RefParser, inventory: InventoryEntry[]) {
continue;
}

// Keep internal refs internal
// Keep internal refs internal. However, if the $ref extends the resolved value
// (i.e. it has additional properties in addition to "$ref"), then we must
// preserve the original $ref rather than rewriting it to the resolved hash.
if (!entry.external) {
if (entry.$ref && typeof entry.$ref === "object") {
if (!entry.extended && entry.$ref && typeof entry.$ref === "object") {
entry.$ref.$ref = entry.hash;
}
continue;
Expand Down