updated libraries

This commit is contained in:
Tony Tam
2014-09-23 00:57:04 -07:00
parent 922848b195
commit d838073389
2 changed files with 1781 additions and 1721 deletions

View File

@@ -455,158 +455,7 @@ OperationGroup.prototype.sort = function(sorter) {
Operation.prototype.getType = function (param) {
var type = param.type;
var format = param.forma/**
* SwaggerHttp is a wrapper for executing requests
*/
var SwaggerHttp = function() {};
SwaggerHttp.prototype.execute = function(obj) {
if(obj && (typeof obj.useJQuery === 'boolean'))
this.useJQuery = obj.useJQuery;
else
this.useJQuery = this.isIE8();
if(this.useJQuery)
return new JQueryHttpClient().execute(obj);
else
return new ShredHttpClient().execute(obj);
}
SwaggerHttp.prototype.isIE8 = function() {
var detectedIE = false;
if (typeof navigator !== 'undefined' && navigator.userAgent) {
nav = navigator.userAgent.toLowerCase();
if (nav.indexOf('msie') !== -1) {
var version = parseInt(nav.split('msie')[1]);
if (version <= 8) {
detectedIE = true;
}
}
}
return detectedIE;
};
/*
* JQueryHttpClient lets a browser take advantage of JQuery's cross-browser magic.
* NOTE: when jQuery is available it will export both '$' and 'jQuery' to the global space.
* Since we are using closures here we need to alias it for internal use.
*/
var JQueryHttpClient = function(options) {
"use strict";
if(!jQuery){
var jQuery = window.jQuery;
}
}
JQueryHttpClient.prototype.execute = function(obj) {
var cb = obj.on;
var request = obj;
obj.type = obj.method;
obj.cache = false;
obj.beforeSend = function(xhr) {
var key, results;
if (obj.headers) {
results = [];
var key;
for (key in obj.headers) {
if (key.toLowerCase() === "content-type") {
results.push(obj.contentType = obj.headers[key]);
} else if (key.toLowerCase() === "accept") {
results.push(obj.accepts = obj.headers[key]);
} else {
results.push(xhr.setRequestHeader(key, obj.headers[key]));
}
}
return results;
}
};
obj.data = obj.body;
obj.complete = function(response, textStatus, opts) {
var headers = {},
headerArray = response.getAllResponseHeaders().split("\n");
for(var i = 0; i < headerArray.length; i++) {
var toSplit = headerArray[i].trim();
if(toSplit.length === 0)
continue;
var separator = toSplit.indexOf(":");
if(separator === -1) {
// Name but no value in the header
headers[toSplit] = null;
continue;
}
var name = toSplit.substring(0, separator).trim(),
value = toSplit.substring(separator + 1).trim();
headers[name] = value;
}
var out = {
url: request.url,
method: request.method,
status: response.status,
data: response.responseText,
headers: headers
};
var contentType = (headers["content-type"]||headers["Content-Type"]||null)
if(contentType != null) {
if(contentType.indexOf("application/json") == 0 || contentType.indexOf("+json") > 0) {
if(response.responseText && response.responseText !== "")
out.obj = JSON.parse(response.responseText);
else
out.obj = {}
}
}
if(response.status >= 200 && response.status < 300)
cb.response(out);
else if(response.status === 0 || (response.status >= 400 && response.status < 599))
cb.error(out);
else
return cb.response(out);
};
jQuery.support.cors = true;
return jQuery.ajax(obj);
}
/*
* ShredHttpClient is a light-weight, node or browser HTTP client
*/
var ShredHttpClient = function(options) {
this.options = (options||{});
this.isInitialized = false;
var identity, toString;
if (typeof window !== 'undefined') {
this.Shred = require("./shred");
this.content = require("./shred/content");
}
else
this.Shred = require("shred");
this.shred = new this.Shred();
}
ShredHttpClient.prototype.initShred = function () {
this.isInitialized = true;
this.registerProcessors(this.shred);
}
ShredHttpClient.prototype.registerProcessors = function(shred) {
var identity = function(x) {
return x;
};
var toString = function(x) {
return x.toString();
};
if (typeof window !== 'undefined') {
this.content.registerProcessor(["application/json; charset=utf-8", "application/jsot;
var format = param.format;
var isArray = false;
var str;
if(type === 'integer' && format === 'int32')
@@ -768,69 +617,7 @@ Operation.prototype.execute = function(arg1, arg2, arg3, arg4, parent) {
return;
}
// set content typn", "json"], {
parser: identity,
stringify: toString
});
} else {
this.Shred.registerProcessor(["application/json; charset=utf-8", "application/json", "json"], {
parser: identity,
stringify: toString
});
}
}
ShredHttpClient.prototype.execute = function(obj) {
if(!this.isInitialized)
this.initShred();
var cb = obj.on, res;
var transform = function(response) {
var out = {
headers: response._headers,
url: response.request.url,
method: response.request.method,
status: response.status,
data: response.content.data
};
var contentType = (response._headers["content-type"]||response._headers["Content-Type"]||null)
if(contentType != null) {
if(contentType.indexOf("application/json") == 0 || contentType.indexOf("+json") > 0) {
if(response.content.data && response.content.data !== "")
out.obj = JSON.parse(response.content.data);
else
out.obj = {}
}
}
return out;
};
res = {
error: function(response) {
if (obj)
return cb.error(transform(response));
},
redirect: function(response) {
if (obj)
return cb.redirect(transform(response));
},
307: function(response) {
if (obj)
return cb.redirect(transform(response));
},
response: function(response) {
if (obj)
return cb.response(transform(response));
}
};
if (obj) {
obj.on = res;
}
return this.shred.request(obj);
};e negotiation
// set content type negotiation
var consumes = this.consumes || this.parent.consumes || [ 'application/json' ];
var produces = this.produces || this.parent.produces || [ 'application/json' ];
@@ -1334,4 +1121,217 @@ e.authorizations = new SwaggerAuthorizations();
e.ApiKeyAuthorization = ApiKeyAuthorization;
e.PasswordAuthorization = PasswordAuthorization;
e.CookieAuthorization = CookieAuthorization;
e.SwaggerClient = SwaggerClient;
e.SwaggerClient = SwaggerClient;/**
* SwaggerHttp is a wrapper for executing requests
*/
var SwaggerHttp = function() {};
SwaggerHttp.prototype.execute = function(obj) {
if(obj && (typeof obj.useJQuery === 'boolean'))
this.useJQuery = obj.useJQuery;
else
this.useJQuery = this.isIE8();
if(this.useJQuery)
return new JQueryHttpClient().execute(obj);
else
return new ShredHttpClient().execute(obj);
}
SwaggerHttp.prototype.isIE8 = function() {
var detectedIE = false;
if (typeof navigator !== 'undefined' && navigator.userAgent) {
nav = navigator.userAgent.toLowerCase();
if (nav.indexOf('msie') !== -1) {
var version = parseInt(nav.split('msie')[1]);
if (version <= 8) {
detectedIE = true;
}
}
}
return detectedIE;
};
/*
* JQueryHttpClient lets a browser take advantage of JQuery's cross-browser magic.
* NOTE: when jQuery is available it will export both '$' and 'jQuery' to the global space.
* Since we are using closures here we need to alias it for internal use.
*/
var JQueryHttpClient = function(options) {
"use strict";
if(!jQuery){
var jQuery = window.jQuery;
}
}
JQueryHttpClient.prototype.execute = function(obj) {
var cb = obj.on;
var request = obj;
obj.type = obj.method;
obj.cache = false;
obj.beforeSend = function(xhr) {
var key, results;
if (obj.headers) {
results = [];
var key;
for (key in obj.headers) {
if (key.toLowerCase() === "content-type") {
results.push(obj.contentType = obj.headers[key]);
} else if (key.toLowerCase() === "accept") {
results.push(obj.accepts = obj.headers[key]);
} else {
results.push(xhr.setRequestHeader(key, obj.headers[key]));
}
}
return results;
}
};
obj.data = obj.body;
obj.complete = function(response, textStatus, opts) {
var headers = {},
headerArray = response.getAllResponseHeaders().split("\n");
for(var i = 0; i < headerArray.length; i++) {
var toSplit = headerArray[i].trim();
if(toSplit.length === 0)
continue;
var separator = toSplit.indexOf(":");
if(separator === -1) {
// Name but no value in the header
headers[toSplit] = null;
continue;
}
var name = toSplit.substring(0, separator).trim(),
value = toSplit.substring(separator + 1).trim();
headers[name] = value;
}
var out = {
url: request.url,
method: request.method,
status: response.status,
data: response.responseText,
headers: headers
};
var contentType = (headers["content-type"]||headers["Content-Type"]||null)
if(contentType != null) {
if(contentType.indexOf("application/json") == 0 || contentType.indexOf("+json") > 0) {
if(response.responseText && response.responseText !== "")
out.obj = JSON.parse(response.responseText);
else
out.obj = {}
}
}
if(response.status >= 200 && response.status < 300)
cb.response(out);
else if(response.status === 0 || (response.status >= 400 && response.status < 599))
cb.error(out);
else
return cb.response(out);
};
jQuery.support.cors = true;
return jQuery.ajax(obj);
}
/*
* ShredHttpClient is a light-weight, node or browser HTTP client
*/
var ShredHttpClient = function(options) {
this.options = (options||{});
this.isInitialized = false;
var identity, toString;
if (typeof window !== 'undefined') {
this.Shred = require("./shred");
this.content = require("./shred/content");
}
else
this.Shred = require("shred");
this.shred = new this.Shred();
}
ShredHttpClient.prototype.initShred = function () {
this.isInitialized = true;
this.registerProcessors(this.shred);
}
ShredHttpClient.prototype.registerProcessors = function(shred) {
var identity = function(x) {
return x;
};
var toString = function(x) {
return x.toString();
};
if (typeof window !== 'undefined') {
this.content.registerProcessor(["application/json; charset=utf-8", "application/json", "json"], {
parser: identity,
stringify: toString
});
} else {
this.Shred.registerProcessor(["application/json; charset=utf-8", "application/json", "json"], {
parser: identity,
stringify: toString
});
}
}
ShredHttpClient.prototype.execute = function(obj) {
if(!this.isInitialized)
this.initShred();
var cb = obj.on, res;
var transform = function(response) {
var out = {
headers: response._headers,
url: response.request.url,
method: response.request.method,
status: response.status,
data: response.content.data
};
var contentType = (response._headers["content-type"]||response._headers["Content-Type"]||null)
if(contentType != null) {
if(contentType.indexOf("application/json") == 0 || contentType.indexOf("+json") > 0) {
if(response.content.data && response.content.data !== "")
out.obj = JSON.parse(response.content.data);
else
out.obj = {}
}
}
return out;
};
res = {
error: function(response) {
if (obj)
return cb.error(transform(response));
},
redirect: function(response) {
if (obj)
return cb.redirect(transform(response));
},
307: function(response) {
if (obj)
return cb.redirect(transform(response));
},
response: function(response) {
if (obj)
return cb.response(transform(response));
}
};
if (obj) {
obj.on = res;
}
return this.shred.request(obj);
};