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/MainView'
'view/ResourceView' 'view/ResourceView'
'view/OperationView' 'view/OperationView'
'view/StatusCodeView'
'view/ParameterView' 'view/ParameterView'
] ]

View File

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

@@ -16,6 +16,10 @@ class OperationView extends Backbone.View
# Render each parameter # Render each parameter
@addParameter param for param in @model.parameters @addParameter param for param in @model.parameters
# Render each response code
@addStatusCode statusCode for statusCode in @model.errorResponses
@ @
addParameter: (param) -> addParameter: (param) ->
@@ -23,6 +27,10 @@ class OperationView extends Backbone.View
paramView = new ParameterView({model: param, tagName: 'tr', readOnly: @model.isReadOnly}) paramView = new ParameterView({model: param, tagName: 'tr', readOnly: @model.isReadOnly})
$('.operation-params', $(@el)).append paramView.render().el $('.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) -> submitOperation: (e) ->
e?.preventDefault() 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> </tbody>
</table> </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}} {{#if isReadOnly}}
{{else}} {{else}}
<div class='sandbox_header'> <div class='sandbox_header'>

View File

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