Merge pull request #80 from pose/master

Added table with response codes to Operation
This commit is contained in:
Ayush Gupta
2012-11-14 06:50:50 -08:00
6 changed files with 50 additions and 10 deletions

View File

@@ -8,6 +8,7 @@ sourceFiles = [
'view/MainView'
'view/ResourceView'
'view/OperationView'
'view/StatusCodeView'
'view/ParameterView'
]

View File

@@ -252,7 +252,7 @@
_results = [];
for (_i = 0, _len = ops.length; _i < _len; _i++) {
o = ops[_i];
op = new SwaggerOperation(o.nickname, resource_path, o.httpMethod, o.parameters, o.summary, o.notes, o.responseClass, this);
op = new SwaggerOperation(o.nickname, resource_path, o.httpMethod, o.parameters, o.summary, o.notes, o.responseClass, o.errorResponses, this);
this.operations[op.nickname] = op;
_results.push(this.operationsArray.push(op));
}
@@ -381,8 +381,8 @@
SwaggerOperation = (function() {
function SwaggerOperation(nickname, path, httpMethod, parameters, summary, notes, responseClass, resource) {
var parameter, v, _i, _j, _len, _len1, _ref, _ref1,
function SwaggerOperation(nickname, path, httpMethod, parameters, summary, notes, responseClass, errorResponses, resource) {
var parameter, v, _i, _j, _len, _len1, _ref, _ref1, _ref2,
_this = this;
this.nickname = nickname;
this.path = path;
@@ -391,6 +391,7 @@
this.summary = summary;
this.notes = notes;
this.responseClass = responseClass;
this.errorResponses = errorResponses;
this.resource = resource;
this["do"] = __bind(this["do"], this);
@@ -407,15 +408,16 @@
this.httpMethod = this.httpMethod.toLowerCase();
this.isGetMethod = this.httpMethod === "get";
this.resourceName = this.resource.name;
if (this.responseClass.toLowerCase() === 'void') {
if (((_ref = this.responseClass) != null ? _ref.toLowerCase() : void 0) === 'void') {
this.responseClass = void 0;
}
if (this.responseClass != null) {
this.responseClassSignature = this.getSignature(this.responseClass, this.resource.models);
}
_ref = this.parameters;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
parameter = _ref[_i];
this.errorResponses = this.errorResponses || [];
_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.allowableValues = {};
@@ -430,9 +432,9 @@
}
if (parameter.allowableValues.values != null) {
parameter.allowableValues.descriptiveValues = [];
_ref1 = parameter.allowableValues.values;
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
v = _ref1[_j];
_ref2 = parameter.allowableValues.values;
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,

View File

@@ -16,6 +16,10 @@ class OperationView extends Backbone.View
# Render each parameter
@addParameter param for param in @model.parameters
# Render each response code
@addStatusCode statusCode for statusCode in @model.errorResponses
@
addParameter: (param) ->
@@ -23,6 +27,10 @@ class OperationView extends Backbone.View
paramView = new ParameterView({model: param, tagName: 'tr', readOnly: @model.isReadOnly})
$('.operation-params', $(@el)).append paramView.render().el
addStatusCode: (statusCode) ->
# Render status codes
statusCodeView = new StatusCodeView({model: statusCode, tagName: 'tr'})
$('.operation-status', $(@el)).append statusCodeView.render().el
submitOperation: (e) ->
e?.preventDefault()

View File

@@ -0,0 +1,11 @@
class StatusCodeView extends Backbone.View
initialize: ->
render: ->
template = @template()
$(@el).html(template(@model))
@
template: ->
Handlebars.templates.status_code

View File

@@ -45,6 +45,21 @@
</tbody>
</table>
{{#if errorResponses}}
<div style='margin:0;padding:0;display:inline'></div>
<h4>Status Codes</h4>
<table class='fullwidth'>
<thead>
<tr>
<th>HTTP Status Code</th>
<th>Reason</th>
</tr>
</thead>
<tbody class="operation-status">
</tbody>
</table>
{{/if}}
{{#if isReadOnly}}
{{else}}
<div class='sandbox_header'>

View File

@@ -0,0 +1,3 @@
<td width='15%' class='code'>{{code}}</td>
<td>{{{reason}}}</td>