swagger-ui.lib.swagger-client.js Maven / Gradle / Ivy
// swagger-client.js
// version 2.1.0-alpha.5
/**
* Array Model
**/
var ArrayModel = function(definition) {
this.name = "name";
this.definition = definition || {};
this.properties = [];
this.type;
this.ref;
var requiredFields = definition.enum || [];
var items = definition.items;
if(items) {
var type = items.type;
if(items.type) {
this.type = typeFromJsonSchema(type.type, type.format);
}
else {
this.ref = items['$ref'];
}
}
}
ArrayModel.prototype.createJSONSample = function(modelsToIgnore) {
var result;
modelsToIgnore = (modelsToIgnore||{})
if(this.type) {
result = type;
}
else if (this.ref) {
var name = simpleRef(this.ref);
result = models[name].createJSONSample();
}
return [ result ];
};
ArrayModel.prototype.getSampleValue = function(modelsToIgnore) {
var result;
modelsToIgnore = (modelsToIgnore || {})
if(this.type) {
result = type;
}
else if (this.ref) {
var name = simpleRef(this.ref);
result = models[name].getSampleValue(modelsToIgnore);
}
return [ result ];
}
ArrayModel.prototype.getMockSignature = function(modelsToIgnore) {
var propertiesStr = [];
if(this.ref) {
return models[simpleRef(this.ref)].getMockSignature();
}
};
/**
* SwaggerAuthorizations applys the correct authorization to an operation being executed
*/
var SwaggerAuthorizations = function() {
this.authz = {};
};
SwaggerAuthorizations.prototype.add = function(name, auth) {
this.authz[name] = auth;
return auth;
};
SwaggerAuthorizations.prototype.remove = function(name) {
return delete this.authz[name];
};
SwaggerAuthorizations.prototype.apply = function(obj, authorizations) {
var status = null;
var key;
// if the "authorizations" key is undefined, or has an empty array, add all keys
if(typeof authorizations === 'undefined' || Object.keys(authorizations).length == 0) {
for (key in this.authz) {
value = this.authz[key];
result = value.apply(obj, authorizations);
if (result === true)
status = true;
}
}
else {
if(Array.isArray(authorizations)) {
var i;
for(i = 0; i < authorizations.length; i++) {
var auth = authorizations[i];
log(auth);
for (key in this.authz) {
var value = this.authz[key];
if(typeof value !== 'undefined') {
result = value.apply(obj, authorizations);
if (result === true)
status = true;
}
}
}
}
}
return status;
};
/**
* ApiKeyAuthorization allows a query param or header to be injected
*/
var ApiKeyAuthorization = function(name, value, type) {
this.name = name;
this.value = value;
this.type = type;
};
ApiKeyAuthorization.prototype.apply = function(obj, authorizations) {
if (this.type === "query") {
if (obj.url.indexOf('?') > 0)
obj.url = obj.url + "&" + this.name + "=" + this.value;
else
obj.url = obj.url + "?" + this.name + "=" + this.value;
return true;
} else if (this.type === "header") {
obj.headers[this.name] = this.value;
return true;
}
};
var CookieAuthorization = function(cookie) {
this.cookie = cookie;
}
CookieAuthorization.prototype.apply = function(obj, authorizations) {
obj.cookieJar = obj.cookieJar || CookieJar();
obj.cookieJar.setCookie(this.cookie);
return true;
}
/**
* Password Authorization is a basic auth implementation
*/
var PasswordAuthorization = function(name, username, password) {
this.name = name;
this.username = username;
this.password = password;
this._btoa = null;
if (typeof window !== 'undefined')
this._btoa = btoa;
else
this._btoa = require("btoa");
};
PasswordAuthorization.prototype.apply = function(obj, authorizations) {
var base64encoder = this._btoa;
obj.headers["Authorization"] = "Basic " + base64encoder(this.username + ":" + this.password);
return true;
};var __bind = function(fn, me){
return function(){
return fn.apply(me, arguments);
};
};
fail = function(message) {
log(message);
}
log = function(){
log.history = log.history || [];
log.history.push(arguments);
if(this.console){
console.log( Array.prototype.slice.call(arguments)[0] );
}
};
if (!Array.prototype.indexOf) {
Array.prototype.indexOf = function(obj, start) {
for (var i = (start || 0), j = this.length; i < j; i++) {
if (this[i] === obj) { return i; }
}
return -1;
}
}
if (!('filter' in Array.prototype)) {
Array.prototype.filter= function(filter, that /*opt*/) {
var other= [], v;
for (var i=0, n= this.length; i' + propertiesStr.join(',