Render response headers

Fixes #930
This commit is contained in:
Mohsen Azimi
2015-03-05 10:50:38 -08:00
parent 516b85ee65
commit eeb83a40bd
4 changed files with 42 additions and 8 deletions

27
dist/swagger-ui.js vendored
View File

@@ -543,7 +543,7 @@ this["Handlebars"]["templates"]["operation"] = Handlebars.template({"1":function
},"18":function(depth0,helpers,partials,data) { },"18":function(depth0,helpers,partials,data) {
return " <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 " <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";
},"20":function(depth0,helpers,partials,data) { },"20":function(depth0,helpers,partials,data) {
return " <div style='margin:0;padding:0;display:inline'></div>\n <h4>Response Messages</h4>\n <table class='fullwidth'>\n <thead>\n <tr>\n <th>HTTP Status Code</th>\n <th>Reason</th>\n <th>Response Model</th>\n </tr>\n </thead>\n <tbody class=\"operation-status\">\n \n </tbody>\n </table>\n"; return " <div style='margin:0;padding:0;display:inline'></div>\n <h4>Response Messages</h4>\n <table class='fullwidth'>\n <thead>\n <tr>\n <th>HTTP Status Code</th>\n <th>Reason</th>\n <th>Response Model</th>\n <th>Headers</th>\n </tr>\n </thead>\n <tbody class=\"operation-status\">\n\n </tbody>\n </table>\n";
},"22":function(depth0,helpers,partials,data) { },"22":function(depth0,helpers,partials,data) {
return ""; return "";
},"24":function(depth0,helpers,partials,data) { },"24":function(depth0,helpers,partials,data) {
@@ -960,13 +960,25 @@ this["Handlebars"]["templates"]["signature"] = Handlebars.template({"compiler":[
+ escapeExpression(((helper = (helper = helpers.sampleJSON || (depth0 != null ? depth0.sampleJSON : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"sampleJSON","hash":{},"data":data}) : helper))) + escapeExpression(((helper = (helper = helpers.sampleJSON || (depth0 != null ? depth0.sampleJSON : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"sampleJSON","hash":{},"data":data}) : helper)))
+ "</code></pre>\n <small class=\"notice\"></small>\n </div>\n</div>\n\n"; + "</code></pre>\n <small class=\"notice\"></small>\n </div>\n</div>\n\n";
},"useData":true}); },"useData":true});
this["Handlebars"]["templates"]["status_code"] = Handlebars.template({"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) { this["Handlebars"]["templates"]["status_code"] = Handlebars.template({"1":function(depth0,helpers,partials,data) {
var lambda=this.lambda, escapeExpression=this.escapeExpression;
return " <tr>\n <td>"
+ escapeExpression(lambda((data && data.key), depth0))
+ "</td>\n <td>"
+ escapeExpression(lambda((depth0 != null ? depth0.description : depth0), depth0))
+ "</td>\n <td>"
+ escapeExpression(lambda((depth0 != null ? depth0.type : depth0), depth0))
+ "</td>\n </tr>\n";
},"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) {
var stack1, helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression, buffer = "<td width='15%' class='code'>" var stack1, helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression, buffer = "<td width='15%' class='code'>"
+ escapeExpression(((helper = (helper = helpers.code || (depth0 != null ? depth0.code : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"code","hash":{},"data":data}) : helper))) + escapeExpression(((helper = (helper = helpers.code || (depth0 != null ? depth0.code : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"code","hash":{},"data":data}) : helper)))
+ "</td>\n<td>"; + "</td>\n<td>";
stack1 = ((helper = (helper = helpers.message || (depth0 != null ? depth0.message : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"message","hash":{},"data":data}) : helper)); stack1 = ((helper = (helper = helpers.message || (depth0 != null ? depth0.message : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"message","hash":{},"data":data}) : helper));
if (stack1 != null) { buffer += stack1; } if (stack1 != null) { buffer += stack1; }
return buffer + "</td>\n<td width='50%'><span class=\"model-signature\" /></td>"; buffer += "</td>\n<td width='50%'><span class=\"model-signature\" /></td>\n<td class=\"headers\">\n <table>\n <tbody>\n";
stack1 = helpers.each.call(depth0, (depth0 != null ? depth0.headers : depth0), {"name":"each","hash":{},"fn":this.program(1, data),"inverse":this.noop,"data":data});
if (stack1 != null) { buffer += stack1; }
return buffer + " </tbody>\n </table>\n</td>";
},"useData":true}); },"useData":true});
var ApiKeyButton, var ApiKeyButton,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
@@ -1822,7 +1834,7 @@ OperationView = (function(superClass) {
}; };
OperationView.prototype.showStatus = function(response) { OperationView.prototype.showStatus = function(response) {
var code, content, contentType, e, headers, json, opts, pre, response_body, response_body_el, url; var code, content, contentType, e, headers, json, opts, pre, response_body, response_body_el, supportsAudioPlayback, url;
if (response.content === void 0) { if (response.content === void 0) {
content = response.data; content = response.data;
url = response.url; url = response.url;
@@ -1840,6 +1852,11 @@ OperationView = (function(superClass) {
} }
$(".response_body", $(this.el)).removeClass('json'); $(".response_body", $(this.el)).removeClass('json');
$(".response_body", $(this.el)).removeClass('xml'); $(".response_body", $(this.el)).removeClass('xml');
supportsAudioPlayback = function(contentType) {
var audioElement;
audioElement = document.createElement('audio');
return !!(audioElement.canPlayType && audioElement.canPlayType(contentType).replace(/no/, ''));
};
if (!content) { if (!content) {
code = $('<code />').text("no content"); code = $('<code />').text("no content");
pre = $('<pre class="json" />').append(code); pre = $('<pre class="json" />').append(code);
@@ -1861,6 +1878,8 @@ OperationView = (function(superClass) {
pre = $('<pre class="xml" />').append(code); pre = $('<pre class="xml" />').append(code);
} else if (/^image\//.test(contentType)) { } else if (/^image\//.test(contentType)) {
pre = $('<img>').attr('src', url); pre = $('<img>').attr('src', url);
} else if (/^audio\//.test(contentType) && supportsAudioPlayback(contentType)) {
pre = $('<audio controls>').append($('<source>').attr('src', url).attr('type', contentType));
} else { } else {
code = $('<code />').text(content); code = $('<code />').text(content);
pre = $('<pre class="json" />').append(code); pre = $('<pre class="json" />').append(code);

File diff suppressed because one or more lines are too long

View File

@@ -74,10 +74,11 @@
<th>HTTP Status Code</th> <th>HTTP Status Code</th>
<th>Reason</th> <th>Reason</th>
<th>Response Model</th> <th>Response Model</th>
<th>Headers</th>
</tr> </tr>
</thead> </thead>
<tbody class="operation-status"> <tbody class="operation-status">
</tbody> </tbody>
</table> </table>
{{/if}} {{/if}}

View File

@@ -1,3 +1,16 @@
<td width='15%' class='code'>{{code}}</td> <td width='15%' class='code'>{{code}}</td>
<td>{{{message}}}</td> <td>{{{message}}}</td>
<td width='50%'><span class="model-signature" /></td> <td width='50%'><span class="model-signature" /></td>
<td class="headers">
<table>
<tbody>
{{#each headers}}
<tr>
<td>{{@key}}</td>
<td>{{this.description}}</td>
<td>{{this.type}}</td>
</tr>
{{/each}}
</tbody>
</table>
</td>