Skip to content

Commit

Permalink
fix: always return null if sub schema is not found
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-tymoshenko committed Oct 20, 2023
1 parent 97511ba commit 34a9deb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ function getDataByJSONPointer (data, jsonPointer) {
}
current = current[part]
}
return current
return current ?? null
}

module.exports = { RefResolver }
18 changes: 18 additions & 0 deletions test/ref-resolver.test.js → test/get-schema.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,21 @@ test('should not use a root $id if it is an anchor', () => {
const resolvedSchema3 = refResolver.getSchema(schemaIdArgument, schemaIdProperty)
assert.equal(resolvedSchema3, schema)
})

test('should return null if sub schema by json pointer is not found', () => {
const refResolver = new RefResolver()

const schemaId = 'schemaId'
const schema = {
$id: 'schemaId',
type: 'object',
properties: {
foo: { type: 'string' }
}
}

refResolver.addSchema(schema)

const schemaRefs = refResolver.getSchema(schemaId, '#/missingSchema')
assert.equal(schemaRefs, null)
})

0 comments on commit 34a9deb

Please sign in to comment.