Skip to content

Commit ff7311f

Browse files
authored
fix: resolveInlineRef should handle arrays (#85)
1 parent eef0ce8 commit ff7311f

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/__tests__/resolveInlineRef.spec.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ describe('resolveInlineRef', () => {
1010
$ref: '#/c',
1111
},
1212
c: {
13-
$ref: '#/d',
14-
},
15-
d: {
16-
foo: 'woo!',
13+
$ref: '#/d/0',
1714
},
15+
d: [
16+
{
17+
foo: 'woo!',
18+
},
19+
],
1820
};
1921

2022
expect(resolveInlineRef(doc, '#/a')).toEqual('woo!');

src/resolveInlineRef.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function _resolveInlineRef(document: Dictionary<unknown>, ref: string, seen: unk
1212
const path = pointerToPath(ref);
1313
let value: unknown = document;
1414
for (const segment of path) {
15-
if (!isPlainObject(value) || !(segment in value)) {
15+
if ((!isPlainObject(value) && !Array.isArray(value)) || !(segment in value)) {
1616
throw new ReferenceError(`Could not resolve '${ref}'`);
1717
}
1818

0 commit comments

Comments
 (0)