Add file download to try operation

This commit is contained in:
Mohsen Azimi
2015-03-26 11:41:06 -07:00
parent cc34e270b7
commit 6b8f6e2827
3 changed files with 1334 additions and 963 deletions

2130
dist/swagger-ui.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -572,6 +572,8 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({
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);
// JSON
} else if (contentType === 'application/json' || /\+json$/.test(contentType)) { } else if (contentType === 'application/json' || /\+json$/.test(contentType)) {
var json = null; var json = null;
try { try {
@@ -581,16 +583,33 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({
} }
code = $('<code />').text(json); code = $('<code />').text(json);
pre = $('<pre class="json" />').append(code); pre = $('<pre class="json" />').append(code);
// XML
} else if (contentType === 'application/xml' || /\+xml$/.test(contentType)) { } else if (contentType === 'application/xml' || /\+xml$/.test(contentType)) {
code = $('<code />').text(this.formatXml(content)); code = $('<code />').text(this.formatXml(content));
pre = $('<pre class="xml" />').append(code); pre = $('<pre class="xml" />').append(code);
// HTML
} else if (contentType === 'text/html') { } else if (contentType === 'text/html') {
code = $('<code />').html(_.escape(content)); code = $('<code />').html(_.escape(content));
pre = $('<pre class="xml" />').append(code); pre = $('<pre class="xml" />').append(code);
// Image
} else if (/^image\//.test(contentType)) { } else if (/^image\//.test(contentType)) {
pre = $('<img>').attr('src', url); pre = $('<img>').attr('src', url);
// Audio
} else if (/^audio\//.test(contentType) && supportsAudioPlayback(contentType)) { } else if (/^audio\//.test(contentType) && supportsAudioPlayback(contentType)) {
pre = $('<audio controls>').append($('<source>').attr('src', url).attr('type', contentType)); pre = $('<audio controls>').append($('<source>').attr('src', url).attr('type', contentType));
// Download
} else if (headers['Content-Disposition'].test(/attachment/) ||
headers['content-disposition'].test(/attachment/) ||
headers['Content-Description'].test(/File Transfer/) ||
headers['content-description'].test(/File Transfer/)) {
window.location = response.url;
// Anything else (CORS)
} else { } else {
code = $('<code />').text(content); code = $('<code />').text(content);
pre = $('<pre class="json" />').append(code); pre = $('<pre class="json" />').append(code);