Skip to content

Commit a67f38c

Browse files
committed
fix: allow $ref pointers to point to a null value
1 parent 5303da9 commit a67f38c

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

lib/pointer.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,14 @@ class Pointer<S extends object = JSONSchema, O extends ParserOptions<S> = Parser
121121
continue;
122122
}
123123

124+
// If the token we're looking for ended up not containing any slashes but is
125+
// actually instead pointing to an existing `null` value then we should use that
126+
// `null` value.
127+
if (token in this.value && this.value[token] === null) {
128+
this.value = null;
129+
continue;
130+
}
131+
124132
this.value = null;
125133

126134
const path = this.$ref.path || "";
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { describe, it } from "vitest";
2+
import { expect } from "vitest";
3+
import $RefParser from "../../../lib/index.js";
4+
import path from "../../utils/path";
5+
import dereferenced from "./dereferenced.js";
6+
7+
describe("dereferencing a `$ref` that points to a `null` value", () => {
8+
it.only("should dereference successfully", async () => {
9+
const parser = new $RefParser();
10+
const schema = await parser.dereference(path.rel("test/specs/dereference-null-ref/dereference-null-ref.yaml"));
11+
expect(schema).to.equal(parser.schema);
12+
expect(schema).to.deep.equal(dereferenced);
13+
});
14+
});
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
components:
2+
examples:
3+
product:
4+
value:
5+
data:
6+
admission:
7+
$ref: "#/components/examples/product/value/data/pas"
8+
pas: null
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export default {
2+
components: {
3+
examples: {
4+
product: {
5+
value: {
6+
data: {
7+
admission: null,
8+
pas: null,
9+
},
10+
},
11+
},
12+
},
13+
},
14+
};

0 commit comments

Comments
 (0)