Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

swagger-client

Package Overview
Dependencies
Maintainers
2
Versions
295
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

swagger-client - npm Package Compare versions

Comparing version 2.1.14 to 2.1.15

17

lib/client.js

@@ -69,3 +69,4 @@ 'use strict';

'url',
'useJQuery'
'useJQuery',
'jqueryAjaxCache'
];

@@ -102,2 +103,3 @@ // We have to keep track of the function/property names to avoid collisions for tag names which are used to allow the

this.useJQuery = false;
this.jqueryAjaxCache = false;
this.swaggerObject = {};

@@ -126,2 +128,9 @@ this.deferredClient = undefined;

if(this.url && this.url.indexOf('http') === -1) {
// no protocol, so we can only use window if it exists
if(window && window.location) {
this.url = window.location.origin + this.url;
}
}
options = options || {};

@@ -144,3 +153,2 @@ this.clientAuthorizations.add(options.authorizations);

}
if (options.useJQuery) {

@@ -150,2 +158,6 @@ this.useJQuery = options.useJQuery;

if (options.jqueryAjaxCache) {
this.jqueryAjaxCache = options.jqueryAjaxCache;
}
if (options.enableCookies) {

@@ -183,2 +195,3 @@ this.enableCookies = options.enableCookies;

useJQuery: this.useJQuery,
jqueryAjaxCache: this.jqueryAjaxCache,
url: this.url,

@@ -185,0 +198,0 @@ method: 'get',

@@ -60,2 +60,3 @@ 'use strict';

var success = obj.on.response;
var error = obj.on.error;

@@ -76,2 +77,13 @@ var requestInterceptor = function(data) {

var errorInterceptor = function(data) {
if(opts && opts.responseInterceptor) {
data = opts.responseInterceptor.apply(data);
}
error(data);
};
obj.on.error = function(data) {
errorInterceptor(data);
};
obj.on.response = function(data) {

@@ -84,8 +96,7 @@ responseInterceptor(data);

if (obj.body.type && obj.body.type === 'formData'){
obj.contentType = false;
obj.processData = false;
delete obj.headers['Content-Type'];
} else {
obj.body = JSON.stringify(obj.body);
if(opts.useJQuery) {
obj.contentType = false;
obj.processData = false;
delete obj.headers['Content-Type'];
}
}

@@ -134,4 +145,5 @@ }

obj.type = obj.method;
obj.cache = false;
obj.cache = obj.jqueryAjaxCache;
obj.data = obj.body;
delete obj.jqueryAjaxCache;
delete obj.useJQuery;

@@ -208,6 +220,2 @@ delete obj.body;

var r = request[method](obj.url);
var name;
for (name in headers) {
r.set(name, headers[name]);
}

@@ -218,6 +226,48 @@ if (obj.enableCookies) {

if (obj.body) {
r.send(obj.body);
if(obj.body) {
if(_.isObject(obj.body)) {
var contentType = obj.headers['Content-Type'] || '';
if (contentType.indexOf('multipart/form-data') === 0) {
delete headers['Content-Type'];
if({}.toString.apply(obj.body) === '[object FormData]') {
var itr = obj.body.keys();
while(true) {
var v = itr.next();
if(v.done) {
break;
}
var key = v.value;
var value = obj.body.get(key);
console.log({}.toString.apply(value));
if({}.toString.apply(value) === '[object File]') {
r.attach(key, value);
}
else {
r.field(key, value);
}
}
}
else {
var keyname;
for (var keyname in obj.body) {
var value = obj.body[keyname];
r.field(keyname, value);
}
}
}
else if (_.isObject(obj.body)) {
obj.body = JSON.stringify(obj.body);
r.send(obj.body);
}
}
else {
r.send(obj.body);
}
}
var name;
for (name in headers) {
r.set(name, headers[name]);
}
if(typeof r.buffer === 'function') {

@@ -224,0 +274,0 @@ r.buffer(); // force superagent to populate res.text with the raw response data

1

lib/resolver.js

@@ -545,3 +545,2 @@ 'use strict';

if(lastChar !== '/' && (item.indexOf('#') !== 0 && item.indexOf('http://') !== 0 && item.indexOf('https://'))) {
console.log('working with ' + item);
appendHash = false;

@@ -548,0 +547,0 @@ var parts = root.split('\/');

@@ -48,2 +48,3 @@ 'use strict';

this.useJQuery = parent.useJQuery;
this.jqueryAjaxCache = parent.jqueryAjaxCache;
this.enableCookies = parent.enableCookies;

@@ -56,2 +57,6 @@ this.parameterMacro = parent.parameterMacro || function (operation, parameter) {

if(this.basePath !== '/' && this.basePath.slice(-1) == '/') {
this.basePath = this.basePath.slice(0, -1);
}
if (typeof this.deprecated === 'string') {

@@ -452,3 +457,3 @@ switch(this.deprecated.toLowerCase()) {

var formParams = {};
var requestUrl = this.path;
var requestUrl = this.path.replace(/#.*/, ''); // remove URL fragment
var querystring = ''; // grab params from the args, build the querystring along the way

@@ -472,3 +477,3 @@

} else if (param.in === 'query' && typeof args[param.name] !== 'undefined') {
if (querystring === '') {
if (querystring === '' && requestUrl.indexOf('?') < 0) {
querystring += '?';

@@ -485,6 +490,6 @@ } else {

} else {
querystring += this.encodeQueryParam(param.name) + '=' + this.encodeQueryParam(args[param.name]);
querystring += this.encodeQueryKey(param.name) + '=' + this.encodeQueryParam(args[param.name]);
}
} else {
querystring += this.encodeQueryParam(param.name) + '=' + this.encodeQueryParam(args[param.name]);
querystring += this.encodeQueryKey(param.name) + '=' + this.encodeQueryParam(args[param.name]);
}

@@ -531,3 +536,6 @@ } else if (param.in === 'formData') {

} else if (param.in === 'formData') {
formParams[param.name] = args[param.name];
formParams[param.name] = {
param: param,
value: args[param.name]
};
hasFormParams = true;

@@ -561,10 +569,19 @@ }

for (key in formParams) {
value = formParams[key];
var param = formParams[key].param;
value = formParams[key].value;
if (typeof value !== 'undefined') {
if (encoded !== '') {
encoded += '&';
if (Array.isArray(value)) {
if (encoded !== '') {
encoded += '&';
}
encoded += this.encodeQueryCollection(param.collectionFormat, key, value);
}
else {
if (encoded !== '') {
encoded += '&';
}
encoded += encodeURIComponent(key) + '=' + encodeURIComponent(value);
encoded += encodeURIComponent(key) + '=' + encodeURIComponent(value);
}
}

@@ -575,3 +592,3 @@ }

} else if (isMultiPart) {
if (opts.useJQuery) {
if (typeof FormData === 'function') {
var bodyParam = new FormData();

@@ -585,15 +602,57 @@

if (typeof value !== 'undefined') {
// required for jquery file upload
if (value.type === 'file' && value.value) {
delete headers['Content-Type'];
if({}.toString.apply(value) === '[object File]') {
bodyParam.append(key, value);
}
else if (value.type === 'file' && value.value) {
bodyParam.append(key, value.value);
} else {
bodyParam.append(key, value);
if (Array.isArray(value)) {
bodyParam.append(key, this.encodeQueryCollection(param.collectionFormat, key, value));
}
else {
bodyParam.append(key, value);
}
}
}
}
body = bodyParam;
}
else {
bodyParam = {};
for (key in formParams) {
value = args[key];
if (Array.isArray(value)) {
var delimeter;
var format = param.collectionFormat || 'multi';
if(format === 'ssv') {
delimeter = ' ';
}
else if(format === 'pipes') {
delimeter = '|';
}
else if(format === 'tsv') {
delimeter = '\t';
}
else {
delimeter = ',';
}
var data;
value.forEach(function(v) {
if(data) {
data += delimeter;
}
else {
data = '';
}
data += v;
});
bodyParam[key] = data;
}
else {
bodyParam[key] = value;
}
}
body = bodyParam;
}
headers['Content-Type'] = 'multipart/form-data';
}

@@ -691,3 +750,2 @@

if (typeof opts.useJQuery === 'undefined') {

@@ -697,2 +755,6 @@ opts.useJQuery = this.useJQuery;

if (typeof opts.jqueryAjaxCache === 'undefined') {
opts.jqueryAjaxCache = this.jqueryAjaxCache;
}
if (typeof opts.enableCookies === 'undefined') {

@@ -746,2 +808,3 @@ opts.enableCookies = this.enableCookies;

useJQuery: opts.useJQuery,
jqueryAjaxCache: opts.jqueryAjaxCache,
deferred: deferred,

@@ -829,4 +892,5 @@ headers: headers,

// if there's a body, need to set the consumes header via requestContentType
var hasBody = body || definedFileParams.length || definedFormParams.length;
if (this.method === 'post' || this.method === 'put' || this.method === 'patch' ||
((this.method === 'delete' || this.method === 'get') && body) ) {
((this.method === 'delete' || this.method === 'get') && hasBody)) {
if (opts.requestContentType) {

@@ -837,2 +901,3 @@ consumes = opts.requestContentType;

if (definedFormParams.length > 0) {
consumes = undefined;
if (opts.requestContentType) { // override if set

@@ -842,3 +907,15 @@ consumes = opts.requestContentType;

consumes = 'multipart/form-data';
} else { // default to x-www-from-urlencoded
} else {
if (this.consumes && this.consumes.length > 0) {
// use the consumes setting
for(var c in this.consumes) {
var chk = this.consumes[c];
if(chk.indexOf('application/x-www-form-urlencoded') === 0 || chk.indexOf('multipart/form-data') === 0) {
consumes = chk;
}
}
}
}
if(typeof consumes === 'undefined') {
// default to x-www-from-urlencoded
consumes = 'application/x-www-form-urlencoded';

@@ -865,2 +942,5 @@ }

}
else if(this.consumes && this.consumes.length > 0 && this.consumes[0] === 'application/x-www-form-urlencoded') {
headers['Content-Type'] = this.consumes[0];
}

@@ -914,13 +994,73 @@ if (accepts) {

}
var isFormData = false;
var isMultipart = false;
var type = obj.headers['Content-Type'];
if(type && type.indexOf('application/x-www-form-urlencoded') === 0) {
isFormData = true;
}
else if (type && type.indexOf('multipart/form-data') === 0) {
isFormData = true;
isMultipart = true;
}
if (obj.body) {
var body;
if (_.isObject(obj.body)) {
if(isMultipart) {
isMultipart = true;
// add the form data
for(var i = 0; i < this.parameters.length; i++) {
var parameter = this.parameters[i];
if(parameter.in === 'formData') {
if (!body) {
body = '';
}
if (_.isObject(obj.body)) {
body = JSON.stringify(obj.body);
var paramValue;
if(typeof FormData === 'function' && obj.body instanceof FormData) {
paramValue = obj.body.get(parameter.name);
}
else {
paramValue = obj.body[parameter.name];
}
if (paramValue) {
if (parameter.type === 'file') {
if(paramValue.name) {
body += '-F @' + paramValue.name + ' ';
}
}
else {
body += '-F ';
if (Array.isArray(paramValue)) {
body += this.encodeQueryCollection(parameter.collectionFormat, parameter.name, paramValue);
} else {
body += this.encodeQueryKey(parameter.name) + '=' + paramValue;
}
body += ' ';
}
}
}
}
}
if(!body) {
body = JSON.stringify(obj.body);
}
} else {
body = obj.body;
}
// escape @ => %40, ' => %27
body = body.replace(/\'/g, '%27').replace(/\n/g, " \\ \n ");
results.push('-d \'' + body.replace(/\'/g, '\\u0027') + '\'');
if(!isFormData) {
// escape & => %26
body = body.replace(/&/g, '%26');
}
if(isMultipart) {
results.push(body);
}
else {
results.push('-d \'' + body.replace(/@/g, '%40') + '\'');
}
}

@@ -939,3 +1079,3 @@

} else if (type === 'tsv') {
separator = '\\t';
separator = '%09';
} else if (type === 'pipes') {

@@ -962,2 +1102,3 @@ separator = '|';

type = type || 'default';
if (type === 'default' || type === 'multi') {

@@ -967,3 +1108,3 @@ for (i = 0; i < value.length; i++) {

encoded += this.encodeQueryParam(name) + '=' + this.encodeQueryParam(value[i]);
encoded += this.encodeQueryKey(name) + '=' + this.encodeQueryParam(value[i]);
}

@@ -978,3 +1119,3 @@ } else {

} else if (type === 'tsv') {
separator = '\\t';
separator = '%09';
} else if (type === 'pipes') {

@@ -988,3 +1129,3 @@ separator = '|';

encoded += this.encodeQueryParam(name) + '[]=' + this.encodeQueryParam(value[i]);
encoded += this.encodeQueryKey(name) + '[]=' + this.encodeQueryParam(value[i]);
}

@@ -996,3 +1137,3 @@ }

if (i === 0) {
encoded = this.encodeQueryParam(name) + '=' + this.encodeQueryParam(value[i]);
encoded = this.encodeQueryKey(name) + '=' + this.encodeQueryParam(value[i]);
} else {

@@ -1008,2 +1149,7 @@ encoded += separator + this.encodeQueryParam(value[i]);

Operation.prototype.encodeQueryKey = function (arg) {
return encodeURIComponent(arg)
.replace('%5B','[').replace('%5D', ']').replace('%24', '$');
};
Operation.prototype.encodeQueryParam = function (arg) {

@@ -1010,0 +1156,0 @@ return encodeURIComponent(arg);

@@ -11,3 +11,3 @@ {

"description": "swagger-client is a javascript client for use with swaggering APIs.",
"version": "2.1.14",
"version": "2.1.15",
"homepage": "http://swagger.io",

@@ -14,0 +14,0 @@ "repository": {

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc