Skip to content

Commit aeb8f31

Browse files
committed
Merge pull request #534 from swagger-api/develop_2.0
Prepare for release
2 parents b20a805 + 43de59e commit aeb8f31

22 files changed

+2934
-31602
lines changed

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
## Pull Requests
2-
Plase make your pull requests are made to the [**`develop_2.0`**](https://github.com/swagger-api/swagger-js/tree/develop_2.0) branch at this time.
2+
Please open your pull requests against the [**`develop_2.0`**](https://github.com/swagger-api/swagger-js/tree/develop_2.0) branch at this time.

browser/swagger-client.js

+1,751-1,729
Large diffs are not rendered by default.

browser/swagger-client.min.js

+337-29,354
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gulpfile.js

+4
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ gulp.task('build', function (cb) {
7777
standalone: 'SwaggerClient'
7878
});
7979

80+
if (!useDebug) {
81+
b.transform({global: true}, 'uglifyify');
82+
}
83+
8084
b.transform('brfs')
8185
.bundle()
8286
.pipe(source(basename + (!useDebug ? '.min' : '') + '.js'))

index.js

+1
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,4 @@ SwaggerClient.PasswordAuthorization = auth.PasswordAuthorization;
4040
SwaggerClient.CookieAuthorization = auth.CookieAuthorization;
4141
SwaggerClient.SwaggerApi = deprecationWrapper;
4242
SwaggerClient.SwaggerClient = deprecationWrapper;
43+
SwaggerClient.SchemaMarkup = require('./lib/schema-markup');

lib/auth.js

+17-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22

3+
var helpers = require('./helpers');
34
var btoa = require('btoa'); // jshint ignore:line
45
var CookieJar = require('cookiejar');
56
var _ = {
@@ -22,7 +23,7 @@ var SwaggerAuthorizations = module.exports.SwaggerAuthorizations = function (aut
2223
*
2324
*/
2425
SwaggerAuthorizations.prototype.add = function (name, auth) {
25-
if(name && typeof name === 'object') {
26+
if(_.isObject(name)) {
2627
for (var key in name) {
2728
this.authz[key] = name[key];
2829
}
@@ -38,7 +39,7 @@ SwaggerAuthorizations.prototype.remove = function (name) {
3839
};
3940

4041
SwaggerAuthorizations.prototype.apply = function (obj, securities) {
41-
var status = null;
42+
var status = true;
4243
var applyAll = !securities;
4344
var flattenedSecurities = [];
4445

@@ -58,7 +59,8 @@ SwaggerAuthorizations.prototype.apply = function (obj, securities) {
5859

5960
_.each(this.authz, function (auth, authName) {
6061
if(applyAll || _.includes(flattenedSecurities, authName)) {
61-
status = status || !!auth.apply(obj); // logical ORs regarding status
62+
var newStatus = auth.apply(obj);
63+
status = status && !!newStatus; // logical ORs regarding status
6264
}
6365
});
6466

@@ -84,7 +86,9 @@ ApiKeyAuthorization.prototype.apply = function (obj) {
8486

8587
return true;
8688
} else if (this.type === 'header') {
87-
obj.headers[this.name] = this.value;
89+
if(typeof obj.headers[this.name] === 'undefined') {
90+
obj.headers[this.name] = this.value;
91+
}
8892

8993
return true;
9094
}
@@ -104,14 +108,20 @@ CookieAuthorization.prototype.apply = function (obj) {
104108
/**
105109
* Password Authorization is a basic auth implementation
106110
*/
107-
var PasswordAuthorization = module.exports.PasswordAuthorization = function (name, username, password) {
108-
this.name = name;
111+
var PasswordAuthorization = module.exports.PasswordAuthorization = function (username, password) {
112+
if (arguments.length === 3) {
113+
helpers.log('PasswordAuthorization: the \'name\' argument has been removed, pass only username and password');
114+
username = arguments[1];
115+
password = arguments[2];
116+
}
109117
this.username = username;
110118
this.password = password;
111119
};
112120

113121
PasswordAuthorization.prototype.apply = function (obj) {
114-
obj.headers.Authorization = 'Basic ' + btoa(this.username + ':' + this.password);
122+
if(typeof obj.headers.Authorization === 'undefined') {
123+
obj.headers.Authorization = 'Basic ' + btoa(this.username + ':' + this.password);
124+
}
115125

116126
return true;
117127
};

lib/client.js

+38-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ var _ = {
77
forEach: require('lodash-compat/collection/forEach'),
88
indexOf: require('lodash-compat/array/indexOf'),
99
isArray: require('lodash-compat/lang/isArray'),
10+
isObject: require('lodash-compat/lang/isObject'),
1011
isFunction: require('lodash-compat/lang/isFunction'),
1112
isPlainObject: require('lodash-compat/lang/isPlainObject'),
1213
isUndefined: require('lodash-compat/lang/isUndefined')
@@ -92,6 +93,7 @@ var SwaggerClient = module.exports = function (url, options) {
9293
this.resourceCount = 0;
9394
this.url = null;
9495
this.useJQuery = false;
96+
this.swaggerObject = {}
9597

9698
this.clientAuthorizations = new auth.SwaggerAuthorizations();
9799

@@ -108,7 +110,7 @@ SwaggerClient.prototype.initialize = function (url, options) {
108110

109111
if (typeof url === 'string') {
110112
this.url = url;
111-
} else if (typeof url === 'object') {
113+
} else if (_.isObject(url)) {
112114
options = url;
113115
this.url = options.url;
114116
}
@@ -178,6 +180,7 @@ SwaggerClient.prototype.build = function (mock) {
178180
}
179181

180182
self.swaggerVersion = responseObj.swaggerVersion;
183+
self.swaggerObject = responseObj
181184

182185
if (responseObj.swagger && parseInt(responseObj.swagger) === 2) {
183186
self.swaggerVersion = responseObj.swagger;
@@ -187,8 +190,11 @@ SwaggerClient.prototype.build = function (mock) {
187190
self.isValid = true;
188191
} else {
189192
var converter = new SwaggerSpecConverter();
193+
self.oldSwaggerObject = self.swaggerObject
194+
190195
converter.setDocumentationLocation(self.url);
191196
converter.convert(responseObj, self.clientAuthorizations, function(spec) {
197+
self.swaggerObject = spec
192198
new Resolver().resolve(spec, self.url, self.buildFromSpec, self);
193199
self.isValid = true;
194200
});
@@ -198,9 +204,10 @@ SwaggerClient.prototype.build = function (mock) {
198204
};
199205

200206
if (this.spec) {
207+
self.swaggerObject = this.spec
201208
setTimeout(function () {
202209
new Resolver().resolve(self.spec, self.buildFromSpec, self);
203-
}, 10);
210+
}, 10);
204211
} else {
205212
this.clientAuthorizations.apply(obj);
206213

@@ -470,8 +477,36 @@ SwaggerClient.prototype.idFromOp = function (path, httpMethod, op) {
470477
return opId;
471478
};
472479

480+
SwaggerClient.prototype.setHost = function (host) {
481+
this.host = host;
482+
483+
if(this.apis) {
484+
_.forEach(this.apis, function(api) {
485+
if(api.operations) {
486+
_.forEach(api.operations, function(operation) {
487+
operation.host = host;
488+
});
489+
}
490+
});
491+
}
492+
};
493+
494+
SwaggerClient.prototype.setBasePath = function (basePath) {
495+
this.basePath = basePath;
496+
497+
if(this.apis) {
498+
_.forEach(this.apis, function(api) {
499+
if(api.operations) {
500+
_.forEach(api.operations, function(operation) {
501+
operation.basePath = basePath;
502+
});
503+
}
504+
});
505+
}
506+
};
507+
473508
SwaggerClient.prototype.fail = function (message) {
474509
this.failure(message);
475510

476511
throw message;
477-
};
512+
};

lib/helpers.js

+3-73
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
'use strict';
22

33
var _ = {
4-
isPlainObject: require('lodash-compat/lang/isPlainObject')
4+
isPlainObject: require('lodash-compat/lang/isPlainObject'),
5+
indexOf: require('lodash-compat/array/indexOf')
56
};
67

78
module.exports.__bind = function (fn, me) {
@@ -21,7 +22,7 @@ module.exports.fail = function (message) {
2122
log(message);
2223
};
2324

24-
module.exports.optionHtml = function (label, value) {
25+
var optionHtml = module.exports.optionHtml = function (label, value) {
2526
return '<tr><td class="optionName">' + label + ':</td><td>' + value + '</td></tr>';
2627
};
2728

@@ -33,34 +34,6 @@ var resolveSchema = module.exports.resolveSchema = function (schema) {
3334
return schema;
3435
};
3536

36-
module.exports.typeFromJsonSchema = function (type, format) {
37-
var str;
38-
39-
if (type === 'integer' && format === 'int32') {
40-
str = 'integer';
41-
} else if (type === 'integer' && format === 'int64') {
42-
str = 'long';
43-
} else if (type === 'integer' && typeof format === 'undefined') {
44-
str = 'long';
45-
} else if (type === 'string' && format === 'date-time') {
46-
str = 'date-time';
47-
} else if (type === 'string' && format === 'date') {
48-
str = 'date';
49-
} else if (type === 'number' && format === 'float') {
50-
str = 'float';
51-
} else if (type === 'number' && format === 'double') {
52-
str = 'double';
53-
} else if (type === 'number' && typeof format === 'undefined') {
54-
str = 'double';
55-
} else if (type === 'boolean') {
56-
str = 'boolean';
57-
} else if (type === 'string') {
58-
str = 'string';
59-
}
60-
61-
return str;
62-
};
63-
6437
var simpleRef = module.exports.simpleRef = function (name) {
6538
if (typeof name === 'undefined') {
6639
return null;
@@ -73,46 +46,3 @@ var simpleRef = module.exports.simpleRef = function (name) {
7346
}
7447
};
7548

76-
var getStringSignature = module.exports.getStringSignature = function (obj, baseComponent) {
77-
var str = '';
78-
79-
if (typeof obj.$ref !== 'undefined') {
80-
str += simpleRef(obj.$ref);
81-
} else if (typeof obj.type === 'undefined') {
82-
str += 'object';
83-
} else if (obj.type === 'array') {
84-
if (baseComponent) {
85-
str += getStringSignature((obj.items || obj.$ref || {}));
86-
} else {
87-
str += 'Array[';
88-
str += getStringSignature((obj.items || obj.$ref || {}));
89-
str += ']';
90-
}
91-
} else if (obj.type === 'integer' && obj.format === 'int32') {
92-
str += 'integer';
93-
} else if (obj.type === 'integer' && obj.format === 'int64') {
94-
str += 'long';
95-
} else if (obj.type === 'integer' && typeof obj.format === 'undefined') {
96-
str += 'long';
97-
} else if (obj.type === 'string' && obj.format === 'date-time') {
98-
str += 'date-time';
99-
} else if (obj.type === 'string' && obj.format === 'date') {
100-
str += 'date';
101-
} else if (obj.type === 'string' && typeof obj.format === 'undefined') {
102-
str += 'string';
103-
} else if (obj.type === 'number' && obj.format === 'float') {
104-
str += 'float';
105-
} else if (obj.type === 'number' && obj.format === 'double') {
106-
str += 'double';
107-
} else if (obj.type === 'number' && typeof obj.format === 'undefined') {
108-
str += 'double';
109-
} else if (obj.type === 'boolean') {
110-
str += 'boolean';
111-
} else if (obj.$ref) {
112-
str += simpleRef(obj.$ref);
113-
} else {
114-
str += obj.type;
115-
}
116-
117-
return str;
118-
};

lib/http.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ var helpers = require('./helpers');
44
var jQuery = require('jquery');
55
var request = require('superagent');
66
var jsyaml = require('js-yaml');
7+
var _ = {
8+
isObject: require('lodash-compat/lang/isObject')
9+
};
710

811
/*
912
* JQueryHttpClient is a light-weight, node or browser HTTP client
@@ -49,7 +52,7 @@ SwaggerHttp.prototype.execute = function (obj, opts) {
4952
};
5053

5154

52-
if (obj && typeof obj.body === 'object') {
55+
if (_.isObject(obj) && _.isObject(obj.body)) {
5356
// special processing for file uploads via jquery
5457
if (obj.body.type && obj.body.type === 'formData'){
5558
obj.contentType = false;

0 commit comments

Comments
 (0)