Skip to content

Commit bc385b7

Browse files
enhanced the tests for PR #105
1 parent 839b6de commit bc385b7

9 files changed

Lines changed: 112 additions & 24 deletions

lib/bundle.js

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

test/specs/bundle/bundle.spec.js

Lines changed: 0 additions & 17 deletions
This file was deleted.

test/specs/deep/deep.spec.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,3 @@ describe('Schema with deeply-nested $refs', function () {
4949
});
5050
});
5151
});
52-

test/specs/bundle/inner.yaml renamed to test/specs/external-multiple/definitions.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
User:
32
type: object
43
required: [name]
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
helper.bundled.externalMultiple = {
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+
$ref: '#/properties/user/example'
25+
}
26+
}
27+
};

test/specs/bundle/bundled.dereferenced.js renamed to test/specs/external-multiple/external-multiple.dereferenced.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
helper.dereferenced.bundled = {
1+
helper.dereferenced.externalMultiple = {
22
type: 'object',
33
required: ['user', 'token'],
44
properties: {
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
helper.parsed.externalMultiple = {
2+
schema: {
3+
type: 'object',
4+
required: ['user', 'token'],
5+
properties: {
6+
token: {
7+
type: 'string'
8+
},
9+
user: {
10+
$ref: 'definitions.yaml#/User'
11+
}
12+
},
13+
example: {
14+
token: '11111111',
15+
user: {
16+
$ref: 'definitions.yaml#/User/example'
17+
}
18+
}
19+
},
20+
21+
definitions: {
22+
User: {
23+
type: 'object',
24+
required: ['name'],
25+
properties: {
26+
name: {
27+
type: 'string'
28+
}
29+
},
30+
example: {
31+
name: 'Homer'
32+
}
33+
}
34+
}
35+
};
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
describe('Schema with multiple external $refs to different parts of a file', function () {
2+
'use strict';
3+
4+
it('should parse successfully', function () {
5+
var parser = new $RefParser();
6+
return parser
7+
.parse(path.abs('specs/external-multiple/external-multiple.yaml'))
8+
.then(function (schema) {
9+
expect(schema).to.equal(parser.schema);
10+
expect(schema).to.deep.equal(helper.parsed.externalMultiple.schema);
11+
expect(parser.$refs.paths()).to.deep.equal([path.abs('specs/external-multiple/external-multiple.yaml')]);
12+
});
13+
});
14+
15+
it('should resolve successfully', helper.testResolve(
16+
path.rel('specs/external-multiple/external-multiple.yaml'),
17+
path.abs('specs/external-multiple/external-multiple.yaml'), helper.parsed.externalMultiple.schema,
18+
path.abs('specs/external-multiple/definitions.yaml'), helper.parsed.externalMultiple.definitions
19+
));
20+
21+
it('should dereference successfully', function () {
22+
var parser = new $RefParser();
23+
return parser
24+
.dereference(path.rel('specs/external-multiple/external-multiple.yaml'))
25+
.then(function (schema) {
26+
expect(schema).to.equal(parser.schema);
27+
expect(schema).to.deep.equal(helper.dereferenced.externalMultiple);
28+
29+
// Reference equality
30+
expect(schema.properties.user.example).to.equal(schema.example.user);
31+
32+
// The "circular" flag should NOT be set
33+
expect(parser.$refs.circular).to.equal(false);
34+
});
35+
});
36+
37+
it('should bundle successfully', function () {
38+
var parser = new $RefParser();
39+
return parser
40+
.bundle(path.rel('specs/external-multiple/external-multiple.yaml'))
41+
.then(function (schema) {
42+
expect(schema).to.equal(parser.schema);
43+
expect(schema).to.deep.equal(helper.bundled.externalMultiple);
44+
});
45+
});
46+
});

test/specs/bundle/outter.yaml renamed to test/specs/external-multiple/external-multiple.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
21
type: object
32
required: [user, token]
43
properties:
54
token:
65
type: string
76
user:
8-
$ref: './inner.yaml#/User'
7+
$ref: 'definitions.yaml#/User'
98
example:
109
token: '11111111'
1110
user:
12-
$ref: './inner.yaml#/User/example'
11+
$ref: 'definitions.yaml#/User/example'

0 commit comments

Comments
 (0)