added validator for v2
This commit is contained in:
214
dist/lib/swagger.js
vendored
214
dist/lib/swagger.js
vendored
@@ -1,5 +1,7 @@
|
|||||||
// swagger.js
|
// swagger.js
|
||||||
// version 2.0.34
|
// version 2.0.41
|
||||||
|
|
||||||
|
(function () {
|
||||||
|
|
||||||
var __bind = function (fn, me) {
|
var __bind = function (fn, me) {
|
||||||
return function () {
|
return function () {
|
||||||
@@ -7,7 +9,7 @@ var __bind = function(fn, me){
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
log = function(){
|
var log = function () {
|
||||||
log.history = log.history || [];
|
log.history = log.history || [];
|
||||||
log.history.push(arguments);
|
log.history.push(arguments);
|
||||||
if (this.console) {
|
if (this.console) {
|
||||||
@@ -15,6 +17,16 @@ log = function(){
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// if you want to apply conditional formatting of parameter values
|
||||||
|
var parameterMacro = function (value) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if you want to apply conditional formatting of model property values
|
||||||
|
var modelPropertyMacro = function (value) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
if (!Array.prototype.indexOf) {
|
if (!Array.prototype.indexOf) {
|
||||||
Array.prototype.indexOf = function (obj, start) {
|
Array.prototype.indexOf = function (obj, start) {
|
||||||
for (var i = (start || 0), j = this.length; i < j; i++) {
|
for (var i = (start || 0), j = this.length; i < j; i++) {
|
||||||
@@ -79,8 +91,8 @@ Object.keys = Object.keys || (function () {
|
|||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|
||||||
var SwaggerApi = function (url, options) {
|
var SwaggerApi = function (url, options) {
|
||||||
|
this.isBuilt = false;
|
||||||
this.url = null;
|
this.url = null;
|
||||||
this.debug = false;
|
this.debug = false;
|
||||||
this.basePath = null;
|
this.basePath = null;
|
||||||
@@ -88,6 +100,8 @@ var SwaggerApi = function(url, options) {
|
|||||||
this.authorizationScheme = null;
|
this.authorizationScheme = null;
|
||||||
this.info = null;
|
this.info = null;
|
||||||
this.useJQuery = false;
|
this.useJQuery = false;
|
||||||
|
this.modelsArray = [];
|
||||||
|
this.isValid;
|
||||||
|
|
||||||
options = (options || {});
|
options = (options || {});
|
||||||
if (url)
|
if (url)
|
||||||
@@ -109,11 +123,15 @@ var SwaggerApi = function(url, options) {
|
|||||||
|
|
||||||
this.failure = options.failure != null ? options.failure : function () { };
|
this.failure = options.failure != null ? options.failure : function () { };
|
||||||
this.progress = options.progress != null ? options.progress : function () { };
|
this.progress = options.progress != null ? options.progress : function () { };
|
||||||
if (options.success != null)
|
if (options.success != null) {
|
||||||
this.build();
|
this.build();
|
||||||
|
this.isBuilt = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SwaggerApi.prototype.build = function () {
|
SwaggerApi.prototype.build = function () {
|
||||||
|
if (this.isBuilt)
|
||||||
|
return this;
|
||||||
var _this = this;
|
var _this = this;
|
||||||
this.progress('fetching resource list: ' + this.url);
|
this.progress('fetching resource list: ' + this.url);
|
||||||
var obj = {
|
var obj = {
|
||||||
@@ -121,7 +139,7 @@ SwaggerApi.prototype.build = function() {
|
|||||||
url: this.url,
|
url: this.url,
|
||||||
method: "get",
|
method: "get",
|
||||||
headers: {
|
headers: {
|
||||||
accept: "application/json"
|
accept: "application/json,application/json;charset=\"utf-8\",*/*"
|
||||||
},
|
},
|
||||||
on: {
|
on: {
|
||||||
error: function (response) {
|
error: function (response) {
|
||||||
@@ -158,6 +176,7 @@ SwaggerApi.prototype.buildFromSpec = function(response) {
|
|||||||
}
|
}
|
||||||
this.apis = {};
|
this.apis = {};
|
||||||
this.apisArray = [];
|
this.apisArray = [];
|
||||||
|
this.consumes = response.consumes;
|
||||||
this.produces = response.produces;
|
this.produces = response.produces;
|
||||||
this.authSchemes = response.authorizations;
|
this.authSchemes = response.authorizations;
|
||||||
if (response.info != null) {
|
if (response.info != null) {
|
||||||
@@ -175,28 +194,29 @@ SwaggerApi.prototype.buildFromSpec = function(response) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (response.basePath) {
|
if (response.basePath)
|
||||||
this.basePath = response.basePath;
|
this.basePath = response.basePath;
|
||||||
} else if (this.url.indexOf('?') > 0) {
|
else if (this.url.indexOf('?') > 0)
|
||||||
this.basePath = this.url.substring(0, this.url.lastIndexOf('?'));
|
this.basePath = this.url.substring(0, this.url.lastIndexOf('?'));
|
||||||
} else {
|
else
|
||||||
this.basePath = this.url;
|
this.basePath = this.url;
|
||||||
}
|
|
||||||
if (isApi) {
|
if (isApi) {
|
||||||
var newName = response.resourcePath.replace(/\//g, '');
|
var newName = response.resourcePath.replace(/\//g, '');
|
||||||
this.resourcePath = response.resourcePath;
|
this.resourcePath = response.resourcePath;
|
||||||
res = new SwaggerResource(response, this);
|
var res = new SwaggerResource(response, this);
|
||||||
this.apis[newName] = res;
|
this.apis[newName] = res;
|
||||||
this.apisArray.push(res);
|
this.apisArray.push(res);
|
||||||
} else {
|
} else {
|
||||||
var k;
|
var k;
|
||||||
for (k = 0; k < response.apis.length; k++) {
|
for (k = 0; k < response.apis.length; k++) {
|
||||||
var resource = response.apis[k];
|
var resource = response.apis[k];
|
||||||
res = new SwaggerResource(resource, this);
|
var res = new SwaggerResource(resource, this);
|
||||||
this.apis[res.name] = res;
|
this.apis[res.name] = res;
|
||||||
this.apisArray.push(res);
|
this.apisArray.push(res);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this.isValid = true;
|
||||||
if (this.success) {
|
if (this.success) {
|
||||||
this.success();
|
this.success();
|
||||||
}
|
}
|
||||||
@@ -239,11 +259,12 @@ SwaggerApi.prototype.buildFrom1_1Spec = function(response) {
|
|||||||
} else {
|
} else {
|
||||||
for (k = 0; k < response.apis.length; k++) {
|
for (k = 0; k < response.apis.length; k++) {
|
||||||
resource = response.apis[k];
|
resource = response.apis[k];
|
||||||
res = new SwaggerResource(resource, this);
|
var res = new SwaggerResource(resource, this);
|
||||||
this.apis[res.name] = res;
|
this.apis[res.name] = res;
|
||||||
this.apisArray.push(res);
|
this.apisArray.push(res);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this.isValid = true;
|
||||||
if (this.success) {
|
if (this.success) {
|
||||||
this.success();
|
this.success();
|
||||||
}
|
}
|
||||||
@@ -276,7 +297,6 @@ SwaggerApi.prototype.fail = function(message) {
|
|||||||
|
|
||||||
SwaggerApi.prototype.setConsolidatedModels = function () {
|
SwaggerApi.prototype.setConsolidatedModels = function () {
|
||||||
var model, modelName, resource, resource_name, _i, _len, _ref, _ref1, _results;
|
var model, modelName, resource, resource_name, _i, _len, _ref, _ref1, _results;
|
||||||
this.modelsArray = [];
|
|
||||||
this.models = {};
|
this.models = {};
|
||||||
_ref = this.apis;
|
_ref = this.apis;
|
||||||
for (resource_name in _ref) {
|
for (resource_name in _ref) {
|
||||||
@@ -321,8 +341,8 @@ var SwaggerResource = function(resourceObj, api) {
|
|||||||
var _this = this;
|
var _this = this;
|
||||||
this.api = api;
|
this.api = api;
|
||||||
this.api = this.api;
|
this.api = this.api;
|
||||||
produces = [];
|
var consumes = (this.consumes | []);
|
||||||
consumes = [];
|
var produces = (this.produces | []);
|
||||||
this.path = this.api.resourcePath != null ? this.api.resourcePath : resourceObj.path;
|
this.path = this.api.resourcePath != null ? this.api.resourcePath : resourceObj.path;
|
||||||
this.description = resourceObj.description;
|
this.description = resourceObj.description;
|
||||||
|
|
||||||
@@ -348,12 +368,12 @@ var SwaggerResource = function(resourceObj, api) {
|
|||||||
this.url = this.api.basePath + this.path.replace('{format}', 'json');
|
this.url = this.api.basePath + this.path.replace('{format}', 'json');
|
||||||
}
|
}
|
||||||
this.api.progress('fetching resource ' + this.name + ': ' + this.url);
|
this.api.progress('fetching resource ' + this.name + ': ' + this.url);
|
||||||
obj = {
|
var obj = {
|
||||||
url: this.url,
|
url: this.url,
|
||||||
method: "get",
|
method: "get",
|
||||||
useJQuery: this.useJQuery,
|
useJQuery: this.useJQuery,
|
||||||
headers: {
|
headers: {
|
||||||
accept: "application/json"
|
accept: "application/json,application/json;charset=\"utf-8\",*/*"
|
||||||
},
|
},
|
||||||
on: {
|
on: {
|
||||||
response: function (resp) {
|
response: function (resp) {
|
||||||
@@ -430,7 +450,7 @@ SwaggerResource.prototype.addModels = function(models) {
|
|||||||
}
|
}
|
||||||
var output = [];
|
var output = [];
|
||||||
for (var i = 0; i < this.modelsArray.length; i++) {
|
for (var i = 0; i < this.modelsArray.length; i++) {
|
||||||
model = this.modelsArray[i];
|
var model = this.modelsArray[i];
|
||||||
output.push(model.setReferencedModels(this.models));
|
output.push(model.setReferencedModels(this.models));
|
||||||
}
|
}
|
||||||
return output;
|
return output;
|
||||||
@@ -439,9 +459,9 @@ SwaggerResource.prototype.addModels = function(models) {
|
|||||||
|
|
||||||
SwaggerResource.prototype.addOperations = function (resource_path, ops, consumes, produces) {
|
SwaggerResource.prototype.addOperations = function (resource_path, ops, consumes, produces) {
|
||||||
if (ops) {
|
if (ops) {
|
||||||
output = [];
|
var output = [];
|
||||||
for (var i = 0; i < ops.length; i++) {
|
for (var i = 0; i < ops.length; i++) {
|
||||||
o = ops[i];
|
var o = ops[i];
|
||||||
consumes = this.consumes;
|
consumes = this.consumes;
|
||||||
produces = this.produces;
|
produces = this.produces;
|
||||||
if (o.consumes != null)
|
if (o.consumes != null)
|
||||||
@@ -453,7 +473,7 @@ SwaggerResource.prototype.addOperations = function(resource_path, ops, consumes,
|
|||||||
produces = o.produces;
|
produces = o.produces;
|
||||||
else
|
else
|
||||||
produces = this.produces;
|
produces = this.produces;
|
||||||
type = (o.type||o.responseClass);
|
var type = (o.type || o.responseClass);
|
||||||
|
|
||||||
if (type === "array") {
|
if (type === "array") {
|
||||||
ref = null;
|
ref = null;
|
||||||
@@ -461,8 +481,8 @@ SwaggerResource.prototype.addOperations = function(resource_path, ops, consumes,
|
|||||||
ref = o.items["type"] || o.items["$ref"];
|
ref = o.items["type"] || o.items["$ref"];
|
||||||
type = "array[" + ref + "]";
|
type = "array[" + ref + "]";
|
||||||
}
|
}
|
||||||
responseMessages = o.responseMessages;
|
var responseMessages = o.responseMessages;
|
||||||
method = o.method;
|
var method = o.method;
|
||||||
if (o.httpMethod) {
|
if (o.httpMethod) {
|
||||||
method = o.httpMethod;
|
method = o.httpMethod;
|
||||||
}
|
}
|
||||||
@@ -478,7 +498,7 @@ SwaggerResource.prototype.addOperations = function(resource_path, ops, consumes,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
o.nickname = this.sanitize(o.nickname);
|
o.nickname = this.sanitize(o.nickname);
|
||||||
op = new SwaggerOperation(o.nickname, resource_path, method, o.parameters, o.summary, o.notes, type, responseMessages, this, consumes, produces, o.authorizations);
|
var op = new SwaggerOperation(o.nickname, resource_path, method, o.parameters, o.summary, o.notes, type, responseMessages, this, consumes, produces, o.authorizations);
|
||||||
this.operations[op.nickname] = op;
|
this.operations[op.nickname] = op;
|
||||||
output.push(this.operationsArray.push(op));
|
output.push(this.operationsArray.push(op));
|
||||||
}
|
}
|
||||||
@@ -524,7 +544,7 @@ var SwaggerModel = function(modelName, obj) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
prop = new SwaggerModelProperty(propertyName, obj.properties[propertyName]);
|
var prop = new SwaggerModelProperty(propertyName, obj.properties[propertyName]);
|
||||||
this.properties.push(prop);
|
this.properties.push(prop);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -547,7 +567,7 @@ SwaggerModel.prototype.setReferencedModels = function(allModels) {
|
|||||||
SwaggerModel.prototype.getMockSignature = function (modelsToIgnore) {
|
SwaggerModel.prototype.getMockSignature = function (modelsToIgnore) {
|
||||||
var propertiesStr = [];
|
var propertiesStr = [];
|
||||||
for (var i = 0; i < this.properties.length; i++) {
|
for (var i = 0; i < this.properties.length; i++) {
|
||||||
prop = this.properties[i];
|
var prop = this.properties[i];
|
||||||
propertiesStr.push(prop.toString());
|
propertiesStr.push(prop.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -562,7 +582,7 @@ SwaggerModel.prototype.getMockSignature = function(modelsToIgnore) {
|
|||||||
modelsToIgnore.push(this.name);
|
modelsToIgnore.push(this.name);
|
||||||
|
|
||||||
for (var i = 0; i < this.properties.length; i++) {
|
for (var i = 0; i < this.properties.length; i++) {
|
||||||
prop = this.properties[i];
|
var prop = this.properties[i];
|
||||||
if ((prop.refModel != null) && modelsToIgnore.indexOf(prop.refModel.name) === -1) {
|
if ((prop.refModel != null) && modelsToIgnore.indexOf(prop.refModel.name) === -1) {
|
||||||
returnVal = returnVal + ('<br>' + prop.refModel.getMockSignature(modelsToIgnore));
|
returnVal = returnVal + ('<br>' + prop.refModel.getMockSignature(modelsToIgnore));
|
||||||
}
|
}
|
||||||
@@ -579,7 +599,7 @@ SwaggerModel.prototype.createJSONSample = function(modelsToIgnore) {
|
|||||||
var modelsToIgnore = (modelsToIgnore || [])
|
var modelsToIgnore = (modelsToIgnore || [])
|
||||||
modelsToIgnore.push(this.name);
|
modelsToIgnore.push(this.name);
|
||||||
for (var i = 0; i < this.properties.length; i++) {
|
for (var i = 0; i < this.properties.length; i++) {
|
||||||
prop = this.properties[i];
|
var prop = this.properties[i];
|
||||||
result[prop.name] = prop.getSampleValue(modelsToIgnore);
|
result[prop.name] = prop.getSampleValue(modelsToIgnore);
|
||||||
}
|
}
|
||||||
modelsToIgnore.pop(this.name);
|
modelsToIgnore.pop(this.name);
|
||||||
@@ -593,6 +613,7 @@ var SwaggerModelProperty = function(name, obj) {
|
|||||||
this.isCollection = this.dataType && (this.dataType.toLowerCase() === 'array' || this.dataType.toLowerCase() === 'list' || this.dataType.toLowerCase() === 'set');
|
this.isCollection = this.dataType && (this.dataType.toLowerCase() === 'array' || this.dataType.toLowerCase() === 'list' || this.dataType.toLowerCase() === 'set');
|
||||||
this.descr = obj.description;
|
this.descr = obj.description;
|
||||||
this.required = obj.required;
|
this.required = obj.required;
|
||||||
|
this.defaultValue = modelPropertyMacro(obj.defaultValue);
|
||||||
if (obj.items != null) {
|
if (obj.items != null) {
|
||||||
if (obj.items.type != null) {
|
if (obj.items.type != null) {
|
||||||
this.refDataType = obj.items.type;
|
this.refDataType = obj.items.type;
|
||||||
@@ -620,7 +641,7 @@ var SwaggerModelProperty = function(name, obj) {
|
|||||||
|
|
||||||
SwaggerModelProperty.prototype.getSampleValue = function (modelsToIgnore) {
|
SwaggerModelProperty.prototype.getSampleValue = function (modelsToIgnore) {
|
||||||
var result;
|
var result;
|
||||||
if ((this.refModel != null) && (modelsToIgnore.indexOf(prop.refModel.name) === -1)) {
|
if ((this.refModel != null) && (modelsToIgnore.indexOf(this.refModel.name) === -1)) {
|
||||||
result = this.refModel.createJSONSample(modelsToIgnore);
|
result = this.refModel.createJSONSample(modelsToIgnore);
|
||||||
} else {
|
} else {
|
||||||
if (this.isCollection) {
|
if (this.isCollection) {
|
||||||
@@ -638,7 +659,9 @@ SwaggerModelProperty.prototype.getSampleValue = function(modelsToIgnore) {
|
|||||||
|
|
||||||
SwaggerModelProperty.prototype.toSampleValue = function (value) {
|
SwaggerModelProperty.prototype.toSampleValue = function (value) {
|
||||||
var result;
|
var result;
|
||||||
if (value === "integer") {
|
if ((typeof this.defaultValue !== 'undefined') && this.defaultValue !== null) {
|
||||||
|
result = this.defaultValue;
|
||||||
|
} else if (value === "integer") {
|
||||||
result = 0;
|
result = 0;
|
||||||
} else if (value === "boolean") {
|
} else if (value === "boolean") {
|
||||||
result = false;
|
result = false;
|
||||||
@@ -686,8 +709,10 @@ var SwaggerOperation = function(nickname, path, method, parameters, summary, not
|
|||||||
this.authorizations = authorizations;
|
this.authorizations = authorizations;
|
||||||
this["do"] = __bind(this["do"], this);
|
this["do"] = __bind(this["do"], this);
|
||||||
|
|
||||||
if (errors.length > 0)
|
if (errors.length > 0) {
|
||||||
|
console.error('SwaggerOperation errors', errors, arguments);
|
||||||
this.resource.api.fail(errors);
|
this.resource.api.fail(errors);
|
||||||
|
}
|
||||||
|
|
||||||
this.path = this.path.replace('{format}', 'json');
|
this.path = this.path.replace('{format}', 'json');
|
||||||
this.method = this.method.toLowerCase();
|
this.method = this.method.toLowerCase();
|
||||||
@@ -768,6 +793,7 @@ var SwaggerOperation = function(nickname, path, method, parameters, summary, not
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
param.defaultValue = parameterMacro(param.defaultValue);
|
||||||
}
|
}
|
||||||
this.resource[this.nickname] = function (args, callback, error) {
|
this.resource[this.nickname] = function (args, callback, error) {
|
||||||
return _this["do"](args, callback, error);
|
return _this["do"](args, callback, error);
|
||||||
@@ -888,7 +914,7 @@ SwaggerOperation.prototype["do"] = function(args, opts, callback, error) {
|
|||||||
if (possibleParams) {
|
if (possibleParams) {
|
||||||
var key;
|
var key;
|
||||||
for (key in possibleParams) {
|
for (key in possibleParams) {
|
||||||
value = possibleParams[key];
|
var value = possibleParams[key];
|
||||||
if (args[value.name]) {
|
if (args[value.name]) {
|
||||||
params[value.name] = args[value.name];
|
params[value.name] = args[value.name];
|
||||||
}
|
}
|
||||||
@@ -935,7 +961,7 @@ SwaggerOperation.prototype.urlify = function(args) {
|
|||||||
if (param.paramType === 'path') {
|
if (param.paramType === 'path') {
|
||||||
if (args[param.name]) {
|
if (args[param.name]) {
|
||||||
// apply path params and remove from args
|
// apply path params and remove from args
|
||||||
var reg = new RegExp('\{' + param.name + '[^\}]*\}', 'gi');
|
var reg = new RegExp('\\{\\s*?' + param.name + '.*?\\}(?=\\s*?(\\/|$))', 'gi');
|
||||||
url = url.replace(reg, this.encodePathParam(args[param.name]));
|
url = url.replace(reg, this.encodePathParam(args[param.name]));
|
||||||
delete args[param.name];
|
delete args[param.name];
|
||||||
}
|
}
|
||||||
@@ -1104,18 +1130,19 @@ var SwaggerRequest = function(type, url, params, opts, successCallback, errorCal
|
|||||||
var body = params.body;
|
var body = params.body;
|
||||||
|
|
||||||
// encode the body for form submits
|
// encode the body for form submits
|
||||||
if (headers["Accept"] && headers["Accept"].indexOf("application/x-www-form-urlencoded") === 0) {
|
if (headers["Content-Type"]) {
|
||||||
var fields = {};
|
|
||||||
var possibleParams = {};
|
|
||||||
var values = {};
|
var values = {};
|
||||||
var key;
|
var i;
|
||||||
for(key in formParams){
|
var operationParams = this.operation.parameters;
|
||||||
var param = formParams[key];
|
for (i = 0; i < operationParams.length; i++) {
|
||||||
|
var param = operationParams[i];
|
||||||
|
if (param.paramType === "form")
|
||||||
values[param.name] = param;
|
values[param.name] = param;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (headers["Content-Type"].indexOf("application/x-www-form-urlencoded") === 0) {
|
||||||
var encoded = "";
|
var encoded = "";
|
||||||
var key;
|
var key, value;
|
||||||
for (key in values) {
|
for (key in values) {
|
||||||
value = this.params[key];
|
value = this.params[key];
|
||||||
if (typeof value !== 'undefined') {
|
if (typeof value !== 'undefined') {
|
||||||
@@ -1126,7 +1153,27 @@ var SwaggerRequest = function(type, url, params, opts, successCallback, errorCal
|
|||||||
}
|
}
|
||||||
body = encoded;
|
body = encoded;
|
||||||
}
|
}
|
||||||
|
else if (headers["Content-Type"].indexOf("multipart/form-data") === 0) {
|
||||||
|
// encode the body for form submits
|
||||||
|
var data = "";
|
||||||
|
var boundary = "----SwaggerFormBoundary" + Date.now();
|
||||||
|
var key, value;
|
||||||
|
for (key in values) {
|
||||||
|
value = this.params[key];
|
||||||
|
if (typeof value !== 'undefined') {
|
||||||
|
data += '--' + boundary + '\n';
|
||||||
|
data += 'Content-Disposition: form-data; name="' + key + '"';
|
||||||
|
data += '\n\n';
|
||||||
|
data += value + "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
data += "--" + boundary + "--\n";
|
||||||
|
headers["Content-Type"] = "multipart/form-data; boundary=" + boundary;
|
||||||
|
body = data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var obj;
|
||||||
if (!((this.headers != null) && (this.headers.mock != null))) {
|
if (!((this.headers != null) && (this.headers.mock != null))) {
|
||||||
obj = {
|
obj = {
|
||||||
url: this.url,
|
url: this.url,
|
||||||
@@ -1155,7 +1202,7 @@ var SwaggerRequest = function(type, url, params, opts, successCallback, errorCal
|
|||||||
} else {
|
} else {
|
||||||
e = exports;
|
e = exports;
|
||||||
}
|
}
|
||||||
status = e.authorizations.apply(obj, this.operation.authorizations);
|
var status = e.authorizations.apply(obj, this.operation.authorizations);
|
||||||
if (opts.mock == null) {
|
if (opts.mock == null) {
|
||||||
if (status !== false) {
|
if (status !== false) {
|
||||||
new SwaggerHttp().execute(obj);
|
new SwaggerHttp().execute(obj);
|
||||||
@@ -1166,12 +1213,13 @@ var SwaggerRequest = function(type, url, params, opts, successCallback, errorCal
|
|||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return obj;
|
||||||
};
|
};
|
||||||
|
|
||||||
SwaggerRequest.prototype.setHeaders = function (params, operation) {
|
SwaggerRequest.prototype.setHeaders = function (params, operation) {
|
||||||
// default type
|
// default type
|
||||||
var accepts = "application/json";
|
var accepts = "application/json";
|
||||||
var contentType = null;
|
var consumes = "application/json";
|
||||||
|
|
||||||
var allDefinedParams = this.operation.parameters;
|
var allDefinedParams = this.operation.parameters;
|
||||||
var definedFormParams = [];
|
var definedFormParams = [];
|
||||||
@@ -1198,25 +1246,25 @@ SwaggerRequest.prototype.setHeaders = function(params, operation) {
|
|||||||
// if there's a body, need to set the accepts header via requestContentType
|
// if there's a body, need to set the accepts header via requestContentType
|
||||||
if (body && (this.type === "POST" || this.type === "PUT" || this.type === "PATCH" || this.type === "DELETE")) {
|
if (body && (this.type === "POST" || this.type === "PUT" || this.type === "PATCH" || this.type === "DELETE")) {
|
||||||
if (this.opts.requestContentType)
|
if (this.opts.requestContentType)
|
||||||
accepts = this.opts.requestContentType;
|
consumes = this.opts.requestContentType;
|
||||||
} else {
|
} else {
|
||||||
// if any form params, content type must be set
|
// if any form params, content type must be set
|
||||||
if (definedFormParams.length > 0) {
|
if (definedFormParams.length > 0) {
|
||||||
if (definedFileParams.length > 0)
|
if (definedFileParams.length > 0)
|
||||||
accepts = "multipart/form-data";
|
consumes = "multipart/form-data";
|
||||||
else
|
else
|
||||||
accepts = "application/x-www-form-urlencoded";
|
consumes = "application/x-www-form-urlencoded";
|
||||||
}
|
}
|
||||||
else if (this.type == "DELETE")
|
else if (this.type === "DELETE")
|
||||||
body = "{}";
|
body = "{}";
|
||||||
else if (this.type != "DELETE")
|
else if (this.type != "DELETE")
|
||||||
accepts = null;
|
accepts = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (contentType && this.operation.consumes) {
|
if (consumes && this.operation.consumes) {
|
||||||
if (this.operation.consumes.indexOf(contentType) === -1) {
|
if (this.operation.consumes.indexOf(consumes) === -1) {
|
||||||
log("server doesn't consume " + contentType + ", try " + JSON.stringify(this.operation.consumes));
|
log("server doesn't consume " + consumes + ", try " + JSON.stringify(this.operation.consumes));
|
||||||
contentType = this.operation.consumes[0];
|
consumes = this.operation.consumes[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1231,33 +1279,11 @@ SwaggerRequest.prototype.setHeaders = function(params, operation) {
|
|||||||
accepts = this.operation.produces[0];
|
accepts = this.operation.produces[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (contentType && contentType.indexOf("application/x-www-form-urlencoded") === 0) {
|
|
||||||
var fields = {};
|
|
||||||
var possibleParams = {};
|
|
||||||
var values = {};
|
|
||||||
var key;
|
|
||||||
for(key in formParams){
|
|
||||||
var param = formParams[key];
|
|
||||||
values[param.name] = param;
|
|
||||||
}
|
|
||||||
|
|
||||||
var encoded = "";
|
if ((consumes && body !== "") || (consumes === "application/x-www-form-urlencoded"))
|
||||||
var key;
|
headers["Content-Type"] = consumes;
|
||||||
for(key in values) {
|
|
||||||
value = this.params[key];
|
|
||||||
if(typeof value !== 'undefined'){
|
|
||||||
if(encoded !== "")
|
|
||||||
encoded += "&";
|
|
||||||
encoded += encodeURIComponent(key) + '=' + encodeURIComponent(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
body = encoded;
|
|
||||||
}
|
|
||||||
if ((contentType && body !== "") || (contentType === "application/x-www-form-urlencoded"))
|
|
||||||
headers["Content-Type"] = contentType;
|
|
||||||
if (accepts)
|
if (accepts)
|
||||||
headers["Accept"] = accepts;
|
headers["Accept"] = accepts;
|
||||||
|
|
||||||
return headers;
|
return headers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1463,11 +1489,36 @@ ShredHttpClient.prototype.execute = function(obj) {
|
|||||||
return out;
|
return out;
|
||||||
};
|
};
|
||||||
|
|
||||||
res = {
|
// Transform an error into a usable response-like object
|
||||||
|
var transformError = function (error) {
|
||||||
|
var out = {
|
||||||
|
// Default to a status of 0 - The client will treat this as a generic permissions sort of error
|
||||||
|
status: 0,
|
||||||
|
data: error.message || error
|
||||||
|
};
|
||||||
|
|
||||||
|
if (error.code) {
|
||||||
|
out.obj = error;
|
||||||
|
|
||||||
|
if (error.code === 'ENOTFOUND' || error.code === 'ECONNREFUSED') {
|
||||||
|
// We can tell the client that this should be treated as a missing resource and not as a permissions thing
|
||||||
|
out.status = 404;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return out;
|
||||||
|
};
|
||||||
|
|
||||||
|
var res = {
|
||||||
error: function (response) {
|
error: function (response) {
|
||||||
if (obj)
|
if (obj)
|
||||||
return cb.error(transform(response));
|
return cb.error(transform(response));
|
||||||
},
|
},
|
||||||
|
// Catch the Shred error raised when the request errors as it is made (i.e. No Response is coming)
|
||||||
|
request_error: function (err) {
|
||||||
|
if (obj)
|
||||||
|
return cb.error(transformError(err));
|
||||||
|
},
|
||||||
redirect: function (response) {
|
redirect: function (response) {
|
||||||
if (obj)
|
if (obj)
|
||||||
return cb.redirect(transform(response));
|
return cb.redirect(transform(response));
|
||||||
@@ -1505,7 +1556,7 @@ SwaggerAuthorizations.prototype.remove = function(name) {
|
|||||||
|
|
||||||
SwaggerAuthorizations.prototype.apply = function (obj, authorizations) {
|
SwaggerAuthorizations.prototype.apply = function (obj, authorizations) {
|
||||||
var status = null;
|
var status = null;
|
||||||
var key;
|
var key, value, result;
|
||||||
|
|
||||||
// if the "authorizations" key is undefined, or has an empty array, add all keys
|
// if the "authorizations" key is undefined, or has an empty array, add all keys
|
||||||
if (typeof authorizations === 'undefined' || Object.keys(authorizations).length == 0) {
|
if (typeof authorizations === 'undefined' || Object.keys(authorizations).length == 0) {
|
||||||
@@ -1535,10 +1586,11 @@ SwaggerAuthorizations.prototype.apply = function(obj, authorizations) {
|
|||||||
/**
|
/**
|
||||||
* ApiKeyAuthorization allows a query param or header to be injected
|
* ApiKeyAuthorization allows a query param or header to be injected
|
||||||
*/
|
*/
|
||||||
var ApiKeyAuthorization = function(name, value, type) {
|
var ApiKeyAuthorization = function (name, value, type, delimiter) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.value = value;
|
this.value = value;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
|
this.delimiter = delimiter;
|
||||||
};
|
};
|
||||||
|
|
||||||
ApiKeyAuthorization.prototype.apply = function (obj, authorizations) {
|
ApiKeyAuthorization.prototype.apply = function (obj, authorizations) {
|
||||||
@@ -1549,6 +1601,11 @@ ApiKeyAuthorization.prototype.apply = function(obj, authorizations) {
|
|||||||
obj.url = obj.url + "?" + this.name + "=" + this.value;
|
obj.url = obj.url + "?" + this.name + "=" + this.value;
|
||||||
return true;
|
return true;
|
||||||
} else if (this.type === "header") {
|
} else if (this.type === "header") {
|
||||||
|
if (typeof obj.headers[this.name] !== 'undefined') {
|
||||||
|
if (typeof this.delimiter !== 'undefined')
|
||||||
|
obj.headers[this.name] = obj.headers[this.name] + this.delimiter + this.value;
|
||||||
|
}
|
||||||
|
else
|
||||||
obj.headers[this.name] = this.value;
|
obj.headers[this.name] = this.value;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -1603,3 +1660,6 @@ e.SwaggerModel = SwaggerModel;
|
|||||||
e.SwaggerModelProperty = SwaggerModelProperty;
|
e.SwaggerModelProperty = SwaggerModelProperty;
|
||||||
e.SwaggerResource = SwaggerResource;
|
e.SwaggerResource = SwaggerResource;
|
||||||
e.SwaggerApi = SwaggerApi;
|
e.SwaggerApi = SwaggerApi;
|
||||||
|
e.log = log;
|
||||||
|
|
||||||
|
})();
|
||||||
|
|||||||
26
dist/swagger-ui.js
vendored
26
dist/swagger-ui.js
vendored
@@ -293,6 +293,21 @@ function program8(depth0,data) {
|
|||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function program10(depth0,data) {
|
||||||
|
|
||||||
|
var buffer = "", stack1;
|
||||||
|
buffer += "\n <span style=\"float:right\"><a href=\"http://online.swagger.io/validator/debug?url=";
|
||||||
|
if (stack1 = helpers.url) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
|
||||||
|
else { stack1 = depth0.url; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
|
||||||
|
buffer += escapeExpression(stack1)
|
||||||
|
+ "\"><img id=\"foo\" src=\"http://online.swagger.io/validator?url=";
|
||||||
|
if (stack1 = helpers.url) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
|
||||||
|
else { stack1 = depth0.url; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
|
||||||
|
buffer += escapeExpression(stack1)
|
||||||
|
+ "\"></a>\n </span>\n ";
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
buffer += "<div class='info' id='api_info'>\n ";
|
buffer += "<div class='info' id='api_info'>\n ";
|
||||||
stack1 = helpers['if'].call(depth0, depth0.info, {hash:{},inverse:self.noop,fn:self.program(1, program1, data),data:data});
|
stack1 = helpers['if'].call(depth0, depth0.info, {hash:{},inverse:self.noop,fn:self.program(1, program1, data),data:data});
|
||||||
if(stack1 || stack1 === 0) { buffer += stack1; }
|
if(stack1 || stack1 === 0) { buffer += stack1; }
|
||||||
@@ -303,7 +318,10 @@ function program8(depth0,data) {
|
|||||||
+ "\n ";
|
+ "\n ";
|
||||||
stack1 = helpers['if'].call(depth0, depth0.apiVersion, {hash:{},inverse:self.noop,fn:self.program(8, program8, data),data:data});
|
stack1 = helpers['if'].call(depth0, depth0.apiVersion, {hash:{},inverse:self.noop,fn:self.program(8, program8, data),data:data});
|
||||||
if(stack1 || stack1 === 0) { buffer += stack1; }
|
if(stack1 || stack1 === 0) { buffer += stack1; }
|
||||||
buffer += "]</h4>\n </div>\n</div>\n";
|
buffer += "]\n ";
|
||||||
|
stack1 = helpers['if'].call(depth0, depth0.validatorUrl, {hash:{},inverse:self.noop,fn:self.program(10, program10, data),data:data});
|
||||||
|
if(stack1 || stack1 === 0) { buffer += stack1; }
|
||||||
|
buffer += "\n </h4>\n </div>\n</div>\n";
|
||||||
return buffer;
|
return buffer;
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
@@ -1483,13 +1501,15 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log(this.model);
|
|
||||||
if (this.model.info && this.model.info.license && typeof this.model.info.license === 'string') {
|
if (this.model.info && this.model.info.license && typeof this.model.info.license === 'string') {
|
||||||
name = this.model.info.license;
|
name = this.model.info.license;
|
||||||
url = this.model.info.licenseUrl;
|
url = this.model.info.licenseUrl;
|
||||||
this.model.info.license = {};
|
this.model.info.license = {};
|
||||||
this.model.info.license.name = name;
|
this.model.info.license.name = name;
|
||||||
return this.model.info.license.url = url;
|
this.model.info.license.url = url;
|
||||||
|
}
|
||||||
|
if (this.model.url.indexOf('http://localhost') === -1 && this.model.swaggerVersion === 2) {
|
||||||
|
return this.model.validatorUrl = this.model.url;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
2
dist/swagger-ui.min.js
vendored
2
dist/swagger-ui.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -14,7 +14,6 @@ class MainView extends Backbone.View
|
|||||||
if (sorterName == "alpha") # sort top level paths if alpha
|
if (sorterName == "alpha") # sort top level paths if alpha
|
||||||
@model.apisArray.sort sorter
|
@model.apisArray.sort sorter
|
||||||
|
|
||||||
log @model
|
|
||||||
if @model.info and @model.info.license and typeof @model.info.license is 'string'
|
if @model.info and @model.info.license and typeof @model.info.license is 'string'
|
||||||
name = @model.info.license
|
name = @model.info.license
|
||||||
url = @model.info.licenseUrl
|
url = @model.info.licenseUrl
|
||||||
@@ -22,6 +21,9 @@ class MainView extends Backbone.View
|
|||||||
@model.info.license.name = name
|
@model.info.license.name = name
|
||||||
@model.info.license.url = url
|
@model.info.license.url = url
|
||||||
|
|
||||||
|
if @model.url.indexOf('http://localhost') is -1 and @model.swaggerVersion is 2
|
||||||
|
@model.validatorUrl = @model.url
|
||||||
|
|
||||||
render: ->
|
render: ->
|
||||||
# Render the outer container for resources
|
# Render the outer container for resources
|
||||||
$(@el).html(Handlebars.templates.main(@model))
|
$(@el).html(Handlebars.templates.main(@model))
|
||||||
|
|||||||
@@ -17,6 +17,11 @@
|
|||||||
<h4 style="color: #999">[ <span style="font-variant: small-caps">base url</span>: {{basePath}}
|
<h4 style="color: #999">[ <span style="font-variant: small-caps">base url</span>: {{basePath}}
|
||||||
{{#if apiVersion}}
|
{{#if apiVersion}}
|
||||||
, <span style="font-variant: small-caps">api version</span>: {{apiVersion}}
|
, <span style="font-variant: small-caps">api version</span>: {{apiVersion}}
|
||||||
{{/if}}]</h4>
|
{{/if}}]
|
||||||
|
{{#if validatorUrl}}
|
||||||
|
<span style="float:right"><a href="http://online.swagger.io/validator/debug?url={{url}}"><img id="foo" src="http://online.swagger.io/validator?url={{url}}"></a>
|
||||||
|
</span>
|
||||||
|
{{/if}}
|
||||||
|
</h4>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user