Skip to content

Commit 25aaa4a

Browse files
committed
merged with master
2 parents 0e8eb0c + 9407ae6 commit 25aaa4a

File tree

8 files changed

+79
-16
lines changed

8 files changed

+79
-16
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "swagger-js",
3-
"version": "2.1.11",
3+
"version": "2.1.22",
44
"main": "browser/swagger-client.js",
55
"ignore": [
66
"gulpfile.js",

browser/swagger-client.js

Lines changed: 23 additions & 6 deletions
Large diffs are not rendered by default.

browser/swagger-client.min.js

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

lib/client.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ SwaggerClient.prototype.initialize = function (url, options) {
136136
this.defaultSuccessCallback = options.defaultSuccessCallback || null;
137137
this.defaultErrorCallback = options.defaultErrorCallback || null;
138138
this.modelPropertyMacro = options.modelPropertyMacro || null;
139+
this.connectionAgent = options.connectionAgent || null;
139140
this.parameterMacro = options.parameterMacro || null;
140141
this.usePromise = options.usePromise || null;
141142

@@ -201,6 +202,7 @@ SwaggerClient.prototype.build = function (mock) {
201202
var obj = {
202203
useJQuery: this.useJQuery,
203204
jqueryAjaxCache: this.jqueryAjaxCache,
205+
connectionAgent: this.connectionAgent,
204206
url: this.url,
205207
method: 'get',
206208
headers: {
@@ -352,11 +354,21 @@ SwaggerClient.prototype.buildFromSpec = function (response) {
352354
} else if (typeof this.scheme === 'undefined') {
353355
if(typeof window !== 'undefined') {
354356
var scheme = window.location.protocol.replace(':','');
355-
if(this.schemes.indexOf(scheme) !== -1) {
357+
if(scheme === 'https' && this.schemes.indexOf(scheme) === -1) {
358+
// can't call http from https served page in a browser!
359+
helpers.log('Cannot call a http server from https inside a browser!');
360+
this.scheme = 'http';
361+
}
362+
else if(this.schemes.indexOf(scheme) !== -1) {
356363
this.scheme = scheme;
357364
}
358365
else {
359-
this.scheme = 'http';
366+
if(this.schemes.indexOf('https') !== -1) {
367+
this.scheme = 'https';
368+
}
369+
else {
370+
this.scheme = 'http';
371+
}
360372
}
361373
}
362374
else {

lib/http.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ JQueryHttpClient.prototype.execute = function (obj) {
207207
};
208208

209209
SuperagentHttpClient.prototype.execute = function (obj) {
210+
var connectionAgent = obj.connectionAgent;
210211
var method = obj.method.toLowerCase();
211212
var timeout = obj.timeout;
212213

@@ -216,6 +217,10 @@ SuperagentHttpClient.prototype.execute = function (obj) {
216217
var headers = obj.headers || {};
217218
var r = request[method](obj.url);
218219

220+
if (connectionAgent) {
221+
r.agent(connectionAgent);
222+
}
223+
219224
if (timeout) {
220225
r.timeout(timeout);
221226
}
@@ -240,7 +245,7 @@ SuperagentHttpClient.prototype.execute = function (obj) {
240245
if (contentType.indexOf('multipart/form-data') === 0) {
241246
delete headers['Content-Type'];
242247
if({}.toString.apply(obj.body) === '[object FormData]') {
243-
var itr = obj.body.keys();
248+
var itr = _.keys(obj);
244249
var p = [];
245250
while(true) {
246251
var v = itr.next();

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
}
99
],
1010
"description": "swagger-client is a javascript client for use with swaggering APIs.",
11-
"version": "2.1.21",
11+
"version": "2.1.22",
1212
"homepage": "http://swagger.io",
1313
"repository": {
1414
"type": "git",

test/client.js

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1439,7 +1439,6 @@ describe('SwaggerClient', function () {
14391439
}).then(function(client) {
14401440
client.test.getBlob({})
14411441
.then(function (response) {
1442-
console.log('horray');
14431442
var filename = './file.tmp';
14441443
fs.writeFile(filename, response.data, function(err) {
14451444
if(err) {
@@ -1459,6 +1458,36 @@ describe('SwaggerClient', function () {
14591458
});
14601459
});
14611460

1461+
it('should honor schemes', function(done) {
1462+
var spec = {
1463+
schemes: ['https'],
1464+
paths: {
1465+
'/v2/nada': {
1466+
get: {
1467+
operationId: 'getNothing',
1468+
tags: [ 'test' ],
1469+
parameters: [],
1470+
responses: {
1471+
default: {
1472+
description: 'ok'
1473+
}
1474+
}
1475+
}
1476+
}
1477+
}
1478+
};
1479+
1480+
var output = new SwaggerClient({
1481+
url: 'http://localhost:8000',
1482+
spec: spec,
1483+
usePromise: true
1484+
}).then(function(client) {
1485+
var mock = client.test.getNothing({},{mock: true});
1486+
expect(mock.url).toEqual('https://localhost:8000/v2/nada');
1487+
done();
1488+
});
1489+
});
1490+
14621491
it('should read vendor extensions', function(done) {
14631492
new SwaggerClient({
14641493
url: 'http://localhost:8000/v2/extensions.yaml',

test/spec/v2/spec1.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"host": "localhost:8000",
2121
"basePath": "/v2/api",
2222
"schemes": [
23-
"http"
23+
"https"
2424
],
2525
"tags": [
2626
{

0 commit comments

Comments
 (0)