swagger-client
Advanced tools
Comparing version 2.1.18 to 2.1.19
@@ -142,2 +142,8 @@ 'use strict'; | ||
// operation request timeout default | ||
this.timeout = options.timeout || null; | ||
// default to request timeout when not specified | ||
this.fetchSpecTimeout = typeof options.fetchSpecTimeout !== 'undefined' | ||
? options.fetchSpecTimeout | ||
: options.timeout || null; | ||
@@ -165,2 +171,6 @@ if(this.usePromise) { | ||
// maybe don't need this? | ||
this.options.timeout = this.timeout; | ||
this.options.fetchSpecTimeout = this.fetchSpecTimeout; | ||
this.supportedSubmitMethods = options.supportedSubmitMethods || []; | ||
@@ -206,2 +216,4 @@ this.failure = options.failure || function (err) { throw err; }; | ||
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'); | ||
} else if (response.status === 0) { | ||
@@ -246,2 +258,7 @@ return self.fail('Can\'t read from server. It may not have the appropriate access-control-origin settings.'); | ||
// only set timeout when specified | ||
if (this.fetchSpecTimeout) { | ||
obj.timeout = this.fetchSpecTimeout; | ||
} | ||
if (this.spec) { | ||
@@ -306,5 +323,22 @@ self.swaggerObject = this.spec; | ||
if (typeof this.scheme === 'undefined' && typeof this.schemes === 'undefined' || this.schemes.length === 0) { | ||
this.scheme = location.scheme || 'http'; | ||
if(typeof window !== 'undefined') { | ||
// use the window scheme | ||
this.scheme = window.location.scheme; | ||
} | ||
else { | ||
this.scheme = location.scheme || 'http'; | ||
} | ||
} else if (typeof this.scheme === 'undefined') { | ||
this.scheme = this.schemes[0] || location.scheme; | ||
if(typeof window !== 'undefined') { | ||
var scheme = window.location.protocol.replace(':',''); | ||
if(this.schemes.indexOf(scheme) !== -1) { | ||
this.scheme = scheme; | ||
} | ||
else { | ||
this.scheme = 'http'; | ||
} | ||
} | ||
else { | ||
this.scheme = this.schemes[0] || location.scheme; | ||
} | ||
} | ||
@@ -311,0 +345,0 @@ |
@@ -211,2 +211,3 @@ 'use strict'; | ||
var method = obj.method.toLowerCase(); | ||
var timeout = obj.timeout; | ||
@@ -219,2 +220,6 @@ if (method === 'delete') { | ||
if (timeout) { | ||
r.timeout(timeout); | ||
} | ||
if (obj.enableCookies) { | ||
@@ -231,2 +236,3 @@ r.withCredentials(); | ||
var itr = obj.body.keys(); | ||
var p = []; | ||
while(true) { | ||
@@ -238,10 +244,20 @@ var v = itr.next(); | ||
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); | ||
// only once | ||
if(p.indexOf(key) === -1) { | ||
p.push(key); | ||
var value = obj.body.getAll(key); | ||
if({}.toString.apply(value) === '[object File]') { | ||
r.attach(key, value); | ||
} | ||
else { | ||
if (Array.isArray(value)) { | ||
for (var v in value) { | ||
r.field(key, value[v]); | ||
} | ||
} | ||
else { | ||
r.field(key, value); | ||
} | ||
} | ||
} | ||
else { | ||
r.field(key, value); | ||
} | ||
} | ||
@@ -253,3 +269,10 @@ } | ||
var value = obj.body[keyname]; | ||
r.field(keyname, value); | ||
if(Array.isArray(value)) { | ||
for(var v in value) { | ||
r.field(keyname, v); | ||
} | ||
} | ||
else { | ||
r.field(keyname, value); | ||
} | ||
} | ||
@@ -256,0 +279,0 @@ } |
@@ -371,2 +371,7 @@ 'use strict'; | ||
// apply timeout only when specified | ||
if (scope && scope.fetchSpecTimeout) { | ||
obj.timeout = scope.fetchSpecTimeout; | ||
} | ||
if (scope && scope.clientAuthorizations) { | ||
@@ -487,3 +492,3 @@ scope.clientAuthorizations.apply(obj); | ||
var abs = resolvedTo.obj[key]; | ||
if (localResolve !== true) { | ||
@@ -566,2 +571,57 @@ // don't retain root for local definitions | ||
function splitUrl(url) { | ||
var result = {}; | ||
var proto = /[a-z]+:\/\//i.exec(url); | ||
if (proto) { | ||
result.proto = proto[0].slice(0, -3); | ||
url = url.slice(result.proto.length + 1); | ||
} | ||
if (url.slice(0, 2) === '//') { | ||
result.domain = url.slice(2).split('/')[0]; | ||
url = url.slice(2 + result.domain.length); | ||
} | ||
var p = url.split('#'); | ||
if (p[0].length) result.path = p[0]; | ||
if (p.length > 1) result.fragment = p.slice(1).join('#'); | ||
return result; | ||
} | ||
function unsplitUrl(url) { | ||
var result = url.path; | ||
if (result === undefined) result = ''; | ||
if (url.fragment !== undefined) result += '#' + url.fragment; | ||
if (url.domain !== undefined) { | ||
if (result.slice(0, 1) === '/') result = result.slice(1); | ||
result = '//' + url.domain + '/' + result; | ||
if (url.proto !== undefined) result = url.proto + ':' + result; | ||
} | ||
return result; | ||
} | ||
function joinUrl(base, rel) { | ||
var relsp = splitUrl(rel); | ||
if (relsp.domain !== undefined) return rel; | ||
var result = splitUrl(base); | ||
if (relsp.path === undefined) { | ||
// change only fragment part | ||
result.fragment = relsp.fragment; | ||
} else if (relsp.path.slice(0, 1) === '/') { | ||
// relative to domain | ||
result.path = relsp.path; | ||
result.fragment = relsp.fragment; | ||
} else { | ||
// relative to path | ||
var path = result.path === undefined ? [] : result.path.split('/'); | ||
var relpath = relsp.path.split('/'); | ||
if (path.length) path.pop(); | ||
while (relpath[0] === '..' || relpath[0] === '.') { | ||
if (relpath[0] === '..') path.pop(); | ||
relpath.shift(); | ||
} | ||
result.path = path.concat(relpath).join('/'); | ||
result.fragment = relsp.fragment; | ||
} | ||
return unsplitUrl(result); | ||
} | ||
Resolver.prototype.retainRoot = function(origKey, obj, root) { | ||
@@ -573,26 +633,3 @@ // walk object and look for relative $refs | ||
if (key === '$ref' && typeof item === 'string') { | ||
// stop and inspect | ||
if (item.indexOf('http:') !== 0 && item.indexOf('https:') !== 0) { | ||
// TODO: check if root ends in '/'. If not, AND item has no protocol, make relative | ||
var appendHash = true; | ||
var oldRoot = root; | ||
if (root) { | ||
var lastChar = root.slice(-1); | ||
if (lastChar !== '/' && (item.indexOf('#') !== 0 && item.indexOf('http:') !== 0 && item.indexOf('https:'))) { | ||
appendHash = false; | ||
var parts = root.split('\/'); | ||
parts = parts.splice(0, parts.length - 1); | ||
root = ''; | ||
for (var i = 0; i < parts.length; i++) { | ||
root += parts[i] + '/'; | ||
} | ||
} | ||
} | ||
if (item.indexOf('#') !== 0 && appendHash) { | ||
item = '#' + item; | ||
} | ||
item = (root || '') + item; | ||
obj[key] = item; | ||
} | ||
obj[key] = joinUrl(root, item); | ||
} | ||
@@ -605,6 +642,3 @@ else if (_.isObject(item)) { | ||
else if(_.isString(obj) && origKey === '$ref') { | ||
// look at the ref? | ||
if(obj.indexOf('http:') === -1 && obj.indexOf('https:') === -1) { | ||
obj = root + obj; | ||
} | ||
obj = joinUrl(root, obj); | ||
} | ||
@@ -611,0 +645,0 @@ return obj; |
@@ -499,3 +499,4 @@ 'use strict'; | ||
on: {}, | ||
method: 'get' | ||
method: 'get', | ||
timeout: opts.timeout | ||
}; | ||
@@ -502,0 +503,0 @@ /* jshint ignore:start */ |
@@ -32,3 +32,3 @@ 'use strict'; | ||
this.description = args.description; | ||
this.host = parent.host || 'localhost'; | ||
this.host = parent.host; | ||
this.method = (httpMethod || errors.push('Operation ' + operationId + ' is missing method.')); | ||
@@ -47,2 +47,3 @@ this.models = models || {}; | ||
this.summary = args.summary || ''; | ||
this.timeout = parent.timeout; | ||
this.type = null; | ||
@@ -52,2 +53,11 @@ this.useJQuery = parent.useJQuery; | ||
this.enableCookies = parent.enableCookies; | ||
if(!this.host) { | ||
if(typeof window !== 'undefined') { | ||
this.host = window.location.host; | ||
} | ||
else { | ||
this.host = 'localhost'; | ||
} | ||
} | ||
this.parameterMacro = parent.parameterMacro || function (operation, parameter) { | ||
@@ -436,2 +446,3 @@ return parameter.default; | ||
var headers = this.setContentTypes(args, {}); | ||
var headerParamsByLowerCase = {}; | ||
@@ -441,12 +452,17 @@ for (var i = 0; i < this.parameters.length; i++) { | ||
if (typeof args[param.name] !== 'undefined') { | ||
if (param.in === 'header') { | ||
var value = args[param.name]; | ||
if (param.in === 'header') { | ||
headerParamsByLowerCase[param.name.toLowerCase()] = param; | ||
} | ||
} | ||
if (Array.isArray(value)) { | ||
value = value.toString(); | ||
} | ||
for (var arg in args) { | ||
var headerParam = headerParamsByLowerCase[arg.toLowerCase()]; | ||
if (typeof headerParam !== 'undefined') { | ||
var value = args[arg]; | ||
headers[param.name] = value; | ||
if (Array.isArray(value)) { | ||
value = value.toString(); | ||
} | ||
headers[headerParam.name] = value; | ||
} | ||
@@ -596,2 +612,3 @@ } | ||
for (key in formParams) { | ||
var param = formParams[key].param; | ||
value = args[key]; | ||
@@ -607,3 +624,11 @@ | ||
if (Array.isArray(value)) { | ||
bodyParam.append(key, this.encodeQueryCollection(param.collectionFormat, key, value)); | ||
if(param.collectionFormat === 'multi') { | ||
bodyParam.delete(key); | ||
for(var v in value) { | ||
bodyParam.append(key, value[v]); | ||
} | ||
} | ||
else { | ||
bodyParam.append(key, this.encodeQueryCollection(param.collectionFormat, key, value).split('=').slice(1).join('=')); | ||
} | ||
} | ||
@@ -634,2 +659,6 @@ else { | ||
} | ||
else if(format === 'multi') { | ||
bodyParam[key] = value; | ||
break; | ||
} | ||
else { | ||
@@ -716,3 +745,3 @@ delimeter = ','; | ||
var args = arg1 || {}; | ||
var opts = {}, success, error, deferred; | ||
var opts = {}, success, error, deferred, timeout; | ||
@@ -725,2 +754,6 @@ if (_.isObject(arg2)) { | ||
timeout = typeof opts.timeout !== 'undefined' | ||
? opts.timeout | ||
: this.timeout; | ||
if(this.client) { | ||
@@ -831,2 +864,6 @@ opts.client = this.client; | ||
if (timeout) { | ||
obj.timeout = timeout; | ||
} | ||
this.clientAuthorizations.apply(obj, this.operation.security); | ||
@@ -1016,3 +1053,3 @@ if (opts.mock === true) { | ||
if(typeof FormData === 'function' && obj.body instanceof FormData) { | ||
paramValue = obj.body.get(parameter.name); | ||
paramValue = obj.body.getAll(parameter.name); | ||
} | ||
@@ -1029,13 +1066,17 @@ else { | ||
else { | ||
body += '-F '; | ||
if (Array.isArray(paramValue)) { | ||
body += this.encodeQueryCollection(parameter.collectionFormat, parameter.name, paramValue); | ||
if(parameter.collectionFormat === 'multi') { | ||
for(var v in paramValue) { | ||
body += '-F ' + this.encodeQueryKey(parameter.name) + '=' + paramValue[v] + ' '; | ||
} | ||
} | ||
else { | ||
body += '-F ' + this.encodeQueryCollection(parameter.collectionFormat, parameter.name, paramValue) + ' '; | ||
} | ||
} else { | ||
body += this.encodeQueryKey(parameter.name) + '=' + paramValue; | ||
body += '-F ' + this.encodeQueryKey(parameter.name) + '=' + paramValue + ' '; | ||
} | ||
body += ' '; | ||
} | ||
} | ||
} | ||
} | ||
@@ -1042,0 +1083,0 @@ } |
@@ -11,3 +11,3 @@ { | ||
"description": "swagger-client is a javascript client for use with swaggering APIs.", | ||
"version": "2.1.18", | ||
"version": "2.1.19", | ||
"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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2016587
25072