Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions browser/swagger-client.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions browser/swagger-client.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ SwaggerClient.prototype.build = function (mock) {
},
on: {
error: function (response) {
if (self.url.substring(0, 4) !== 'http') {
if (self && self.url && self.url.substring(0, 4) !== 'http') {
return self.fail('Please specify the protocol for ' + self.url);
} else if (response.errObj && (response.errObj.code === 'ECONNABORTED' || response.errObj.message.indexOf('timeout') !== -1)) {
return self.fail('Request timed out after ' + self.fetchSpecTimeout + 'ms');
Expand Down Expand Up @@ -259,7 +259,7 @@ SwaggerClient.prototype.build = function (mock) {
obj.timeout = this.fetchSpecTimeout;
}

if (this.spec) {
if (this.spec && typeof this.spec === 'object') {
self.swaggerObject = this.spec;
setTimeout(function () {
new Resolver().resolve(self.spec, self.url, self.buildFromSpec, self);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
}
],
"description": "swagger-client is a javascript client for use with swaggering APIs.",
"version": "2.1.29",
"version": "2.1.30",
"homepage": "http://swagger.io",
"repository": {
"type": "git",
Expand Down
55 changes: 55 additions & 0 deletions test/durability.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* global after, before, describe, it */

'use strict';

var expect = require('expect');
var test = require('unit.js');
var SwaggerClient = require('..');

var petstoreRaw = require('./spec/v2/petstore.json');


describe('swagger resolver', function () {
it('fails gracefully with bad spec', function(done) {
new SwaggerClient({
spec: 'bad',
usePromise: true
}).then(function(client) {
done('should have failed');
}).catch(function(err) {
done();
})
});

it('fails gracefully with bad URL', function(done) {
new SwaggerClient({
url: 'http://fake.fake/swagger.json',
usePromise: true
}).then(function(client) {
done('should have failed');
}).catch(function(err) {
done();
})
});

it('fails gracefully with operation', function(done) {
new SwaggerClient({
spec: petstoreRaw,
usePromise: true
}).then(function(client) {
client.pet.getPetById({petId: 3})
.then(function(data) {
console.log('ok')
console.log(data);
done('should have failed');
})
.catch(function(error) {
console.log('error')
console.log(error);
done();
})
}).catch(function(err) {
done('should have failed');
})
});
});