fixed enum, required flags

This commit is contained in:
Tony Tam
2013-08-14 16:49:08 -07:00
parent f29d53d5bc
commit 888db09fd8
7 changed files with 211 additions and 144 deletions

38
dist/lib/swagger.js vendored
View File

@@ -385,10 +385,17 @@
SwaggerModel = (function() { SwaggerModel = (function() {
function SwaggerModel(modelName, obj) { function SwaggerModel(modelName, obj) {
var propertyName; var propertyName, value;
this.name = obj.id != null ? obj.id : modelName; this.name = obj.id != null ? obj.id : modelName;
this.properties = []; this.properties = [];
for (propertyName in obj.properties) { for (propertyName in obj.properties) {
if (obj["enum"] != null) {
for (value in obj["enum"]) {
if (propertyName === value) {
obj.properties[propertyName].required = true;
}
}
}
this.properties.push(new SwaggerModelProperty(propertyName, obj.properties[propertyName])); this.properties.push(new SwaggerModelProperty(propertyName, obj.properties[propertyName]));
} }
} }
@@ -464,6 +471,7 @@
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;
console.log(this);
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;
@@ -524,7 +532,7 @@
SwaggerOperation = (function() { SwaggerOperation = (function() {
function SwaggerOperation(nickname, path, method, parameters, summary, notes, type, responseMessages, resource, consumes, produces) { function SwaggerOperation(nickname, path, method, parameters, summary, notes, type, responseMessages, resource, consumes, produces) {
var parameter, v, _i, _j, _len, _len1, _ref, _ref1, _ref2, var parameter, v, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2, _ref3,
_this = this; _this = this;
this.nickname = nickname; this.nickname = nickname;
this.path = path; this.path = path;
@@ -572,6 +580,26 @@
} }
parameter.signature = this.getSignature(type, this.resource.models); parameter.signature = this.getSignature(type, this.resource.models);
parameter.sampleJSON = this.getSampleJSON(type, this.resource.models); parameter.sampleJSON = this.getSampleJSON(type, this.resource.models);
if (parameter["enum"] != null) {
parameter.isList = true;
parameter.allowableValues = {};
parameter.allowableValues.descriptiveValues = [];
_ref2 = parameter["enum"];
for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) {
v = _ref2[_j];
if ((parameter.defaultValue != null) && parameter.defaultValue === v) {
parameter.allowableValues.descriptiveValues.push({
value: v,
isDefault: true
});
} else {
parameter.allowableValues.descriptiveValues.push({
value: v,
isDefault: false
});
}
}
}
if (parameter.allowableValues != null) { if (parameter.allowableValues != null) {
if (parameter.allowableValues.valueType === "RANGE") { if (parameter.allowableValues.valueType === "RANGE") {
parameter.isRange = true; parameter.isRange = true;
@@ -580,9 +608,9 @@
} }
if (parameter.allowableValues.values != null) { if (parameter.allowableValues.values != null) {
parameter.allowableValues.descriptiveValues = []; parameter.allowableValues.descriptiveValues = [];
_ref2 = parameter.allowableValues.values; _ref3 = parameter.allowableValues.values;
for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) { for (_k = 0, _len2 = _ref3.length; _k < _len2; _k++) {
v = _ref2[_j]; v = _ref3[_k];
if ((parameter.defaultValue != null) && parameter.defaultValue === v) { if ((parameter.defaultValue != null) && parameter.defaultValue === v) {
parameter.allowableValues.descriptiveValues.push({ parameter.allowableValues.descriptiveValues.push({
value: v, value: v,

75
dist/swagger-ui.js vendored
View File

@@ -317,45 +317,45 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
function program1(depth0,data) { function program1(depth0,data) {
var buffer = "", stack1; var buffer = "", stack1;
buffer += "\n <h4>Implementation Notes</h4>\n <p>"; buffer += "\n <h4>Implementation Notes</h4>\n <p>";
if (stack1 = helpers.notes) { stack1 = stack1.call(depth0, {hash:{},data:data}); } if (stack1 = helpers.notes) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
else { stack1 = depth0.notes; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; } else { stack1 = depth0.notes; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
if(stack1 || stack1 === 0) { buffer += stack1; } if(stack1 || stack1 === 0) { buffer += stack1; }
buffer += "</p>\n "; buffer += "</p>\n ";
return buffer; return buffer;
} }
function program3(depth0,data) { function program3(depth0,data) {
return "\n <h4>Response Class</h4>\n <p><span class=\"model-signature\" /></p>\n <br/>\n <div class=\"response-content-type\" />\n "; return "\n <h4>Response Class</h4>\n <p><span class=\"model-signature\" /></p>\n <br/>\n <div class=\"response-content-type\" />\n ";
} }
function program5(depth0,data) { function program5(depth0,data) {
return "\n <h4>Parameters</h4>\n <table class='fullwidth'>\n <thead>\n <tr>\n <th style=\"width: 100px; max-width: 100px\">Parameter</th>\n <th style=\"width: 310px; max-width: 310px\">Value</th>\n <th style=\"width: 200px; max-width: 200px\">Description</th>\n <th style=\"width: 100px; max-width: 100px\">Parameter Type</th>\n <th style=\"width: 220px; max-width: 230px\">Data Type</th>\n </tr>\n </thead>\n <tbody class=\"operation-params\">\n\n </tbody>\n </table>\n "; return "\n <h4>Parameters</h4>\n <table class='fullwidth'>\n <thead>\n <tr>\n <th style=\"width: 100px; max-width: 100px\">Parameter</th>\n <th style=\"width: 310px; max-width: 310px\">Value</th>\n <th style=\"width: 200px; max-width: 200px\">Description</th>\n <th style=\"width: 100px; max-width: 100px\">Parameter Type</th>\n <th style=\"width: 220px; max-width: 230px\">Data Type</th>\n </tr>\n </thead>\n <tbody class=\"operation-params\">\n\n </tbody>\n </table>\n ";
} }
function program7(depth0,data) { function program7(depth0,data) {
return "\n <div style='margin:0;padding:0;display:inline'></div>\n <h4>Error Status Codes</h4>\n <table class='fullwidth'>\n <thead>\n <tr>\n <th>HTTP Status Code</th>\n <th>Reason</th>\n </tr>\n </thead>\n <tbody class=\"operation-status\">\n \n </tbody>\n </table>\n "; return "\n <div style='margin:0;padding:0;display:inline'></div>\n <h4>Error Status Codes</h4>\n <table class='fullwidth'>\n <thead>\n <tr>\n <th>HTTP Status Code</th>\n <th>Reason</th>\n </tr>\n </thead>\n <tbody class=\"operation-status\">\n \n </tbody>\n </table>\n ";
} }
function program9(depth0,data) { function program9(depth0,data) {
return "\n "; return "\n ";
} }
function program11(depth0,data) { function program11(depth0,data) {
return "\n <div class='sandbox_header'>\n <input class='submit' name='commit' type='button' value='Try it out!' />\n <a href='#' class='response_hider' style='display:none'>Hide Response</a>\n <img alt='Throbber' class='response_throbber' src='images/throbber.gif' style='display:none' />\n </div>\n "; return "\n <div class='sandbox_header'>\n <input class='submit' name='commit' type='button' value='Try it out!' />\n <a href='#' class='response_hider' style='display:none'>Hide Response</a>\n <img alt='Throbber' class='response_throbber' src='images/throbber.gif' style='display:none' />\n </div>\n ";
} }
buffer += "\n <ul class='operations' >\n <li class='"; buffer += "\n <ul class='operations' >\n <li class='";
if (stack1 = helpers.method) { stack1 = stack1.call(depth0, {hash:{},data:data}); } if (stack1 = helpers.method) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
else { stack1 = depth0.method; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; } else { stack1 = depth0.method; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
buffer += escapeExpression(stack1) buffer += escapeExpression(stack1)
@@ -375,7 +375,7 @@ function program11(depth0,data) {
if (stack1 = helpers.number) { stack1 = stack1.call(depth0, {hash:{},data:data}); } if (stack1 = helpers.number) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
else { stack1 = depth0.number; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; } else { stack1 = depth0.number; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
buffer += escapeExpression(stack1) buffer += escapeExpression(stack1)
+ "'>\n <div class='heading'>\n <h3>\n <span class='http_method'>\n <a href='#!/"; + "'>\n <div class='heading'>\n <h3>\n <span class='http_method'>\n <a href='#!/";
if (stack1 = helpers.resourceName) { stack1 = stack1.call(depth0, {hash:{},data:data}); } if (stack1 = helpers.resourceName) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
else { stack1 = depth0.resourceName; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; } else { stack1 = depth0.resourceName; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
buffer += escapeExpression(stack1) buffer += escapeExpression(stack1)
@@ -395,7 +395,7 @@ function program11(depth0,data) {
if (stack1 = helpers.method) { stack1 = stack1.call(depth0, {hash:{},data:data}); } if (stack1 = helpers.method) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
else { stack1 = depth0.method; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; } else { stack1 = depth0.method; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
buffer += escapeExpression(stack1) buffer += escapeExpression(stack1)
+ "</a>\n </span>\n <span class='path'>\n <a href='#!/"; + "</a>\n </span>\n <span class='path'>\n <a href='#!/";
if (stack1 = helpers.resourceName) { stack1 = stack1.call(depth0, {hash:{},data:data}); } if (stack1 = helpers.resourceName) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
else { stack1 = depth0.resourceName; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; } else { stack1 = depth0.resourceName; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
buffer += escapeExpression(stack1) buffer += escapeExpression(stack1)
@@ -415,7 +415,7 @@ function program11(depth0,data) {
if (stack1 = helpers.path) { stack1 = stack1.call(depth0, {hash:{},data:data}); } if (stack1 = helpers.path) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
else { stack1 = depth0.path; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; } else { stack1 = depth0.path; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
buffer += escapeExpression(stack1) buffer += escapeExpression(stack1)
+ "</a>\n </span>\n </h3>\n <ul class='options'>\n <li>\n <a href='#!/"; + "</a>\n </span>\n </h3>\n <ul class='options'>\n <li>\n <a href='#!/";
if (stack1 = helpers.resourceName) { stack1 = stack1.call(depth0, {hash:{},data:data}); } if (stack1 = helpers.resourceName) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
else { stack1 = depth0.resourceName; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; } else { stack1 = depth0.resourceName; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
buffer += escapeExpression(stack1) buffer += escapeExpression(stack1)
@@ -435,7 +435,7 @@ function program11(depth0,data) {
if (stack1 = helpers.summary) { stack1 = stack1.call(depth0, {hash:{},data:data}); } if (stack1 = helpers.summary) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
else { stack1 = depth0.summary; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; } else { stack1 = depth0.summary; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
if(stack1 || stack1 === 0) { buffer += stack1; } if(stack1 || stack1 === 0) { buffer += stack1; }
buffer += "</a>\n </li>\n </ul>\n </div>\n <div class='content' id='"; buffer += "</a>\n </li>\n </ul>\n </div>\n <div class='content' id='";
if (stack1 = helpers.resourceName) { stack1 = stack1.call(depth0, {hash:{},data:data}); } if (stack1 = helpers.resourceName) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
else { stack1 = depth0.resourceName; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; } else { stack1 = depth0.resourceName; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
buffer += escapeExpression(stack1) buffer += escapeExpression(stack1)
@@ -451,22 +451,22 @@ function program11(depth0,data) {
if (stack1 = helpers.number) { stack1 = stack1.call(depth0, {hash:{},data:data}); } if (stack1 = helpers.number) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
else { stack1 = depth0.number; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; } else { stack1 = depth0.number; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
buffer += escapeExpression(stack1) buffer += escapeExpression(stack1)
+ "_content' style='display:none'>\n "; + "_content' style='display:none'>\n ";
stack1 = helpers['if'].call(depth0, depth0.notes, {hash:{},inverse:self.noop,fn:self.program(1, program1, data),data:data}); stack1 = helpers['if'].call(depth0, depth0.notes, {hash:{},inverse:self.noop,fn:self.program(1, program1, data),data:data});
if(stack1 || stack1 === 0) { buffer += stack1; } if(stack1 || stack1 === 0) { buffer += stack1; }
buffer += "\n "; buffer += "\n ";
stack1 = helpers['if'].call(depth0, depth0.type, {hash:{},inverse:self.noop,fn:self.program(3, program3, data),data:data}); stack1 = helpers['if'].call(depth0, depth0.type, {hash:{},inverse:self.noop,fn:self.program(3, program3, data),data:data});
if(stack1 || stack1 === 0) { buffer += stack1; } if(stack1 || stack1 === 0) { buffer += stack1; }
buffer += "\n <form accept-charset='UTF-8' class='sandbox'>\n <div style='margin:0;padding:0;display:inline'></div>\n "; buffer += "\n <form accept-charset='UTF-8' class='sandbox'>\n <div style='margin:0;padding:0;display:inline'></div>\n ";
stack1 = helpers['if'].call(depth0, depth0.parameters, {hash:{},inverse:self.noop,fn:self.program(5, program5, data),data:data}); stack1 = helpers['if'].call(depth0, depth0.parameters, {hash:{},inverse:self.noop,fn:self.program(5, program5, data),data:data});
if(stack1 || stack1 === 0) { buffer += stack1; } if(stack1 || stack1 === 0) { buffer += stack1; }
buffer += "\n "; buffer += "\n ";
stack1 = helpers['if'].call(depth0, depth0.errorResponses, {hash:{},inverse:self.noop,fn:self.program(7, program7, data),data:data}); stack1 = helpers['if'].call(depth0, depth0.errorResponses, {hash:{},inverse:self.noop,fn:self.program(7, program7, data),data:data});
if(stack1 || stack1 === 0) { buffer += stack1; } if(stack1 || stack1 === 0) { buffer += stack1; }
buffer += "\n "; buffer += "\n ";
stack1 = helpers['if'].call(depth0, depth0.isReadOnly, {hash:{},inverse:self.program(11, program11, data),fn:self.program(9, program9, data),data:data}); stack1 = helpers['if'].call(depth0, depth0.isReadOnly, {hash:{},inverse:self.program(11, program11, data),fn:self.program(9, program9, data),data:data});
if(stack1 || stack1 === 0) { buffer += stack1; } if(stack1 || stack1 === 0) { buffer += stack1; }
buffer += "\n </form>\n <div class='response' style='display:none'>\n <h4>Request URL</h4>\n <div class='block request_url'></div>\n <h4>Response Body</h4>\n <div class='block response_body'></div>\n <h4>Response Code</h4>\n <div class='block response_code'></div>\n <h4>Response Headers</h4>\n <div class='block response_headers'></div>\n </div>\n </div>\n </li>\n </ul>\n"; buffer += "\n </form>\n <div class='response' style='display:none'>\n <h4>Request URL</h4>\n <div class='block request_url'></div>\n <h4>Response Body</h4>\n <div class='block response_body'></div>\n <h4>Response Code</h4>\n <div class='block response_code'></div>\n <h4>Response Headers</h4>\n <div class='block response_headers'></div>\n </div>\n </div>\n </li>\n </ul>\n";
return buffer; return buffer;
}); });
})(); })();
@@ -598,43 +598,43 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
function program1(depth0,data) { function program1(depth0,data) {
return "\n "; return "\n ";
} }
function program3(depth0,data) { function program3(depth0,data) {
var buffer = "", stack1; var buffer = "", stack1;
buffer += "\n "; buffer += "\n ";
stack1 = helpers['if'].call(depth0, depth0.defaultValue, {hash:{},inverse:self.program(6, program6, data),fn:self.program(4, program4, data),data:data}); stack1 = helpers['if'].call(depth0, depth0.defaultValue, {hash:{},inverse:self.program(6, program6, data),fn:self.program(4, program4, data),data:data});
if(stack1 || stack1 === 0) { buffer += stack1; } if(stack1 || stack1 === 0) { buffer += stack1; }
buffer += "\n "; buffer += "\n ";
return buffer; return buffer;
} }
function program4(depth0,data) { function program4(depth0,data) {
return "\n "; return "\n ";
} }
function program6(depth0,data) { function program6(depth0,data) {
return "\n <option selected=\"\" value=''></option>\n "; return "\n <option selected=\"\" value=''></option>\n ";
} }
function program8(depth0,data) { function program8(depth0,data) {
var buffer = "", stack1; var buffer = "", stack1;
buffer += "\n "; buffer += "\n ";
stack1 = helpers['if'].call(depth0, depth0.isDefault, {hash:{},inverse:self.program(11, program11, data),fn:self.program(9, program9, data),data:data}); stack1 = helpers['if'].call(depth0, depth0.isDefault, {hash:{},inverse:self.program(11, program11, data),fn:self.program(9, program9, data),data:data});
if(stack1 || stack1 === 0) { buffer += stack1; } if(stack1 || stack1 === 0) { buffer += stack1; }
buffer += "\n "; buffer += "\n ";
return buffer; return buffer;
} }
function program9(depth0,data) { function program9(depth0,data) {
var buffer = "", stack1; var buffer = "", stack1;
buffer += "\n <option value='"; buffer += "\n <option value='";
if (stack1 = helpers.value) { stack1 = stack1.call(depth0, {hash:{},data:data}); } if (stack1 = helpers.value) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
else { stack1 = depth0.value; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; } else { stack1 = depth0.value; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
buffer += escapeExpression(stack1) buffer += escapeExpression(stack1)
@@ -642,14 +642,14 @@ function program9(depth0,data) {
if (stack1 = helpers.value) { stack1 = stack1.call(depth0, {hash:{},data:data}); } if (stack1 = helpers.value) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
else { stack1 = depth0.value; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; } else { stack1 = depth0.value; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
buffer += escapeExpression(stack1) buffer += escapeExpression(stack1)
+ " (default)</option>\n "; + " (default)</option>\n ";
return buffer; return buffer;
} }
function program11(depth0,data) { function program11(depth0,data) {
var buffer = "", stack1; var buffer = "", stack1;
buffer += "\n <option value='"; buffer += "\n <option value='";
if (stack1 = helpers.value) { stack1 = stack1.call(depth0, {hash:{},data:data}); } if (stack1 = helpers.value) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
else { stack1 = depth0.value; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; } else { stack1 = depth0.value; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
buffer += escapeExpression(stack1) buffer += escapeExpression(stack1)
@@ -657,7 +657,7 @@ function program11(depth0,data) {
if (stack1 = helpers.value) { stack1 = stack1.call(depth0, {hash:{},data:data}); } if (stack1 = helpers.value) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
else { stack1 = depth0.value; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; } else { stack1 = depth0.value; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
buffer += escapeExpression(stack1) buffer += escapeExpression(stack1)
+ "</option>\n "; + "</option>\n ";
return buffer; return buffer;
} }
@@ -665,17 +665,17 @@ function program11(depth0,data) {
if (stack1 = helpers.name) { stack1 = stack1.call(depth0, {hash:{},data:data}); } if (stack1 = helpers.name) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
else { stack1 = depth0.name; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; } else { stack1 = depth0.name; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
buffer += escapeExpression(stack1) buffer += escapeExpression(stack1)
+ "</td>\n<td>\n <select class='parameter' name='"; + "</td>\n<td>\n <select class='parameter' name='";
if (stack1 = helpers.name) { stack1 = stack1.call(depth0, {hash:{},data:data}); } if (stack1 = helpers.name) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
else { stack1 = depth0.name; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; } else { stack1 = depth0.name; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
buffer += escapeExpression(stack1) buffer += escapeExpression(stack1)
+ "'>\n "; + "'>\n ";
stack1 = helpers['if'].call(depth0, depth0.required, {hash:{},inverse:self.program(3, program3, data),fn:self.program(1, program1, data),data:data}); stack1 = helpers['if'].call(depth0, depth0.required, {hash:{},inverse:self.program(3, program3, data),fn:self.program(1, program1, data),data:data});
if(stack1 || stack1 === 0) { buffer += stack1; } if(stack1 || stack1 === 0) { buffer += stack1; }
buffer += "\n "; buffer += "\n ";
stack2 = helpers.each.call(depth0, ((stack1 = depth0.allowableValues),stack1 == null || stack1 === false ? stack1 : stack1.descriptiveValues), {hash:{},inverse:self.noop,fn:self.program(8, program8, data),data:data}); stack2 = helpers.each.call(depth0, ((stack1 = depth0.allowableValues),stack1 == null || stack1 === false ? stack1 : stack1.descriptiveValues), {hash:{},inverse:self.noop,fn:self.program(8, program8, data),data:data});
if(stack2 || stack2 === 0) { buffer += stack2; } if(stack2 || stack2 === 0) { buffer += stack2; }
buffer += "\n </select>\n</td>\n<td>"; buffer += "\n </select>\n</td>\n<td>";
if (stack2 = helpers.description) { stack2 = stack2.call(depth0, {hash:{},data:data}); } if (stack2 = helpers.description) { stack2 = stack2.call(depth0, {hash:{},data:data}); }
else { stack2 = depth0.description; stack2 = typeof stack2 === functionType ? stack2.apply(depth0) : stack2; } else { stack2 = depth0.description; stack2 = typeof stack2 === functionType ? stack2.apply(depth0) : stack2; }
if(stack2 || stack2 === 0) { buffer += stack2; } if(stack2 || stack2 === 0) { buffer += stack2; }
@@ -1515,7 +1515,7 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
}; };
OperationView.prototype.submitOperation = function(e) { OperationView.prototype.submitOperation = function(e) {
var error_free, form, map, o, opts, _i, _j, _len, _len1, _ref, _ref1; var error_free, form, map, o, opts, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2;
if (e != null) { if (e != null) {
e.preventDefault(); e.preventDefault();
} }
@@ -1553,6 +1553,13 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
map["body"] = o.value; map["body"] = o.value;
} }
} }
_ref2 = form.find("select");
for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
o = _ref2[_k];
if ((o.value != null) && jQuery.trim(o.value).length > 0) {
map[o.name] = 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);

File diff suppressed because one or more lines are too long

View File

@@ -385,10 +385,17 @@
SwaggerModel = (function() { SwaggerModel = (function() {
function SwaggerModel(modelName, obj) { function SwaggerModel(modelName, obj) {
var propertyName; var propertyName, value;
this.name = obj.id != null ? obj.id : modelName; this.name = obj.id != null ? obj.id : modelName;
this.properties = []; this.properties = [];
for (propertyName in obj.properties) { for (propertyName in obj.properties) {
if (obj["enum"] != null) {
for (value in obj["enum"]) {
if (propertyName === value) {
obj.properties[propertyName].required = true;
}
}
}
this.properties.push(new SwaggerModelProperty(propertyName, obj.properties[propertyName])); this.properties.push(new SwaggerModelProperty(propertyName, obj.properties[propertyName]));
} }
} }
@@ -464,6 +471,7 @@
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;
console.log(this);
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;
@@ -524,7 +532,7 @@
SwaggerOperation = (function() { SwaggerOperation = (function() {
function SwaggerOperation(nickname, path, method, parameters, summary, notes, type, responseMessages, resource, consumes, produces) { function SwaggerOperation(nickname, path, method, parameters, summary, notes, type, responseMessages, resource, consumes, produces) {
var parameter, v, _i, _j, _len, _len1, _ref, _ref1, _ref2, var parameter, v, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2, _ref3,
_this = this; _this = this;
this.nickname = nickname; this.nickname = nickname;
this.path = path; this.path = path;
@@ -572,6 +580,26 @@
} }
parameter.signature = this.getSignature(type, this.resource.models); parameter.signature = this.getSignature(type, this.resource.models);
parameter.sampleJSON = this.getSampleJSON(type, this.resource.models); parameter.sampleJSON = this.getSampleJSON(type, this.resource.models);
if (parameter["enum"] != null) {
parameter.isList = true;
parameter.allowableValues = {};
parameter.allowableValues.descriptiveValues = [];
_ref2 = parameter["enum"];
for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) {
v = _ref2[_j];
if ((parameter.defaultValue != null) && parameter.defaultValue === v) {
parameter.allowableValues.descriptiveValues.push({
value: v,
isDefault: true
});
} else {
parameter.allowableValues.descriptiveValues.push({
value: v,
isDefault: false
});
}
}
}
if (parameter.allowableValues != null) { if (parameter.allowableValues != null) {
if (parameter.allowableValues.valueType === "RANGE") { if (parameter.allowableValues.valueType === "RANGE") {
parameter.isRange = true; parameter.isRange = true;
@@ -580,9 +608,9 @@
} }
if (parameter.allowableValues.values != null) { if (parameter.allowableValues.values != null) {
parameter.allowableValues.descriptiveValues = []; parameter.allowableValues.descriptiveValues = [];
_ref2 = parameter.allowableValues.values; _ref3 = parameter.allowableValues.values;
for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) { for (_k = 0, _len2 = _ref3.length; _k < _len2; _k++) {
v = _ref2[_j]; v = _ref3[_k];
if ((parameter.defaultValue != null) && parameter.defaultValue === v) { if ((parameter.defaultValue != null) && parameter.defaultValue === v) {
parameter.allowableValues.descriptiveValues.push({ parameter.allowableValues.descriptiveValues.push({
value: v, value: v,

View File

@@ -89,6 +89,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["body"] = o.value map["body"] = o.value
for o in form.find("select")
if(o.value? && jQuery.trim(o.value).length > 0)
map[o.name] = 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()

View File

@@ -1,85 +1,85 @@
<ul class='operations' > <ul class='operations' >
<li class='{{method}} operation' id='{{resourceName}}_{{nickname}}_{{method}}_{{number}}'> <li class='{{method}} operation' id='{{resourceName}}_{{nickname}}_{{method}}_{{number}}'>
<div class='heading'> <div class='heading'>
<h3> <h3>
<span class='http_method'> <span class='http_method'>
<a href='#!/{{resourceName}}/{{nickname}}_{{method}}_{{number}}' class="toggleOperation">{{method}}</a> <a href='#!/{{resourceName}}/{{nickname}}_{{method}}_{{number}}' class="toggleOperation">{{method}}</a>
</span> </span>
<span class='path'> <span class='path'>
<a href='#!/{{resourceName}}/{{nickname}}_{{method}}_{{number}}' class="toggleOperation">{{path}}</a> <a href='#!/{{resourceName}}/{{nickname}}_{{method}}_{{number}}' class="toggleOperation">{{path}}</a>
</span> </span>
</h3> </h3>
<ul class='options'> <ul class='options'>
<li> <li>
<a href='#!/{{resourceName}}/{{nickname}}_{{method}}_{{number}}' class="toggleOperation">{{{summary}}}</a> <a href='#!/{{resourceName}}/{{nickname}}_{{method}}_{{number}}' class="toggleOperation">{{{summary}}}</a>
</li> </li>
</ul> </ul>
</div> </div>
<div class='content' id='{{resourceName}}_{{nickname}}_{{method}}_{{number}}_content' style='display:none'> <div class='content' id='{{resourceName}}_{{nickname}}_{{method}}_{{number}}_content' style='display:none'>
{{#if notes}} {{#if notes}}
<h4>Implementation Notes</h4> <h4>Implementation Notes</h4>
<p>{{{notes}}}</p> <p>{{{notes}}}</p>
{{/if}} {{/if}}
{{#if type}} {{#if type}}
<h4>Response Class</h4> <h4>Response Class</h4>
<p><span class="model-signature" /></p> <p><span class="model-signature" /></p>
<br/> <br/>
<div class="response-content-type" /> <div class="response-content-type" />
{{/if}} {{/if}}
<form accept-charset='UTF-8' class='sandbox'> <form accept-charset='UTF-8' class='sandbox'>
<div style='margin:0;padding:0;display:inline'></div> <div style='margin:0;padding:0;display:inline'></div>
{{#if parameters}} {{#if parameters}}
<h4>Parameters</h4> <h4>Parameters</h4>
<table class='fullwidth'> <table class='fullwidth'>
<thead> <thead>
<tr> <tr>
<th style="width: 100px; max-width: 100px">Parameter</th> <th style="width: 100px; max-width: 100px">Parameter</th>
<th style="width: 310px; max-width: 310px">Value</th> <th style="width: 310px; max-width: 310px">Value</th>
<th style="width: 200px; max-width: 200px">Description</th> <th style="width: 200px; max-width: 200px">Description</th>
<th style="width: 100px; max-width: 100px">Parameter Type</th> <th style="width: 100px; max-width: 100px">Parameter Type</th>
<th style="width: 220px; max-width: 230px">Data Type</th> <th style="width: 220px; max-width: 230px">Data Type</th>
</tr> </tr>
</thead> </thead>
<tbody class="operation-params"> <tbody class="operation-params">
</tbody> </tbody>
</table> </table>
{{/if}} {{/if}}
{{#if errorResponses}} {{#if errorResponses}}
<div style='margin:0;padding:0;display:inline'></div> <div style='margin:0;padding:0;display:inline'></div>
<h4>Error Status Codes</h4> <h4>Error Status Codes</h4>
<table class='fullwidth'> <table class='fullwidth'>
<thead> <thead>
<tr> <tr>
<th>HTTP Status Code</th> <th>HTTP Status Code</th>
<th>Reason</th> <th>Reason</th>
</tr> </tr>
</thead> </thead>
<tbody class="operation-status"> <tbody class="operation-status">
</tbody> </tbody>
</table> </table>
{{/if}} {{/if}}
{{#if isReadOnly}} {{#if isReadOnly}}
{{else}} {{else}}
<div class='sandbox_header'> <div class='sandbox_header'>
<input class='submit' name='commit' type='button' value='Try it out!' /> <input class='submit' name='commit' type='button' value='Try it out!' />
<a href='#' class='response_hider' style='display:none'>Hide Response</a> <a href='#' class='response_hider' style='display:none'>Hide Response</a>
<img alt='Throbber' class='response_throbber' src='images/throbber.gif' style='display:none' /> <img alt='Throbber' class='response_throbber' src='images/throbber.gif' style='display:none' />
</div> </div>
{{/if}} {{/if}}
</form> </form>
<div class='response' style='display:none'> <div class='response' style='display:none'>
<h4>Request URL</h4> <h4>Request URL</h4>
<div class='block request_url'></div> <div class='block request_url'></div>
<h4>Response Body</h4> <h4>Response Body</h4>
<div class='block response_body'></div> <div class='block response_body'></div>
<h4>Response Code</h4> <h4>Response Code</h4>
<div class='block response_code'></div> <div class='block response_code'></div>
<h4>Response Headers</h4> <h4>Response Headers</h4>
<div class='block response_headers'></div> <div class='block response_headers'></div>
</div> </div>
</div> </div>
</li> </li>
</ul> </ul>

View File

@@ -1,21 +1,21 @@
<td class='code'>{{name}}</td> <td class='code'>{{name}}</td>
<td> <td>
<select class='parameter' name='{{name}}'> <select class='parameter' name='{{name}}'>
{{#if required}} {{#if required}}
{{else}} {{else}}
{{#if defaultValue}} {{#if defaultValue}}
{{else}} {{else}}
<option selected="" value=''></option> <option selected="" value=''></option>
{{/if}} {{/if}}
{{/if}} {{/if}}
{{#each allowableValues.descriptiveValues}} {{#each allowableValues.descriptiveValues}}
{{#if isDefault}} {{#if isDefault}}
<option value='{{value}}'>{{value}} (default)</option> <option value='{{value}}'>{{value}} (default)</option>
{{else}} {{else}}
<option value='{{value}}'>{{value}}</option> <option value='{{value}}'>{{value}}</option>
{{/if}} {{/if}}
{{/each}} {{/each}}
</select> </select>
</td> </td>
<td>{{{description}}}</td> <td>{{{description}}}</td>
<td>{{{paramType}}}</td> <td>{{{paramType}}}</td>