Skip to content

Commit 34a9deb

Browse files
fix: always return null if sub schema is not found
1 parent 97511ba commit 34a9deb

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ function getDataByJSONPointer (data, jsonPointer) {
257257
}
258258
current = current[part]
259259
}
260-
return current
260+
return current ?? null
261261
}
262262

263263
module.exports = { RefResolver }

test/ref-resolver.test.js renamed to test/get-schema.test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,3 +196,21 @@ test('should not use a root $id if it is an anchor', () => {
196196
const resolvedSchema3 = refResolver.getSchema(schemaIdArgument, schemaIdProperty)
197197
assert.equal(resolvedSchema3, schema)
198198
})
199+
200+
test('should return null if sub schema by json pointer is not found', () => {
201+
const refResolver = new RefResolver()
202+
203+
const schemaId = 'schemaId'
204+
const schema = {
205+
$id: 'schemaId',
206+
type: 'object',
207+
properties: {
208+
foo: { type: 'string' }
209+
}
210+
}
211+
212+
refResolver.addSchema(schema)
213+
214+
const schemaRefs = refResolver.getSchema(schemaId, '#/missingSchema')
215+
assert.equal(schemaRefs, null)
216+
})

0 commit comments

Comments
 (0)