Skip to content

Commit 448af69

Browse files
committed
Merge pull request #718 from swagger-api/issue-708
removed duplicate recursion code
2 parents d8bf14e + 57b1563 commit 448af69

File tree

9 files changed

+803
-6845
lines changed

9 files changed

+803
-6845
lines changed

browser/swagger-client.js

Lines changed: 619 additions & 6674 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

browser/swagger-client.min.js

Lines changed: 132 additions & 146 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/resolver.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ var _ = {
1111
/**
1212
* Resolves a spec's remote references
1313
*/
14-
var Resolver = module.exports = function () {};
14+
var Resolver = module.exports = function () {
15+
this.failedUrls = [];
16+
};
1517

1618
Resolver.prototype.processAllOf = function(root, name, definition, resolutionTable, unresolvedRefs, spec) {
1719
var i, location, property;
@@ -273,7 +275,7 @@ Resolver.prototype.resolve = function (spec, arg1, arg2, arg3) {
273275
self.finish(spec, root, resolutionTable, resolvedRefs, unresolvedRefs, callback, true);
274276
}
275277
}
276-
else {
278+
else if(self.failedUrls.indexOf(item.root) === -1) {
277279
var obj = {
278280
useJQuery: false, // TODO
279281
url: item.root,
@@ -284,6 +286,8 @@ Resolver.prototype.resolve = function (spec, arg1, arg2, arg3) {
284286
on: {
285287
error: function (error) {
286288
processedCalls += 1;
289+
console.log('failed url: ' + obj.url);
290+
self.failedUrls.push(obj.url);
287291
unresolvedRefs[item.key] = {
288292
root: item.root,
289293
location: item.location
@@ -311,6 +315,16 @@ Resolver.prototype.resolve = function (spec, arg1, arg2, arg3) {
311315

312316
new SwaggerHttp().execute(obj, opts);
313317
}
318+
else {
319+
processedCalls += 1;
320+
unresolvedRefs[item.key] = {
321+
root: item.root,
322+
location: item.location
323+
};
324+
if (processedCalls === expectedCalls) {
325+
self.finish(spec, _root, resolutionTable, resolvedRefs, unresolvedRefs, callback);
326+
}
327+
}
314328
}(toResolve[ii], spec, this));
315329
}
316330

@@ -735,8 +749,5 @@ Resolver.prototype.resolveAllOf = function(spec, obj, depth) {
735749
obj[key] = output;
736750
}
737751
}
738-
if(_.isObject(item)) {
739-
this.resolveAllOf(spec, item, depth + 1);
740-
}
741752
}
742753
};

test/auth.js

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ var auth = require('../lib/auth');
1616
*/
1717

1818
describe('2.0 authorizations', function () {
19-
20-
2119
before(function(){
2220
fauxjax.install();
2321
});
@@ -38,7 +36,6 @@ describe('2.0 authorizations', function () {
3836
});
3937

4038
it('adds given hash to the auth object', function(){
41-
4239
// I don't really care what it adds...
4340
var auth = {foo: 'bar'};
4441
var client = new Swagger({
@@ -50,7 +47,8 @@ describe('2.0 authorizations', function () {
5047
expect(client.clientAuthorizations.authz.someAuth).to.equal(auth);
5148

5249
});
53-
50+
/*
51+
// re-enable after https://github.com/swagger-api/swagger-js/issues/711
5452
it('should have auth available when fetching the spec', function(done){
5553
var url = 'http://example.com/not_important';
5654
@@ -77,9 +75,8 @@ describe('2.0 authorizations', function () {
7775
},
7876
failure: function (err) { throw err; }
7977
});
80-
81-
8278
});
79+
*/
8380

8481
it('should have clientAuthorizations instantiated before #initialize', function(){
8582
var client = new Swagger(); // don't initialize here, no-args
@@ -173,23 +170,23 @@ describe('2.0 authorizations', function () {
173170
expect(req.headers.Authorization).to.equal('foo');
174171
});
175172

176-
it('applies multiple auths', function (done) {
177173

174+
/*
175+
// re-enable after https://github.com/swagger-api/swagger-js/issues/711
176+
177+
it('applies multiple auths', function (done) {
178178
var url = 'http://example.com/multiple_auths';
179179
180180
// Mock out the request, will only allow one request
181181
fauxjax.once('request', function (req) {
182-
183182
expect(req.requestHeaders).to.include.keys('auth');
184183
expect(req.requestHeaders.auth).to.equal('val');
185184
186185
expect(req.requestHeaders).to.include.keys('auth1');
187186
expect(req.requestHeaders.auth1).to.equal('val1');
188187
189-
190188
// Send something back, so we don't crash swagger
191189
req.respond( 200, { }, JSON.stringify({swagger: '2.0', title: 'test'}));
192-
193190
});
194191
195192
var swag = new Swagger({
@@ -210,7 +207,6 @@ describe('2.0 authorizations', function () {
210207
},
211208
failure: function (err) { throw err; }
212209
});
213-
214210
});
215-
211+
*/
216212
});

test/both/http.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ var petstoreYaml = fs.readFileSync(__dirname + '/../spec/v2/petstore.yaml', 'utf
99
var petstore;
1010

1111
describe('yaml http', function () {
12-
1312
before(function(){
1413
fauxjax.install();
1514
});
@@ -20,6 +19,8 @@ describe('yaml http', function () {
2019
});
2120

2221
describe('superagent', function(){
22+
/*
23+
// re-enable after https://github.com/swagger-api/swagger-js/issues/711
2324
2425
it('should fetch/parse petstore.yaml', function(done){
2526
// Mock our request
@@ -44,7 +45,7 @@ describe('yaml http', function () {
4445
done();
4546
}
4647
});
47-
48+
*/
4849

4950
// it('should parse yaml with the resolver', function(done){
5051
// var baseSpec = 'swagger: "2.0"';
@@ -109,5 +110,4 @@ describe('yaml http', function () {
109110
// });
110111

111112
});
112-
113113
});

test/client.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ describe('SwaggerClient', function () {
540540
};
541541

542542
new SwaggerClient({
543-
url: 'http://petstore.swagger.io/v2/swagger.json',
543+
url: 'http://localhost:8000/v2/petstore.json',
544544
usePromise: true,
545545
requestInterceptor: interceptor.requestInterceptor,
546546
responseInterceptor: interceptor.responseInterceptor

test/http.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ var sample, instance;
88

99

1010
describe('yaml http', function () {
11-
1211
describe('superagent', function(){
13-
1412
before(function (done) {
1513
mock.petstore(done,{
1614
url: 'http://localhost:8000/v2/petstore.yaml'

test/request.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ describe('swagger basePath override functions', function () {
411411
apply: function(data) {
412412
// rewrites an invalid pet id (-100) to be valid (1)
413413
// you can do what you want here, like inject headers, etc.
414-
data.url = 'http://petstore.swagger.io/v2/pet/1';
414+
data.url = 'http://localhost:8000/v2/api/pet/1';
415415
return data;
416416
}
417417
};

test/resolver.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,29 @@ describe('swagger resolver', function () {
3232
});
3333
});
3434

35+
it('gracefully handles invalid remote references', function(done) {
36+
var api = new Resolver();
37+
var spec = {
38+
paths: {
39+
'/foo': {
40+
get: {
41+
responses: {
42+
200: {
43+
description: 'a two-hundie',
44+
schema: {
45+
$ref: 'im_not_here'
46+
}
47+
}
48+
}
49+
}
50+
}
51+
}
52+
}
53+
api.resolve(spec, 'http://localhost:8080/v2/petstore.json', function (spec) {
54+
done();
55+
});
56+
});
57+
3558
it('resolves a remote model property reference $ref', function (done) {
3659
var api = new Resolver();
3760
var spec = {
@@ -981,7 +1004,6 @@ describe('swagger resolver', function () {
9811004

9821005

9831006
parameters = spec.paths['/foo'].post.parameters;
984-
console.log(parameters);
9851007
done();
9861008
});
9871009
});

0 commit comments

Comments
 (0)