Skip to content

Commit 839b6de

Browse files
GabrielCastroJamesMessinger
authored andcommitted
Fix bundling bug (#105)
Fixed a bug in the `bundle()` method when a file was referenced at multiple different levels
1 parent d8b0769 commit 839b6de

5 files changed

Lines changed: 66 additions & 1 deletion

File tree

lib/bundle.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ function remap (inventory) {
214214
}
215215
else if (entry.file === file && entry.hash.indexOf(hash + '/') === 0) {
216216
// This $ref points to the a sub-value as the prevous $ref, so remap it beneath that path
217-
entry.$ref.$ref = Pointer.join(pathFromRoot, Pointer.parse(entry.hash));
217+
entry.$ref.$ref = Pointer.join(pathFromRoot, Pointer.parse(entry.hash.replace(hash, '#')));
218218
}
219219
else {
220220
// We've moved to a new file or new hash

test/specs/bundle/bundle.spec.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
describe('Bundle', function () {
2+
'use strict';
3+
4+
it('should bundle multiple files, with multiple refs', function () {
5+
var parser = new $RefParser();
6+
return parser.bundle(path.rel('specs/bundle/outter.yaml'))
7+
.then(function (bundled) {
8+
var secondParse = new $RefParser();
9+
return secondParse.dereference(bundled);
10+
})
11+
.then(function (deref) {
12+
expect(deref).to.deep.equal(helper.dereferenced.bundled);
13+
});
14+
});
15+
16+
});
17+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
helper.dereferenced.bundled = {
2+
type: 'object',
3+
required: ['user', 'token'],
4+
properties: {
5+
token: {
6+
type: 'string'
7+
},
8+
user: {
9+
type: 'object',
10+
required: ['name'],
11+
properties: {
12+
name: {
13+
type: 'string'
14+
}
15+
},
16+
example: {
17+
name: 'Homer'
18+
}
19+
}
20+
},
21+
example: {
22+
token: '11111111',
23+
user: {
24+
name: 'Homer'
25+
}
26+
}
27+
};

test/specs/bundle/inner.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
User:
3+
type: object
4+
required: [name]
5+
properties:
6+
name:
7+
type: string
8+
example:
9+
name: 'Homer'

test/specs/bundle/outter.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
type: object
3+
required: [user, token]
4+
properties:
5+
token:
6+
type: string
7+
user:
8+
$ref: './inner.yaml#/User'
9+
example:
10+
token: '11111111'
11+
user:
12+
$ref: './inner.yaml#/User/example'

0 commit comments

Comments
 (0)