Skip to content

Commit

Permalink
fix: dont cache on circular references to prevent overwriting externa…
Browse files Browse the repository at this point in the history
…l ref resolutions
  • Loading branch information
jonluca committed Oct 10, 2024
1 parent 3bcee96 commit 588197e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/dereference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ function dereference$Ref<S extends object = JSONSchema, O extends ParserOptions<
const $refPath = url.resolve(shouldResolveOnCwd ? url.cwd() : path, $ref.$ref);

const cache = dereferencedCache.get($refPath);
if (cache) {
if (cache && !cache.circular) {
const refKeys = Object.keys($ref);
if (refKeys.length > 1) {
const extraKeys = {};
Expand Down
10 changes: 5 additions & 5 deletions test/specs/dereference-callback/dereference-callback.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,26 @@ describe("Schema with a $ref", () => {
expect(calls).to.deep.equal([
{
path: "#/definitions/b",
value: { $ref: "#/definitions/a" },
value: { $ref: "#/definitions/b" },
parent: {
a: {
$ref: "#/definitions/a",
$ref: "#/definitions/b",
},
b: {
$ref: "#/definitions/a",
$ref: "#/definitions/b",
},
},
parentPropName: "a",
},
{
path: "#/definitions/a",
value: { $ref: "#/definitions/a" },
value: { $ref: "#/definitions/b" },
parent: {
c: {
type: "string",
},
d: {
$ref: "#/definitions/a",
$ref: "#/definitions/b",
},
},
parentPropName: "d",
Expand Down

0 comments on commit 588197e

Please sign in to comment.