fix for #602
This commit is contained in:
19
dist/lib/swagger-client.js
vendored
19
dist/lib/swagger-client.js
vendored
@@ -187,6 +187,7 @@ var SwaggerClient = function(url, options) {
|
|||||||
this.isValid = false;
|
this.isValid = false;
|
||||||
this.info = null;
|
this.info = null;
|
||||||
this.useJQuery = false;
|
this.useJQuery = false;
|
||||||
|
this.models = models;
|
||||||
|
|
||||||
options = (options||{});
|
options = (options||{});
|
||||||
if (url)
|
if (url)
|
||||||
@@ -237,10 +238,12 @@ SwaggerClient.prototype.build = function() {
|
|||||||
if(responseObj.swagger && responseObj.swagger === 2.0) {
|
if(responseObj.swagger && responseObj.swagger === 2.0) {
|
||||||
self.swaggerVersion = responseObj.swagger;
|
self.swaggerVersion = responseObj.swagger;
|
||||||
self.buildFromSpec(responseObj);
|
self.buildFromSpec(responseObj);
|
||||||
this.isValid = true;
|
self.isValid = true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
self.isValid = false;
|
||||||
|
self.failure();
|
||||||
}
|
}
|
||||||
else
|
|
||||||
this.isValid = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -418,16 +421,22 @@ var Operation = function(parent, operationId, httpMethod, path, args, definition
|
|||||||
var model;
|
var model;
|
||||||
var responses = this.responses;
|
var responses = this.responses;
|
||||||
|
|
||||||
if(responses['200'])
|
if(responses['200']) {
|
||||||
response = responses['200'];
|
response = responses['200'];
|
||||||
else if(responses['default'])
|
defaultResponseCode = '200';
|
||||||
|
}
|
||||||
|
else if(responses['default']) {
|
||||||
response = responses['default'];
|
response = responses['default'];
|
||||||
|
defaultResponseCode = 'default';
|
||||||
|
}
|
||||||
|
|
||||||
if(response && response.schema) {
|
if(response && response.schema) {
|
||||||
var resolvedModel = this.resolveModel(response.schema, definitions);
|
var resolvedModel = this.resolveModel(response.schema, definitions);
|
||||||
if(resolvedModel) {
|
if(resolvedModel) {
|
||||||
this.type = resolvedModel.name;
|
this.type = resolvedModel.name;
|
||||||
this.responseSampleJSON = JSON.stringify(resolvedModel.getSampleValue(), null, 2);
|
this.responseSampleJSON = JSON.stringify(resolvedModel.getSampleValue(), null, 2);
|
||||||
this.responseClassSignature = resolvedModel.getMockSignature();
|
this.responseClassSignature = resolvedModel.getMockSignature();
|
||||||
|
delete responses[defaultResponseCode];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.type = response.schema.type;
|
this.type = response.schema.type;
|
||||||
|
|||||||
214
dist/lib/swagger.js
vendored
214
dist/lib/swagger.js
vendored
@@ -1,7 +1,5 @@
|
|||||||
// swagger.js
|
// swagger.js
|
||||||
// version 2.0.41
|
// version 2.0.34
|
||||||
|
|
||||||
(function () {
|
|
||||||
|
|
||||||
var __bind = function(fn, me){
|
var __bind = function(fn, me){
|
||||||
return function(){
|
return function(){
|
||||||
@@ -9,7 +7,7 @@
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
var log = function () {
|
log = function(){
|
||||||
log.history = log.history || [];
|
log.history = log.history || [];
|
||||||
log.history.push(arguments);
|
log.history.push(arguments);
|
||||||
if(this.console){
|
if(this.console){
|
||||||
@@ -17,16 +15,6 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// 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++) {
|
||||||
@@ -91,8 +79,8 @@
|
|||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|
||||||
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;
|
||||||
@@ -100,8 +88,6 @@
|
|||||||
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)
|
||||||
@@ -123,15 +109,11 @@
|
|||||||
|
|
||||||
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 = {
|
||||||
@@ -139,7 +121,7 @@
|
|||||||
url: this.url,
|
url: this.url,
|
||||||
method: "get",
|
method: "get",
|
||||||
headers: {
|
headers: {
|
||||||
accept: "application/json,application/json;charset=\"utf-8\",*/*"
|
accept: "application/json"
|
||||||
},
|
},
|
||||||
on: {
|
on: {
|
||||||
error: function(response) {
|
error: function(response) {
|
||||||
@@ -176,7 +158,6 @@
|
|||||||
}
|
}
|
||||||
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) {
|
||||||
@@ -194,29 +175,28 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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;
|
||||||
var res = new SwaggerResource(response, this);
|
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];
|
||||||
var res = new SwaggerResource(resource, this);
|
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();
|
||||||
}
|
}
|
||||||
@@ -259,12 +239,11 @@
|
|||||||
} 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];
|
||||||
var res = new SwaggerResource(resource, this);
|
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();
|
||||||
}
|
}
|
||||||
@@ -297,6 +276,7 @@
|
|||||||
|
|
||||||
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) {
|
||||||
@@ -341,8 +321,8 @@
|
|||||||
var _this = this;
|
var _this = this;
|
||||||
this.api = api;
|
this.api = api;
|
||||||
this.api = this.api;
|
this.api = this.api;
|
||||||
var consumes = (this.consumes | []);
|
produces = [];
|
||||||
var produces = (this.produces | []);
|
consumes = [];
|
||||||
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;
|
||||||
|
|
||||||
@@ -368,12 +348,12 @@
|
|||||||
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);
|
||||||
var obj = {
|
obj = {
|
||||||
url: this.url,
|
url: this.url,
|
||||||
method: "get",
|
method: "get",
|
||||||
useJQuery: this.useJQuery,
|
useJQuery: this.useJQuery,
|
||||||
headers: {
|
headers: {
|
||||||
accept: "application/json,application/json;charset=\"utf-8\",*/*"
|
accept: "application/json"
|
||||||
},
|
},
|
||||||
on: {
|
on: {
|
||||||
response: function(resp) {
|
response: function(resp) {
|
||||||
@@ -450,7 +430,7 @@
|
|||||||
}
|
}
|
||||||
var output = [];
|
var output = [];
|
||||||
for (var i = 0; i < this.modelsArray.length; i++) {
|
for (var i = 0; i < this.modelsArray.length; i++) {
|
||||||
var model = this.modelsArray[i];
|
model = this.modelsArray[i];
|
||||||
output.push(model.setReferencedModels(this.models));
|
output.push(model.setReferencedModels(this.models));
|
||||||
}
|
}
|
||||||
return output;
|
return output;
|
||||||
@@ -459,9 +439,9 @@
|
|||||||
|
|
||||||
SwaggerResource.prototype.addOperations = function(resource_path, ops, consumes, produces) {
|
SwaggerResource.prototype.addOperations = function(resource_path, ops, consumes, produces) {
|
||||||
if (ops) {
|
if (ops) {
|
||||||
var output = [];
|
output = [];
|
||||||
for (var i = 0; i < ops.length; i++) {
|
for (var i = 0; i < ops.length; i++) {
|
||||||
var o = ops[i];
|
o = ops[i];
|
||||||
consumes = this.consumes;
|
consumes = this.consumes;
|
||||||
produces = this.produces;
|
produces = this.produces;
|
||||||
if (o.consumes != null)
|
if (o.consumes != null)
|
||||||
@@ -473,7 +453,7 @@
|
|||||||
produces = o.produces;
|
produces = o.produces;
|
||||||
else
|
else
|
||||||
produces = this.produces;
|
produces = this.produces;
|
||||||
var type = (o.type || o.responseClass);
|
type = (o.type||o.responseClass);
|
||||||
|
|
||||||
if (type === "array") {
|
if (type === "array") {
|
||||||
ref = null;
|
ref = null;
|
||||||
@@ -481,8 +461,8 @@
|
|||||||
ref = o.items["type"] || o.items["$ref"];
|
ref = o.items["type"] || o.items["$ref"];
|
||||||
type = "array[" + ref + "]";
|
type = "array[" + ref + "]";
|
||||||
}
|
}
|
||||||
var responseMessages = o.responseMessages;
|
responseMessages = o.responseMessages;
|
||||||
var method = o.method;
|
method = o.method;
|
||||||
if (o.httpMethod) {
|
if (o.httpMethod) {
|
||||||
method = o.httpMethod;
|
method = o.httpMethod;
|
||||||
}
|
}
|
||||||
@@ -498,7 +478,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
o.nickname = this.sanitize(o.nickname);
|
o.nickname = this.sanitize(o.nickname);
|
||||||
var op = new SwaggerOperation(o.nickname, resource_path, method, o.parameters, o.summary, o.notes, type, responseMessages, this, consumes, produces, o.authorizations);
|
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));
|
||||||
}
|
}
|
||||||
@@ -544,7 +524,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var prop = new SwaggerModelProperty(propertyName, obj.properties[propertyName]);
|
prop = new SwaggerModelProperty(propertyName, obj.properties[propertyName]);
|
||||||
this.properties.push(prop);
|
this.properties.push(prop);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -567,7 +547,7 @@
|
|||||||
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++) {
|
||||||
var prop = this.properties[i];
|
prop = this.properties[i];
|
||||||
propertiesStr.push(prop.toString());
|
propertiesStr.push(prop.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -582,7 +562,7 @@
|
|||||||
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++) {
|
||||||
var prop = this.properties[i];
|
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));
|
||||||
}
|
}
|
||||||
@@ -599,7 +579,7 @@
|
|||||||
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++) {
|
||||||
var prop = this.properties[i];
|
prop = this.properties[i];
|
||||||
result[prop.name] = prop.getSampleValue(modelsToIgnore);
|
result[prop.name] = prop.getSampleValue(modelsToIgnore);
|
||||||
}
|
}
|
||||||
modelsToIgnore.pop(this.name);
|
modelsToIgnore.pop(this.name);
|
||||||
@@ -613,7 +593,6 @@
|
|||||||
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;
|
||||||
@@ -641,7 +620,7 @@
|
|||||||
|
|
||||||
SwaggerModelProperty.prototype.getSampleValue = function(modelsToIgnore) {
|
SwaggerModelProperty.prototype.getSampleValue = function(modelsToIgnore) {
|
||||||
var result;
|
var result;
|
||||||
if ((this.refModel != null) && (modelsToIgnore.indexOf(this.refModel.name) === -1)) {
|
if ((this.refModel != null) && (modelsToIgnore.indexOf(prop.refModel.name) === -1)) {
|
||||||
result = this.refModel.createJSONSample(modelsToIgnore);
|
result = this.refModel.createJSONSample(modelsToIgnore);
|
||||||
} else {
|
} else {
|
||||||
if (this.isCollection) {
|
if (this.isCollection) {
|
||||||
@@ -659,9 +638,7 @@
|
|||||||
|
|
||||||
SwaggerModelProperty.prototype.toSampleValue = function(value) {
|
SwaggerModelProperty.prototype.toSampleValue = function(value) {
|
||||||
var result;
|
var result;
|
||||||
if ((typeof this.defaultValue !== 'undefined') && this.defaultValue !== null) {
|
if (value === "integer") {
|
||||||
result = this.defaultValue;
|
|
||||||
} else if (value === "integer") {
|
|
||||||
result = 0;
|
result = 0;
|
||||||
} else if (value === "boolean") {
|
} else if (value === "boolean") {
|
||||||
result = false;
|
result = false;
|
||||||
@@ -709,10 +686,8 @@
|
|||||||
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();
|
||||||
@@ -793,7 +768,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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);
|
||||||
@@ -914,7 +888,7 @@
|
|||||||
if (possibleParams) {
|
if (possibleParams) {
|
||||||
var key;
|
var key;
|
||||||
for (key in possibleParams) {
|
for (key in possibleParams) {
|
||||||
var value = possibleParams[key];
|
value = possibleParams[key];
|
||||||
if (args[value.name]) {
|
if (args[value.name]) {
|
||||||
params[value.name] = args[value.name];
|
params[value.name] = args[value.name];
|
||||||
}
|
}
|
||||||
@@ -961,7 +935,7 @@
|
|||||||
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('\\{\\s*?' + param.name + '.*?\\}(?=\\s*?(\\/|$))', 'gi');
|
var reg = new RegExp('\{' + param.name + '[^\}]*\}', '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];
|
||||||
}
|
}
|
||||||
@@ -1130,19 +1104,18 @@
|
|||||||
var body = params.body;
|
var body = params.body;
|
||||||
|
|
||||||
// encode the body for form submits
|
// encode the body for form submits
|
||||||
if (headers["Content-Type"]) {
|
if (headers["Accept"] && headers["Accept"].indexOf("application/x-www-form-urlencoded") === 0) {
|
||||||
|
var fields = {};
|
||||||
|
var possibleParams = {};
|
||||||
var values = {};
|
var values = {};
|
||||||
var i;
|
var key;
|
||||||
var operationParams = this.operation.parameters;
|
for(key in formParams){
|
||||||
for (i = 0; i < operationParams.length; i++) {
|
var param = formParams[key];
|
||||||
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, value;
|
var key;
|
||||||
for(key in values) {
|
for(key in values) {
|
||||||
value = this.params[key];
|
value = this.params[key];
|
||||||
if(typeof value !== 'undefined'){
|
if(typeof value !== 'undefined'){
|
||||||
@@ -1153,27 +1126,7 @@
|
|||||||
}
|
}
|
||||||
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,
|
||||||
@@ -1202,7 +1155,7 @@
|
|||||||
} else {
|
} else {
|
||||||
e = exports;
|
e = exports;
|
||||||
}
|
}
|
||||||
var status = e.authorizations.apply(obj, this.operation.authorizations);
|
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);
|
||||||
@@ -1213,13 +1166,12 @@
|
|||||||
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 consumes = "application/json";
|
var contentType = null;
|
||||||
|
|
||||||
var allDefinedParams = this.operation.parameters;
|
var allDefinedParams = this.operation.parameters;
|
||||||
var definedFormParams = [];
|
var definedFormParams = [];
|
||||||
@@ -1246,25 +1198,25 @@
|
|||||||
// 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)
|
||||||
consumes = this.opts.requestContentType;
|
accepts = 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)
|
||||||
consumes = "multipart/form-data";
|
accepts = "multipart/form-data";
|
||||||
else
|
else
|
||||||
consumes = "application/x-www-form-urlencoded";
|
accepts = "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 (consumes && this.operation.consumes) {
|
if (contentType && this.operation.consumes) {
|
||||||
if (this.operation.consumes.indexOf(consumes) === -1) {
|
if (this.operation.consumes.indexOf(contentType) === -1) {
|
||||||
log("server doesn't consume " + consumes + ", try " + JSON.stringify(this.operation.consumes));
|
log("server doesn't consume " + contentType + ", try " + JSON.stringify(this.operation.consumes));
|
||||||
consumes = this.operation.consumes[0];
|
contentType = this.operation.consumes[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1279,11 +1231,33 @@
|
|||||||
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;
|
||||||
|
}
|
||||||
|
|
||||||
if ((consumes && body !== "") || (consumes === "application/x-www-form-urlencoded"))
|
var encoded = "";
|
||||||
headers["Content-Type"] = consumes;
|
var key;
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1489,36 +1463,11 @@
|
|||||||
return out;
|
return out;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Transform an error into a usable response-like object
|
res = {
|
||||||
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));
|
||||||
@@ -1556,7 +1505,7 @@
|
|||||||
|
|
||||||
SwaggerAuthorizations.prototype.apply = function(obj, authorizations) {
|
SwaggerAuthorizations.prototype.apply = function(obj, authorizations) {
|
||||||
var status = null;
|
var status = null;
|
||||||
var key, value, result;
|
var key;
|
||||||
|
|
||||||
// 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) {
|
||||||
@@ -1586,11 +1535,10 @@
|
|||||||
/**
|
/**
|
||||||
* 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, delimiter) {
|
var ApiKeyAuthorization = function(name, value, type) {
|
||||||
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) {
|
||||||
@@ -1601,11 +1549,6 @@
|
|||||||
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;
|
||||||
}
|
}
|
||||||
@@ -1660,6 +1603,3 @@
|
|||||||
e.SwaggerModelProperty = SwaggerModelProperty;
|
e.SwaggerModelProperty = SwaggerModelProperty;
|
||||||
e.SwaggerResource = SwaggerResource;
|
e.SwaggerResource = SwaggerResource;
|
||||||
e.SwaggerApi = SwaggerApi;
|
e.SwaggerApi = SwaggerApi;
|
||||||
e.log = log;
|
|
||||||
|
|
||||||
})();
|
|
||||||
|
|||||||
46
dist/swagger-ui.js
vendored
46
dist/swagger-ui.js
vendored
@@ -1637,7 +1637,7 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
|
|||||||
};
|
};
|
||||||
|
|
||||||
OperationView.prototype.render = function() {
|
OperationView.prototype.render = function() {
|
||||||
var contentTypeModel, isMethodSubmissionSupported, k, o, param, ref, responseContentTypeView, responseSignatureView, schema, signatureModel, statusCode, type, v, _i, _j, _k, _l, _len, _len1, _len2, _len3, _ref5, _ref6, _ref7, _ref8;
|
var code, contentTypeModel, isMethodSubmissionSupported, k, o, param, ref, responseContentTypeView, responseSignatureView, schema, schemaObj, signatureModel, statusCode, type, v, value, _i, _j, _k, _l, _len, _len1, _len2, _len3, _ref5, _ref6, _ref7, _ref8, _ref9;
|
||||||
isMethodSubmissionSupported = true;
|
isMethodSubmissionSupported = true;
|
||||||
if (!isMethodSubmissionSupported) {
|
if (!isMethodSubmissionSupported) {
|
||||||
this.model.isReadOnly = true;
|
this.model.isReadOnly = true;
|
||||||
@@ -1661,6 +1661,29 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (typeof this.model.responses !== 'undefined') {
|
||||||
|
this.model.responseMessages = [];
|
||||||
|
_ref6 = this.model.responses;
|
||||||
|
for (code in _ref6) {
|
||||||
|
value = _ref6[code];
|
||||||
|
schema = null;
|
||||||
|
schemaObj = this.model.responses[code].schema;
|
||||||
|
if (schemaObj && schemaObj['$ref']) {
|
||||||
|
schema = schemaObj['$ref'];
|
||||||
|
if (schema.indexOf('#/definitions/') === 0) {
|
||||||
|
schema = schema.substring('#/definitions/'.length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.model.responseMessages.push({
|
||||||
|
code: code,
|
||||||
|
message: value.description,
|
||||||
|
responseModel: schema
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (typeof this.model.responseMessages === 'undefined') {
|
||||||
|
this.model.responseMessages = [];
|
||||||
|
}
|
||||||
$(this.el).html(Handlebars.templates.operation(this.model));
|
$(this.el).html(Handlebars.templates.operation(this.model));
|
||||||
if (this.model.responseClassSignature && this.model.responseClassSignature !== 'string') {
|
if (this.model.responseClassSignature && this.model.responseClassSignature !== 'string') {
|
||||||
signatureModel = {
|
signatureModel = {
|
||||||
@@ -1682,9 +1705,9 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
|
|||||||
};
|
};
|
||||||
contentTypeModel.consumes = this.model.consumes;
|
contentTypeModel.consumes = this.model.consumes;
|
||||||
contentTypeModel.produces = this.model.produces;
|
contentTypeModel.produces = this.model.produces;
|
||||||
_ref6 = this.model.parameters;
|
_ref7 = this.model.parameters;
|
||||||
for (_j = 0, _len1 = _ref6.length; _j < _len1; _j++) {
|
for (_j = 0, _len1 = _ref7.length; _j < _len1; _j++) {
|
||||||
param = _ref6[_j];
|
param = _ref7[_j];
|
||||||
type = param.type || param.dataType;
|
type = param.type || param.dataType;
|
||||||
if (typeof type === 'undefined') {
|
if (typeof type === 'undefined') {
|
||||||
schema = param.schema;
|
schema = param.schema;
|
||||||
@@ -1708,17 +1731,14 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
|
|||||||
model: contentTypeModel
|
model: contentTypeModel
|
||||||
});
|
});
|
||||||
$('.response-content-type', $(this.el)).append(responseContentTypeView.render().el);
|
$('.response-content-type', $(this.el)).append(responseContentTypeView.render().el);
|
||||||
_ref7 = this.model.parameters;
|
_ref8 = this.model.parameters;
|
||||||
for (_k = 0, _len2 = _ref7.length; _k < _len2; _k++) {
|
for (_k = 0, _len2 = _ref8.length; _k < _len2; _k++) {
|
||||||
param = _ref7[_k];
|
param = _ref8[_k];
|
||||||
this.addParameter(param, contentTypeModel.consumes);
|
this.addParameter(param, contentTypeModel.consumes);
|
||||||
}
|
}
|
||||||
if (typeof this.model.responseMessages === 'undefined') {
|
_ref9 = this.model.responseMessages;
|
||||||
this.model.responseMessages = [];
|
for (_l = 0, _len3 = _ref9.length; _l < _len3; _l++) {
|
||||||
}
|
statusCode = _ref9[_l];
|
||||||
_ref8 = this.model.responseMessages;
|
|
||||||
for (_l = 0, _len3 = _ref8.length; _l < _len3; _l++) {
|
|
||||||
statusCode = _ref8[_l];
|
|
||||||
this.addStatusCode(statusCode);
|
this.addStatusCode(statusCode);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
|
|||||||
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
@@ -187,6 +187,7 @@ var SwaggerClient = function(url, options) {
|
|||||||
this.isValid = false;
|
this.isValid = false;
|
||||||
this.info = null;
|
this.info = null;
|
||||||
this.useJQuery = false;
|
this.useJQuery = false;
|
||||||
|
this.models = models;
|
||||||
|
|
||||||
options = (options||{});
|
options = (options||{});
|
||||||
if (url)
|
if (url)
|
||||||
@@ -237,10 +238,12 @@ SwaggerClient.prototype.build = function() {
|
|||||||
if(responseObj.swagger && responseObj.swagger === 2.0) {
|
if(responseObj.swagger && responseObj.swagger === 2.0) {
|
||||||
self.swaggerVersion = responseObj.swagger;
|
self.swaggerVersion = responseObj.swagger;
|
||||||
self.buildFromSpec(responseObj);
|
self.buildFromSpec(responseObj);
|
||||||
this.isValid = true;
|
self.isValid = true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
self.isValid = false;
|
||||||
|
self.failure();
|
||||||
}
|
}
|
||||||
else
|
|
||||||
this.isValid = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -418,16 +421,22 @@ var Operation = function(parent, operationId, httpMethod, path, args, definition
|
|||||||
var model;
|
var model;
|
||||||
var responses = this.responses;
|
var responses = this.responses;
|
||||||
|
|
||||||
if(responses['200'])
|
if(responses['200']) {
|
||||||
response = responses['200'];
|
response = responses['200'];
|
||||||
else if(responses['default'])
|
defaultResponseCode = '200';
|
||||||
|
}
|
||||||
|
else if(responses['default']) {
|
||||||
response = responses['default'];
|
response = responses['default'];
|
||||||
|
defaultResponseCode = 'default';
|
||||||
|
}
|
||||||
|
|
||||||
if(response && response.schema) {
|
if(response && response.schema) {
|
||||||
var resolvedModel = this.resolveModel(response.schema, definitions);
|
var resolvedModel = this.resolveModel(response.schema, definitions);
|
||||||
if(resolvedModel) {
|
if(resolvedModel) {
|
||||||
this.type = resolvedModel.name;
|
this.type = resolvedModel.name;
|
||||||
this.responseSampleJSON = JSON.stringify(resolvedModel.getSampleValue(), null, 2);
|
this.responseSampleJSON = JSON.stringify(resolvedModel.getSampleValue(), null, 2);
|
||||||
this.responseClassSignature = resolvedModel.getMockSignature();
|
this.responseClassSignature = resolvedModel.getMockSignature();
|
||||||
|
delete responses[defaultResponseCode];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.type = response.schema.type;
|
this.type = response.schema.type;
|
||||||
@@ -446,7 +455,158 @@ OperationGroup.prototype.sort = function(sorter) {
|
|||||||
|
|
||||||
Operation.prototype.getType = function (param) {
|
Operation.prototype.getType = function (param) {
|
||||||
var type = param.type;
|
var type = param.type;
|
||||||
var format = param.format;
|
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 isArray = false;
|
var isArray = false;
|
||||||
var str;
|
var str;
|
||||||
if(type === 'integer' && format === 'int32')
|
if(type === 'integer' && format === 'int32')
|
||||||
@@ -608,7 +768,69 @@ Operation.prototype.execute = function(arg1, arg2, arg3, arg4, parent) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// set content type negotiation
|
// 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
|
||||||
var consumes = this.consumes || this.parent.consumes || [ 'application/json' ];
|
var consumes = this.consumes || this.parent.consumes || [ 'application/json' ];
|
||||||
var produces = this.produces || this.parent.produces || [ 'application/json' ];
|
var produces = this.produces || this.parent.produces || [ 'application/json' ];
|
||||||
|
|
||||||
@@ -1112,217 +1334,4 @@ e.authorizations = new SwaggerAuthorizations();
|
|||||||
e.ApiKeyAuthorization = ApiKeyAuthorization;
|
e.ApiKeyAuthorization = ApiKeyAuthorization;
|
||||||
e.PasswordAuthorization = PasswordAuthorization;
|
e.PasswordAuthorization = PasswordAuthorization;
|
||||||
e.CookieAuthorization = CookieAuthorization;
|
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);
|
|
||||||
};
|
|
||||||
@@ -55,6 +55,20 @@ class OperationView extends Backbone.View
|
|||||||
for o in v
|
for o in v
|
||||||
@model.oauth.scopes.push o
|
@model.oauth.scopes.push o
|
||||||
|
|
||||||
|
if typeof @model.responses isnt 'undefined'
|
||||||
|
@model.responseMessages = []
|
||||||
|
for code, value of @model.responses
|
||||||
|
schema = null
|
||||||
|
schemaObj = @model.responses[code].schema
|
||||||
|
if schemaObj and schemaObj['$ref']
|
||||||
|
schema = schemaObj['$ref']
|
||||||
|
if schema.indexOf('#/definitions/') is 0
|
||||||
|
schema = schema.substring('#/definitions/'.length)
|
||||||
|
@model.responseMessages.push {code: code, message: value.description, responseModel: schema }
|
||||||
|
|
||||||
|
if typeof @model.responseMessages is 'undefined'
|
||||||
|
@model.responseMessages = []
|
||||||
|
|
||||||
$(@el).html(Handlebars.templates.operation(@model))
|
$(@el).html(Handlebars.templates.operation(@model))
|
||||||
|
|
||||||
if @model.responseClassSignature and @model.responseClassSignature != 'string'
|
if @model.responseClassSignature and @model.responseClassSignature != 'string'
|
||||||
@@ -97,8 +111,6 @@ class OperationView extends Backbone.View
|
|||||||
@addParameter param, contentTypeModel.consumes for param in @model.parameters
|
@addParameter param, contentTypeModel.consumes for param in @model.parameters
|
||||||
|
|
||||||
# Render each response code
|
# Render each response code
|
||||||
if typeof @model.responseMessages is 'undefined'
|
|
||||||
@model.responseMessages = []
|
|
||||||
@addStatusCode statusCode for statusCode in @model.responseMessages
|
@addStatusCode statusCode for statusCode in @model.responseMessages
|
||||||
|
|
||||||
@
|
@
|
||||||
|
|||||||
Reference in New Issue
Block a user