Skip to content

Commit a8981c6

Browse files
committed
Merge branch 'feature/guard-against-split'
2 parents b0214c2 + c9c0dd0 commit a8981c6

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

lib/client.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ SwaggerClient.prototype.build = function (mock) {
220220
if (this.spec) {
221221
self.swaggerObject = this.spec;
222222
setTimeout(function () {
223-
new Resolver().resolve(self.spec, self.buildFromSpec, self);
223+
new Resolver().resolve(self.spec, self.url, self.buildFromSpec, self);
224224
}, 10);
225225
} else {
226226
this.clientAuthorizations.apply(obj);

lib/resolver.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,8 @@ Resolver.prototype.resolve = function (spec, arg1, arg2, arg3) {
266266
// resolve anything that is local
267267
for(var ii = 0; ii < toResolve.length; ii++) {
268268
(function(item, spec, self) {
269-
if(item.root === null || item.root === root) {
269+
// NOTE: this used to be item.root === null, but I (@ponelat) have added a guard against .split, which means item.root can be ''
270+
if(!item.root || item.root === root) {
270271
// local resolve
271272
self.resolveItem(spec, _root, resolutionTable, resolvedRefs, unresolvedRefs, item);
272273
processedCalls += 1;
@@ -528,6 +529,10 @@ Resolver.prototype.retainRoot = function(obj, root) {
528529
Resolver.prototype.resolveInline = function (root, spec, property, resolutionTable, unresolvedRefs, location) {
529530
var key = property.$ref, ref = property.$ref, i, p, p2, rs;
530531
var rootTrimmed = false;
532+
533+
root = root || '' // Guard against .split. @fehguy, you'll need to check if this logic fits
534+
// More imporantly is how do we gracefully handle relative urls, when provided just a 'spec', not a 'url' ?
535+
531536
if (ref) {
532537
if(ref.indexOf('../') === 0) {
533538
// reset root

test/resolver.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,4 +1351,35 @@ describe('swagger resolver', function () {
13511351
done();
13521352
});
13531353
});
1354+
1355+
it('resolves remote parameters, without providing a root', function(done) {
1356+
var api = new Resolver();
1357+
var spec = {
1358+
swagger:'2.0',
1359+
info:{},
1360+
host:'localhost:9000',
1361+
basePath:'/2.0',
1362+
paths:{
1363+
'/':{
1364+
get:{
1365+
responses:{
1366+
'200':{
1367+
description:'thanks'
1368+
}
1369+
},
1370+
parameters:[
1371+
{
1372+
'$ref': 'http://localhost:8000/v2/parameters.json#/query/skip'
1373+
}
1374+
]
1375+
}
1376+
}
1377+
}
1378+
};
1379+
api.resolve(spec, function (spec, unresolved) {
1380+
expect(spec.paths['/'].get.parameters[0].name).toBe('skip');
1381+
done();
1382+
});
1383+
});
1384+
13541385
});

0 commit comments

Comments
 (0)