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
18 changes: 14 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.

14 changes: 12 additions & 2 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,11 +325,21 @@ SwaggerClient.prototype.buildFromSpec = function (response) {
} else if (typeof this.scheme === 'undefined') {
if(typeof window !== 'undefined') {
var scheme = window.location.protocol.replace(':','');
if(this.schemes.indexOf(scheme) !== -1) {
if(scheme === 'https' && this.schemes.indexOf(scheme) === -1) {
// can't call http from https served page in a browser!
helpers.log('Cannot call a http server from https inside a browser!');
this.scheme = 'http';
}
else if(this.schemes.indexOf(scheme) !== -1) {
this.scheme = scheme;
}
else {
this.scheme = 'http';
if(this.schemes.indexOf('https') !== -1) {
this.scheme = 'https';
}
else {
this.scheme = 'http';
}
}
}
else {
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.21",
"version": "2.2.21",
"homepage": "http://swagger.io",
"repository": {
"type": "git",
Expand Down
35 changes: 33 additions & 2 deletions test/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -1409,7 +1409,6 @@ describe('SwaggerClient', function () {
});
});


it('should read a blob', function(done) {
var spec = {
paths: {
Expand Down Expand Up @@ -1440,7 +1439,6 @@ describe('SwaggerClient', function () {
}).then(function(client) {
client.test.getBlob({})
.then(function (response) {
console.log('horray');
var filename = './file.tmp';
fs.writeFile(filename, response.data, function(err) {
if(err) {
Expand All @@ -1459,4 +1457,37 @@ describe('SwaggerClient', function () {
done(exception);
});
});


it('should honor schemes', function(done) {
var spec = {
schemes: ['https'],
paths: {
'/v2/nada': {
get: {
operationId: 'getNothing',
tags: [ 'test' ],
parameters: [],
responses: {
default: {
description: 'ok'
}
}
}
}
}
};

var output = new SwaggerClient({
url: 'http://localhost:8000',
spec: spec,
usePromise: true
}).then(function(client) {
var mock = client.test.getNothing({},{mock: true});
expect(mock.url).toEqual('https://localhost:8000/v2/nada');
done();
}).catch(function(exception) {
done(exception);
});
});
});
2 changes: 1 addition & 1 deletion test/spec/v2/spec1.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"host": "localhost:8000",
"basePath": "/v2/api",
"schemes": [
"http"
"https"
],
"tags": [
{
Expand Down