Commit 4b5e4e5d authored by Tony Tam's avatar Tony Tam
Browse files

updated for 1.2 support

parent b2637fc4
...@@ -49,7 +49,6 @@ ...@@ -49,7 +49,6 @@
var e, obj, var e, obj,
_this = this; _this = this;
this.progress('fetching resource list: ' + this.url); this.progress('fetching resource list: ' + this.url);
console.log('getting ' + this.url);
obj = { obj = {
url: this.url, url: this.url,
method: "get", method: "get",
...@@ -387,13 +386,14 @@ ...@@ -387,13 +386,14 @@
} }
SwaggerModel.prototype.setReferencedModels = function(allModels) { SwaggerModel.prototype.setReferencedModels = function(allModels) {
var prop, _i, _len, _ref, _results; var prop, type, _i, _len, _ref, _results;
_ref = this.properties; _ref = this.properties;
_results = []; _results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
prop = _ref[_i]; prop = _ref[_i];
if (allModels[prop.dataType] != null) { type = prop.type || prop.dataType;
_results.push(prop.refModel = allModels[prop.dataType]); if (allModels[type] != null) {
_results.push(prop.refModel = allModels[type]);
} else if ((prop.refDataType != null) && (allModels[prop.refDataType] != null)) { } else if ((prop.refDataType != null) && (allModels[prop.refDataType] != null)) {
_results.push(prop.refModel = allModels[prop.refDataType]); _results.push(prop.refModel = allModels[prop.refDataType]);
} else { } else {
...@@ -516,7 +516,7 @@ ...@@ -516,7 +516,7 @@
SwaggerOperation = (function() { SwaggerOperation = (function() {
function SwaggerOperation(nickname, path, method, parameters, summary, notes, responseClass, responseMessages, resource, consumes, produces) { 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 = this;
this.nickname = nickname; this.nickname = nickname;
this.path = path; this.path = path;
...@@ -555,13 +555,14 @@ ...@@ -555,13 +555,14 @@
_ref1 = this.parameters; _ref1 = this.parameters;
for (_i = 0, _len = _ref1.length; _i < _len; _i++) { for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
parameter = _ref1[_i]; parameter = _ref1[_i];
parameter.name = parameter.name || parameter.dataType; parameter.name = parameter.name || parameter.type || parameter.dataType;
if (parameter.dataType.toLowerCase() === 'boolean') { type = parameter.type || parameter.dataType;
if (type.toLowerCase() === 'boolean') {
parameter.allowableValues = {}; parameter.allowableValues = {};
parameter.allowableValues.values = this.resource.api.booleanValues; parameter.allowableValues.values = this.resource.api.booleanValues;
} }
parameter.signature = this.getSignature(parameter.dataType, this.resource.models); parameter.signature = this.getSignature(type, this.resource.models);
parameter.sampleJSON = this.getSampleJSON(parameter.dataType, this.resource.models); parameter.sampleJSON = this.getSampleJSON(type, this.resource.models);
if (parameter.allowableValues != null) { if (parameter.allowableValues != null) {
if (parameter.allowableValues.valueType === "RANGE") { if (parameter.allowableValues.valueType === "RANGE") {
parameter.isRange = true; parameter.isRange = true;
...@@ -596,34 +597,34 @@ ...@@ -596,34 +597,34 @@
}; };
} }
SwaggerOperation.prototype.isListType = function(dataType) { SwaggerOperation.prototype.isListType = function(type) {
if (dataType.indexOf('[') >= 0) { if (type.indexOf('[') >= 0) {
return dataType.substring(dataType.indexOf('[') + 1, dataType.indexOf(']')); return type.substring(type.indexOf('[') + 1, type.indexOf(']'));
} else { } else {
return void 0; return void 0;
} }
}; };
SwaggerOperation.prototype.getSignature = function(dataType, models) { SwaggerOperation.prototype.getSignature = function(type, models) {
var isPrimitive, listType; var isPrimitive, listType;
listType = this.isListType(dataType); listType = this.isListType(type);
isPrimitive = ((listType != null) && models[listType]) || (models[dataType] != null) ? false : true; isPrimitive = ((listType != null) && models[listType]) || (models[type] != null) ? false : true;
if (isPrimitive) { if (isPrimitive) {
return dataType; return type;
} else { } else {
if (listType != null) { if (listType != null) {
return models[listType].getMockSignature(); return models[listType].getMockSignature();
} else { } 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; var isPrimitive, listType, val;
listType = this.isListType(dataType); listType = this.isListType(type);
isPrimitive = ((listType != null) && models[listType]) || (models[dataType] != null) ? false : true; isPrimitive = ((listType != null) && models[listType]) || (models[type] != null) ? false : true;
val = isPrimitive ? void 0 : (listType != null ? models[listType].createJSONSample() : models[dataType].createJSONSample()); val = isPrimitive ? void 0 : (listType != null ? models[listType].createJSONSample() : models[type].createJSONSample());
if (val) { if (val) {
val = listType ? [val] : val; val = listType ? [val] : val;
return JSON.stringify(val, null, 2); return JSON.stringify(val, null, 2);
...@@ -849,13 +850,14 @@ ...@@ -849,13 +850,14 @@
} }
return _results; return _results;
}).call(this)).length > 0) { }).call(this)).length > 0) {
type = param.type || param.dataType;
if (((function() { if (((function() {
var _i, _len, _ref, _results; var _i, _len, _ref, _results;
_ref = this.operation.parameters; _ref = this.operation.parameters;
_results = []; _results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
param = _ref[_i]; param = _ref[_i];
if (param.dataType.toLowerCase() === "file") { if (type.toLowerCase() === "file") {
_results.push(param); _results.push(param);
} }
} }
...@@ -878,14 +880,14 @@ ...@@ -878,14 +880,14 @@
} }
} }
responseContentType = null; 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) { if (this.opts.responseContentType) {
responseContentType = this.opts.responseContentType; requestContentType = this.opts.requestContentType;
} else { } else {
responseContentType = "application/json"; requestContentType = "application/json";
} }
} else { } else {
responseContentType = null; requestContentType = null;
} }
if (responseContentType && this.operation.produces) { if (responseContentType && this.operation.produces) {
if (this.operation.produces.indexOf(responseContentType) === -1) { if (this.operation.produces.indexOf(responseContentType) === -1) {
......
...@@ -1729,7 +1729,7 @@ templates['status_code'] = template(function (Handlebars,depth0,helpers,partials ...@@ -1729,7 +1729,7 @@ templates['status_code'] = template(function (Handlebars,depth0,helpers,partials
OperationView.prototype.initialize = function() {}; OperationView.prototype.initialize = function() {};
OperationView.prototype.render = 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; isMethodSubmissionSupported = true;
if (!isMethodSubmissionSupported) { if (!isMethodSubmissionSupported) {
this.model.isReadOnly = true; this.model.isReadOnly = true;
...@@ -1757,7 +1757,8 @@ templates['status_code'] = template(function (Handlebars,depth0,helpers,partials ...@@ -1757,7 +1757,8 @@ templates['status_code'] = template(function (Handlebars,depth0,helpers,partials
_ref = this.model.parameters; _ref = this.model.parameters;
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
param = _ref[_i]; param = _ref[_i];
if (param.dataType.toLowerCase() === 'file') { type = param.type || param.dataType;
if (type.toLowerCase() === 'file') {
if (!contentTypeModel.consumes) { if (!contentTypeModel.consumes) {
console.log("set content type "); console.log("set content type ");
contentTypeModel.consumes = 'multipart/form-data'; contentTypeModel.consumes = 'multipart/form-data';
...@@ -1802,7 +1803,7 @@ templates['status_code'] = template(function (Handlebars,depth0,helpers,partials ...@@ -1802,7 +1803,7 @@ templates['status_code'] = template(function (Handlebars,depth0,helpers,partials
}; };
OperationView.prototype.submitOperation = function(e) { 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) { if (e != null) {
e.preventDefault(); e.preventDefault();
} }
...@@ -1833,6 +1834,13 @@ templates['status_code'] = template(function (Handlebars,depth0,helpers,partials ...@@ -1833,6 +1834,13 @@ templates['status_code'] = template(function (Handlebars,depth0,helpers,partials
map[o.name] = encodeURI(o.value); 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.responseContentType = $("div select[name=responseContentType]", $(this.el)).val();
opts.requestContentType = $("div select[name=parameterContentType]", $(this.el)).val(); opts.requestContentType = $("div select[name=parameterContentType]", $(this.el)).val();
return this.model["do"](map, opts, this.showCompleteStatus, this.showErrorStatus, this); return this.model["do"](map, opts, this.showCompleteStatus, this.showErrorStatus, this);
...@@ -2020,11 +2028,12 @@ templates['status_code'] = template(function (Handlebars,depth0,helpers,partials ...@@ -2020,11 +2028,12 @@ templates['status_code'] = template(function (Handlebars,depth0,helpers,partials
ParameterView.prototype.initialize = function() {}; ParameterView.prototype.initialize = function() {};
ParameterView.prototype.render = 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') { if (this.model.paramType === 'body') {
this.model.isBody = true; this.model.isBody = true;
} }
if (this.model.dataType.toLowerCase() === 'file') { if (type.toLowerCase() === 'file') {
this.model.isFile = true; this.model.isFile = true;
} }
template = this.template(); template = this.template();
......
This diff is collapsed.
...@@ -49,7 +49,6 @@ ...@@ -49,7 +49,6 @@
var e, obj, var e, obj,
_this = this; _this = this;
this.progress('fetching resource list: ' + this.url); this.progress('fetching resource list: ' + this.url);
console.log('getting ' + this.url);
obj = { obj = {
url: this.url, url: this.url,
method: "get", method: "get",
...@@ -387,13 +386,14 @@ ...@@ -387,13 +386,14 @@
} }
SwaggerModel.prototype.setReferencedModels = function(allModels) { SwaggerModel.prototype.setReferencedModels = function(allModels) {
var prop, _i, _len, _ref, _results; var prop, type, _i, _len, _ref, _results;
_ref = this.properties; _ref = this.properties;
_results = []; _results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
prop = _ref[_i]; prop = _ref[_i];
if (allModels[prop.dataType] != null) { type = prop.type || prop.dataType;
_results.push(prop.refModel = allModels[prop.dataType]); if (allModels[type] != null) {
_results.push(prop.refModel = allModels[type]);
} else if ((prop.refDataType != null) && (allModels[prop.refDataType] != null)) { } else if ((prop.refDataType != null) && (allModels[prop.refDataType] != null)) {
_results.push(prop.refModel = allModels[prop.refDataType]); _results.push(prop.refModel = allModels[prop.refDataType]);
} else { } else {
...@@ -516,7 +516,7 @@ ...@@ -516,7 +516,7 @@
SwaggerOperation = (function() { SwaggerOperation = (function() {
function SwaggerOperation(nickname, path, method, parameters, summary, notes, responseClass, responseMessages, resource, consumes, produces) { 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 = this;
this.nickname = nickname; this.nickname = nickname;
this.path = path; this.path = path;
...@@ -555,13 +555,14 @@ ...@@ -555,13 +555,14 @@
_ref1 = this.parameters; _ref1 = this.parameters;
for (_i = 0, _len = _ref1.length; _i < _len; _i++) { for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
parameter = _ref1[_i]; parameter = _ref1[_i];
parameter.name = parameter.name || parameter.dataType; parameter.name = parameter.name || parameter.type || parameter.dataType;
if (parameter.dataType.toLowerCase() === 'boolean') { type = parameter.type || parameter.dataType;
if (type.toLowerCase() === 'boolean') {
parameter.allowableValues = {}; parameter.allowableValues = {};
parameter.allowableValues.values = this.resource.api.booleanValues; parameter.allowableValues.values = this.resource.api.booleanValues;
} }
parameter.signature = this.getSignature(parameter.dataType, this.resource.models); parameter.signature = this.getSignature(type, this.resource.models);
parameter.sampleJSON = this.getSampleJSON(parameter.dataType, this.resource.models); parameter.sampleJSON = this.getSampleJSON(type, this.resource.models);
if (parameter.allowableValues != null) { if (parameter.allowableValues != null) {
if (parameter.allowableValues.valueType === "RANGE") { if (parameter.allowableValues.valueType === "RANGE") {
parameter.isRange = true; parameter.isRange = true;
...@@ -596,34 +597,34 @@ ...@@ -596,34 +597,34 @@
}; };
} }
SwaggerOperation.prototype.isListType = function(dataType) { SwaggerOperation.prototype.isListType = function(type) {
if (dataType.indexOf('[') >= 0) { if (type.indexOf('[') >= 0) {
return dataType.substring(dataType.indexOf('[') + 1, dataType.indexOf(']')); return type.substring(type.indexOf('[') + 1, type.indexOf(']'));
} else { } else {
return void 0; return void 0;
} }
}; };
SwaggerOperation.prototype.getSignature = function(dataType, models) { SwaggerOperation.prototype.getSignature = function(type, models) {
var isPrimitive, listType; var isPrimitive, listType;
listType = this.isListType(dataType); listType = this.isListType(type);
isPrimitive = ((listType != null) && models[listType]) || (models[dataType] != null) ? false : true; isPrimitive = ((listType != null) && models[listType]) || (models[type] != null) ? false : true;
if (isPrimitive) { if (isPrimitive) {
return dataType; return type;
} else { } else {
if (listType != null) { if (listType != null) {
return models[listType].getMockSignature(); return models[listType].getMockSignature();
} else { } 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; var isPrimitive, listType, val;
listType = this.isListType(dataType); listType = this.isListType(type);
isPrimitive = ((listType != null) && models[listType]) || (models[dataType] != null) ? false : true; isPrimitive = ((listType != null) && models[listType]) || (models[type] != null) ? false : true;
val = isPrimitive ? void 0 : (listType != null ? models[listType].createJSONSample() : models[dataType].createJSONSample()); val = isPrimitive ? void 0 : (listType != null ? models[listType].createJSONSample() : models[type].createJSONSample());
if (val) { if (val) {
val = listType ? [val] : val; val = listType ? [val] : val;
return JSON.stringify(val, null, 2); return JSON.stringify(val, null, 2);
...@@ -849,13 +850,14 @@ ...@@ -849,13 +850,14 @@
} }
return _results; return _results;
}).call(this)).length > 0) { }).call(this)).length > 0) {
type = param.type || param.dataType;
if (((function() { if (((function() {
var _i, _len, _ref, _results; var _i, _len, _ref, _results;
_ref = this.operation.parameters; _ref = this.operation.parameters;
_results = []; _results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
param = _ref[_i]; param = _ref[_i];
if (param.dataType.toLowerCase() === "file") { if (type.toLowerCase() === "file") {
_results.push(param); _results.push(param);
} }
} }
...@@ -878,14 +880,14 @@ ...@@ -878,14 +880,14 @@
} }
} }
responseContentType = null; 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) { if (this.opts.responseContentType) {
responseContentType = this.opts.responseContentType; requestContentType = this.opts.requestContentType;
} else { } else {
responseContentType = "application/json"; requestContentType = "application/json";
} }
} else { } else {
responseContentType = null; requestContentType = null;
} }
if (responseContentType && this.operation.produces) { if (responseContentType && this.operation.produces) {
if (this.operation.produces.indexOf(responseContentType) === -1) { if (this.operation.produces.indexOf(responseContentType) === -1) {
......
...@@ -32,7 +32,8 @@ class OperationView extends Backbone.View ...@@ -32,7 +32,8 @@ class OperationView extends Backbone.View
contentTypeModel.produces = @model.produces contentTypeModel.produces = @model.produces
for param in @model.parameters for param in @model.parameters
if param.dataType.toLowerCase() == 'file' type = param.type || param.dataType
if type.toLowerCase() == 'file'
if !contentTypeModel.consumes if !contentTypeModel.consumes
console.log "set content type " console.log "set content type "
contentTypeModel.consumes = 'multipart/form-data' contentTypeModel.consumes = 'multipart/form-data'
...@@ -84,6 +85,10 @@ class OperationView extends Backbone.View ...@@ -84,6 +85,10 @@ class OperationView extends Backbone.View
if(o.value? && jQuery.trim(o.value).length > 0) if(o.value? && jQuery.trim(o.value).length > 0)
map[o.name] = encodeURI(o.value) 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.responseContentType = $("div select[name=responseContentType]", $(@el)).val()
opts.requestContentType = $("div select[name=parameterContentType]", $(@el)).val() opts.requestContentType = $("div select[name=parameterContentType]", $(@el)).val()
......
...@@ -2,8 +2,9 @@ class ParameterView extends Backbone.View ...@@ -2,8 +2,9 @@ class ParameterView extends Backbone.View
initialize: -> initialize: ->
render: -> render: ->
type = @model.type || @model.dataType
@model.isBody = true if @model.paramType == 'body' @model.isBody = true if @model.paramType == 'body'
@model.isFile = true if @model.dataType.toLowerCase() == 'file' @model.isFile = true if type.toLowerCase() == 'file'
template = @template() template = @template()
$(@el).html(template(@model)) $(@el).html(template(@model))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment