@@ -49,7 +49,6 @@ | |||
var e, obj, | |||
_this = this; | |||
this.progress('fetching resource list: ' + this.url); | |||
console.log('getting ' + this.url); | |||
obj = { | |||
url: this.url, | |||
method: "get", | |||
@@ -387,13 +386,14 @@ | |||
} | |||
SwaggerModel.prototype.setReferencedModels = function(allModels) { | |||
var prop, _i, _len, _ref, _results; | |||
var prop, type, _i, _len, _ref, _results; | |||
_ref = this.properties; | |||
_results = []; | |||
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | |||
prop = _ref[_i]; | |||
if (allModels[prop.dataType] != null) { | |||
_results.push(prop.refModel = allModels[prop.dataType]); | |||
type = prop.type || prop.dataType; | |||
if (allModels[type] != null) { | |||
_results.push(prop.refModel = allModels[type]); | |||
} else if ((prop.refDataType != null) && (allModels[prop.refDataType] != null)) { | |||
_results.push(prop.refModel = allModels[prop.refDataType]); | |||
} else { | |||
@@ -516,7 +516,7 @@ | |||
SwaggerOperation = (function() { | |||
function SwaggerOperation(nickname, path, method, parameters, summary, notes, responseClass, responseMessages, resource, consumes, produces) { | |||
var parameter, v, _i, _j, _len, _len1, _ref, _ref1, _ref2, | |||
var parameter, type, v, _i, _j, _len, _len1, _ref, _ref1, _ref2, | |||
_this = this; | |||
this.nickname = nickname; | |||
this.path = path; | |||
@@ -555,13 +555,14 @@ | |||
_ref1 = this.parameters; | |||
for (_i = 0, _len = _ref1.length; _i < _len; _i++) { | |||
parameter = _ref1[_i]; | |||
parameter.name = parameter.name || parameter.dataType; | |||
if (parameter.dataType.toLowerCase() === 'boolean') { | |||
parameter.name = parameter.name || parameter.type || parameter.dataType; | |||
type = parameter.type || parameter.dataType; | |||
if (type.toLowerCase() === 'boolean') { | |||
parameter.allowableValues = {}; | |||
parameter.allowableValues.values = this.resource.api.booleanValues; | |||
} | |||
parameter.signature = this.getSignature(parameter.dataType, this.resource.models); | |||
parameter.sampleJSON = this.getSampleJSON(parameter.dataType, this.resource.models); | |||
parameter.signature = this.getSignature(type, this.resource.models); | |||
parameter.sampleJSON = this.getSampleJSON(type, this.resource.models); | |||
if (parameter.allowableValues != null) { | |||
if (parameter.allowableValues.valueType === "RANGE") { | |||
parameter.isRange = true; | |||
@@ -596,34 +597,34 @@ | |||
}; | |||
} | |||
SwaggerOperation.prototype.isListType = function(dataType) { | |||
if (dataType.indexOf('[') >= 0) { | |||
return dataType.substring(dataType.indexOf('[') + 1, dataType.indexOf(']')); | |||
SwaggerOperation.prototype.isListType = function(type) { | |||
if (type.indexOf('[') >= 0) { | |||
return type.substring(type.indexOf('[') + 1, type.indexOf(']')); | |||
} else { | |||
return void 0; | |||
} | |||
}; | |||
SwaggerOperation.prototype.getSignature = function(dataType, models) { | |||
SwaggerOperation.prototype.getSignature = function(type, models) { | |||
var isPrimitive, listType; | |||
listType = this.isListType(dataType); | |||
isPrimitive = ((listType != null) && models[listType]) || (models[dataType] != null) ? false : true; | |||
listType = this.isListType(type); | |||
isPrimitive = ((listType != null) && models[listType]) || (models[type] != null) ? false : true; | |||
if (isPrimitive) { | |||
return dataType; | |||
return type; | |||
} else { | |||
if (listType != null) { | |||
return models[listType].getMockSignature(); | |||
} else { | |||
return models[dataType].getMockSignature(); | |||
return models[type].getMockSignature(); | |||
} | |||
} | |||
}; | |||
SwaggerOperation.prototype.getSampleJSON = function(dataType, models) { | |||
SwaggerOperation.prototype.getSampleJSON = function(type, models) { | |||
var isPrimitive, listType, val; | |||
listType = this.isListType(dataType); | |||
isPrimitive = ((listType != null) && models[listType]) || (models[dataType] != null) ? false : true; | |||
val = isPrimitive ? void 0 : (listType != null ? models[listType].createJSONSample() : models[dataType].createJSONSample()); | |||
listType = this.isListType(type); | |||
isPrimitive = ((listType != null) && models[listType]) || (models[type] != null) ? false : true; | |||
val = isPrimitive ? void 0 : (listType != null ? models[listType].createJSONSample() : models[type].createJSONSample()); | |||
if (val) { | |||
val = listType ? [val] : val; | |||
return JSON.stringify(val, null, 2); | |||
@@ -849,13 +850,14 @@ | |||
} | |||
return _results; | |||
}).call(this)).length > 0) { | |||
type = param.type || param.dataType; | |||
if (((function() { | |||
var _i, _len, _ref, _results; | |||
_ref = this.operation.parameters; | |||
_results = []; | |||
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | |||
param = _ref[_i]; | |||
if (param.dataType.toLowerCase() === "file") { | |||
if (type.toLowerCase() === "file") { | |||
_results.push(param); | |||
} | |||
} | |||
@@ -878,14 +880,14 @@ | |||
} | |||
} | |||
responseContentType = null; | |||
if (this.type === "POST" || this.type === "GET") { | |||
if (this.type === "POST" || this.type === "GET" || this.type === "PATCH" || this.type === "PUT") { | |||
if (this.opts.responseContentType) { | |||
responseContentType = this.opts.responseContentType; | |||
requestContentType = this.opts.requestContentType; | |||
} else { | |||
responseContentType = "application/json"; | |||
requestContentType = "application/json"; | |||
} | |||
} else { | |||
responseContentType = null; | |||
requestContentType = null; | |||
} | |||
if (responseContentType && this.operation.produces) { | |||
if (this.operation.produces.indexOf(responseContentType) === -1) { | |||
@@ -1729,7 +1729,7 @@ templates['status_code'] = template(function (Handlebars,depth0,helpers,partials | |||
OperationView.prototype.initialize = function() {}; | |||
OperationView.prototype.render = function() { | |||
var contentTypeModel, isMethodSubmissionSupported, param, responseContentTypeView, responseSignatureView, signatureModel, statusCode, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2; | |||
var contentTypeModel, isMethodSubmissionSupported, param, responseContentTypeView, responseSignatureView, signatureModel, statusCode, type, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2; | |||
isMethodSubmissionSupported = true; | |||
if (!isMethodSubmissionSupported) { | |||
this.model.isReadOnly = true; | |||
@@ -1757,7 +1757,8 @@ templates['status_code'] = template(function (Handlebars,depth0,helpers,partials | |||
_ref = this.model.parameters; | |||
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | |||
param = _ref[_i]; | |||
if (param.dataType.toLowerCase() === 'file') { | |||
type = param.type || param.dataType; | |||
if (type.toLowerCase() === 'file') { | |||
if (!contentTypeModel.consumes) { | |||
console.log("set content type "); | |||
contentTypeModel.consumes = 'multipart/form-data'; | |||
@@ -1802,7 +1803,7 @@ templates['status_code'] = template(function (Handlebars,depth0,helpers,partials | |||
}; | |||
OperationView.prototype.submitOperation = function(e) { | |||
var error_free, form, map, o, opts, _i, _len, _ref; | |||
var error_free, form, map, o, opts, _i, _j, _len, _len1, _ref, _ref1; | |||
if (e != null) { | |||
e.preventDefault(); | |||
} | |||
@@ -1833,6 +1834,13 @@ templates['status_code'] = template(function (Handlebars,depth0,helpers,partials | |||
map[o.name] = encodeURI(o.value); | |||
} | |||
} | |||
_ref1 = form.find("textarea"); | |||
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { | |||
o = _ref1[_j]; | |||
if ((o.value != null) && jQuery.trim(o.value).length > 0) { | |||
map["body"] = o.value; | |||
} | |||
} | |||
opts.responseContentType = $("div select[name=responseContentType]", $(this.el)).val(); | |||
opts.requestContentType = $("div select[name=parameterContentType]", $(this.el)).val(); | |||
return this.model["do"](map, opts, this.showCompleteStatus, this.showErrorStatus, this); | |||
@@ -2020,11 +2028,12 @@ templates['status_code'] = template(function (Handlebars,depth0,helpers,partials | |||
ParameterView.prototype.initialize = function() {}; | |||
ParameterView.prototype.render = function() { | |||
var contentTypeModel, isParam, parameterContentTypeView, responseContentTypeView, signatureModel, signatureView, template; | |||
var contentTypeModel, isParam, parameterContentTypeView, responseContentTypeView, signatureModel, signatureView, template, type; | |||
type = this.model.type || this.model.dataType; | |||
if (this.model.paramType === 'body') { | |||
this.model.isBody = true; | |||
} | |||
if (this.model.dataType.toLowerCase() === 'file') { | |||
if (type.toLowerCase() === 'file') { | |||
this.model.isFile = true; | |||
} | |||
template = this.template(); | |||
@@ -49,7 +49,6 @@ | |||
var e, obj, | |||
_this = this; | |||
this.progress('fetching resource list: ' + this.url); | |||
console.log('getting ' + this.url); | |||
obj = { | |||
url: this.url, | |||
method: "get", | |||
@@ -387,13 +386,14 @@ | |||
} | |||
SwaggerModel.prototype.setReferencedModels = function(allModels) { | |||
var prop, _i, _len, _ref, _results; | |||
var prop, type, _i, _len, _ref, _results; | |||
_ref = this.properties; | |||
_results = []; | |||
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | |||
prop = _ref[_i]; | |||
if (allModels[prop.dataType] != null) { | |||
_results.push(prop.refModel = allModels[prop.dataType]); | |||
type = prop.type || prop.dataType; | |||
if (allModels[type] != null) { | |||
_results.push(prop.refModel = allModels[type]); | |||
} else if ((prop.refDataType != null) && (allModels[prop.refDataType] != null)) { | |||
_results.push(prop.refModel = allModels[prop.refDataType]); | |||
} else { | |||
@@ -516,7 +516,7 @@ | |||
SwaggerOperation = (function() { | |||
function SwaggerOperation(nickname, path, method, parameters, summary, notes, responseClass, responseMessages, resource, consumes, produces) { | |||
var parameter, v, _i, _j, _len, _len1, _ref, _ref1, _ref2, | |||
var parameter, type, v, _i, _j, _len, _len1, _ref, _ref1, _ref2, | |||
_this = this; | |||
this.nickname = nickname; | |||
this.path = path; | |||
@@ -555,13 +555,14 @@ | |||
_ref1 = this.parameters; | |||
for (_i = 0, _len = _ref1.length; _i < _len; _i++) { | |||
parameter = _ref1[_i]; | |||
parameter.name = parameter.name || parameter.dataType; | |||
if (parameter.dataType.toLowerCase() === 'boolean') { | |||
parameter.name = parameter.name || parameter.type || parameter.dataType; | |||
type = parameter.type || parameter.dataType; | |||
if (type.toLowerCase() === 'boolean') { | |||
parameter.allowableValues = {}; | |||
parameter.allowableValues.values = this.resource.api.booleanValues; | |||
} | |||
parameter.signature = this.getSignature(parameter.dataType, this.resource.models); | |||
parameter.sampleJSON = this.getSampleJSON(parameter.dataType, this.resource.models); | |||
parameter.signature = this.getSignature(type, this.resource.models); | |||
parameter.sampleJSON = this.getSampleJSON(type, this.resource.models); | |||
if (parameter.allowableValues != null) { | |||
if (parameter.allowableValues.valueType === "RANGE") { | |||
parameter.isRange = true; | |||
@@ -596,34 +597,34 @@ | |||
}; | |||
} | |||
SwaggerOperation.prototype.isListType = function(dataType) { | |||
if (dataType.indexOf('[') >= 0) { | |||
return dataType.substring(dataType.indexOf('[') + 1, dataType.indexOf(']')); | |||
SwaggerOperation.prototype.isListType = function(type) { | |||
if (type.indexOf('[') >= 0) { | |||
return type.substring(type.indexOf('[') + 1, type.indexOf(']')); | |||
} else { | |||
return void 0; | |||
} | |||
}; | |||
SwaggerOperation.prototype.getSignature = function(dataType, models) { | |||
SwaggerOperation.prototype.getSignature = function(type, models) { | |||
var isPrimitive, listType; | |||
listType = this.isListType(dataType); | |||
isPrimitive = ((listType != null) && models[listType]) || (models[dataType] != null) ? false : true; | |||
listType = this.isListType(type); | |||
isPrimitive = ((listType != null) && models[listType]) || (models[type] != null) ? false : true; | |||
if (isPrimitive) { | |||
return dataType; | |||
return type; | |||
} else { | |||
if (listType != null) { | |||
return models[listType].getMockSignature(); | |||
} else { | |||
return models[dataType].getMockSignature(); | |||
return models[type].getMockSignature(); | |||
} | |||
} | |||
}; | |||
SwaggerOperation.prototype.getSampleJSON = function(dataType, models) { | |||
SwaggerOperation.prototype.getSampleJSON = function(type, models) { | |||
var isPrimitive, listType, val; | |||
listType = this.isListType(dataType); | |||
isPrimitive = ((listType != null) && models[listType]) || (models[dataType] != null) ? false : true; | |||
val = isPrimitive ? void 0 : (listType != null ? models[listType].createJSONSample() : models[dataType].createJSONSample()); | |||
listType = this.isListType(type); | |||
isPrimitive = ((listType != null) && models[listType]) || (models[type] != null) ? false : true; | |||
val = isPrimitive ? void 0 : (listType != null ? models[listType].createJSONSample() : models[type].createJSONSample()); | |||
if (val) { | |||
val = listType ? [val] : val; | |||
return JSON.stringify(val, null, 2); | |||
@@ -849,13 +850,14 @@ | |||
} | |||
return _results; | |||
}).call(this)).length > 0) { | |||
type = param.type || param.dataType; | |||
if (((function() { | |||
var _i, _len, _ref, _results; | |||
_ref = this.operation.parameters; | |||
_results = []; | |||
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | |||
param = _ref[_i]; | |||
if (param.dataType.toLowerCase() === "file") { | |||
if (type.toLowerCase() === "file") { | |||
_results.push(param); | |||
} | |||
} | |||
@@ -878,14 +880,14 @@ | |||
} | |||
} | |||
responseContentType = null; | |||
if (this.type === "POST" || this.type === "GET") { | |||
if (this.type === "POST" || this.type === "GET" || this.type === "PATCH" || this.type === "PUT") { | |||
if (this.opts.responseContentType) { | |||
responseContentType = this.opts.responseContentType; | |||
requestContentType = this.opts.requestContentType; | |||
} else { | |||
responseContentType = "application/json"; | |||
requestContentType = "application/json"; | |||
} | |||
} else { | |||
responseContentType = null; | |||
requestContentType = null; | |||
} | |||
if (responseContentType && this.operation.produces) { | |||
if (this.operation.produces.indexOf(responseContentType) === -1) { | |||
@@ -32,7 +32,8 @@ class OperationView extends Backbone.View | |||
contentTypeModel.produces = @model.produces | |||
for param in @model.parameters | |||
if param.dataType.toLowerCase() == 'file' | |||
type = param.type || param.dataType | |||
if type.toLowerCase() == 'file' | |||
if !contentTypeModel.consumes | |||
console.log "set content type " | |||
contentTypeModel.consumes = 'multipart/form-data' | |||
@@ -84,6 +85,10 @@ class OperationView extends Backbone.View | |||
if(o.value? && jQuery.trim(o.value).length > 0) | |||
map[o.name] = encodeURI(o.value) | |||
for o in form.find("textarea") | |||
if(o.value? && jQuery.trim(o.value).length > 0) | |||
map["body"] = o.value | |||
opts.responseContentType = $("div select[name=responseContentType]", $(@el)).val() | |||
opts.requestContentType = $("div select[name=parameterContentType]", $(@el)).val() | |||
@@ -2,8 +2,9 @@ class ParameterView extends Backbone.View | |||
initialize: -> | |||
render: -> | |||
type = @model.type || @model.dataType | |||
@model.isBody = true if @model.paramType == 'body' | |||
@model.isFile = true if @model.dataType.toLowerCase() == 'file' | |||
@model.isFile = true if type.toLowerCase() == 'file' | |||
template = @template() | |||
$(@el).html(template(@model)) | |||