diff --git a/README.md b/README.md
index 6aca9b41..ffb30355 100644
--- a/README.md
+++ b/README.md
@@ -96,8 +96,9 @@ operationsSorter | Apply a sort to the operation list of each API. It can be 'al
onComplete | This is a callback function parameter which can be passed to be notified of when SwaggerUI has completed rendering successfully.
onFailure | This is a callback function parameter which can be passed to be notified of when SwaggerUI encountered a failure was unable to render.
highlightSizeThreshold | Any size response below this threshold will be highlighted syntactically, attempting to highlight large responses can lead to browser hangs, not including a threshold will default to highlight all returned responses.
-supportedSubmitMethods | An array of of the HTTP operations that will have the 'Try it out!` option. An empty array disables all operations. This does not filter the operations from the display.
+supportedSubmitMethods | An array of of the HTTP operations that will have the 'Try it out!' option. An empty array disables all operations. This does not filter the operations from the display.
oauth2RedirectUrl | OAuth redirect URL
+showRequestHeaders | Whether or not to show the headers that were sent when making a request via the 'Try it out!' option. Defaults to `false`.
* All other parameters are explained in greater detail below
diff --git a/dist/index.html b/dist/index.html
index 9429a589..a6904d0f 100644
--- a/dist/index.html
+++ b/dist/index.html
@@ -52,7 +52,8 @@
log("Unable to Load SwaggerUI");
},
docExpansion: "none",
- apisSorter: "alpha"
+ apisSorter: "alpha",
+ showRequestHeaders: false
});
function addApiKeyAuthorization(){
diff --git a/dist/swagger-ui.js b/dist/swagger-ui.js
index ee30fd4b..c3c2686d 100644
--- a/dist/swagger-ui.js
+++ b/dist/swagger-ui.js
@@ -408,6 +408,8 @@ this["Handlebars"]["templates"]["operation"] = Handlebars.template({"1":function
return "";
},"24":function(depth0,helpers,partials,data) {
return "
\n";
+ },"26":function(depth0,helpers,partials,data) {
+ return " Request Headers \n \n";
},"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) {
var stack1, helper, options, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression, blockHelperMissing=helpers.blockHelperMissing, buffer = "\n \n \n \n
Request URL \n
\n
Response Body \n
\n
Response Code \n
\n
Response Headers \n \n
\n \n \n \n";
+ buffer += " \n \n
Request URL \n
\n";
+ stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.showRequestHeaders : depth0), {"name":"if","hash":{},"fn":this.program(26, data),"inverse":this.noop,"data":data});
+ if (stack1 != null) { buffer += stack1; }
+ return buffer + "
Response Body \n
\n
Response Code \n
\n
Response Headers \n \n
\n \n \n \n";
},"useData":true});
this["Handlebars"]["templates"]["param_list"] = Handlebars.template({"1":function(depth0,helpers,partials,data) {
var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression;
@@ -1574,6 +1579,10 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({
signature: this.model.responseClassSignature
};
}
+ var opts = this.options.swaggerOptions;
+ if (opts.showRequestHeaders) {
+ this.model.showRequestHeaders = true;
+ }
$(this.el).html(Handlebars.templates.operation(this.model));
if (signatureModel) {
responseSignatureView = new SwaggerUi.Views.SignatureView({
@@ -1655,7 +1664,7 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({
// Note: copied from CoffeeScript compiled file
// TODO: redactor
submitOperation: function(e) {
- var error_free, form, isFileUpload, l, len, len1, len2, m, map, n, o, opts, ref1, ref2, ref3, val;
+ var error_free, form, isFileUpload, map, opts;
if (e !== null) {
e.preventDefault();
}
@@ -1704,43 +1713,16 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({
}
});
if (error_free) {
- map = {};
+ map = this.getInputMap(form);
+ isFileUpload = this.isFileUpload(form);
opts = {
parent: this
};
- if(this.options.swaggerOptions) {
+ if (this.options.swaggerOptions) {
for(var key in this.options.swaggerOptions) {
opts[key] = this.options.swaggerOptions[key];
}
}
- isFileUpload = false;
- ref1 = form.find('input');
- for (l = 0, len = ref1.length; l < len; l++) {
- o = ref1[l];
- if ((o.value !== null) && jQuery.trim(o.value).length > 0) {
- map[o.name] = o.value;
- }
- if (o.type === 'file') {
- map[o.name] = o.files[0];
- isFileUpload = true;
- }
- }
- ref2 = form.find('textarea');
- for (m = 0, len1 = ref2.length; m < len1; m++) {
- o = ref2[m];
- val = this.getTextAreaValue(o);
- if ((val !== null) && jQuery.trim(val).length > 0) {
- map[o.name] = val;
- }
- }
- ref3 = form.find('select');
- for (n = 0, len2 = ref3.length; n < len2; n++) {
- o = ref3[n];
- val = this.getSelectedValue(o);
- if ((val !== null) && jQuery.trim(val).length > 0) {
- map[o.name] = val;
- }
- }
opts.responseContentType = $('div select[name=responseContentType]', $(this.el)).val();
opts.requestContentType = $('div select[name=parameterContentType]', $(this.el)).val();
$('.response_throbber', $(this.el)).show();
@@ -1752,6 +1734,51 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({
}
},
+ getInputMap: function (form) {
+ var map, ref1, l, len, o, ref2, m, len1, val, ref3, n, len2;
+ map = {};
+ ref1 = form.find('input');
+ for (l = 0, len = ref1.length; l < len; l++) {
+ o = ref1[l];
+ if ((o.value !== null) && jQuery.trim(o.value).length > 0) {
+ map[o.name] = o.value;
+ }
+ if (o.type === 'file') {
+ map[o.name] = o.files[0];
+ }
+ }
+ ref2 = form.find('textarea');
+ for (m = 0, len1 = ref2.length; m < len1; m++) {
+ o = ref2[m];
+ val = this.getTextAreaValue(o);
+ if ((val !== null) && jQuery.trim(val).length > 0) {
+ map[o.name] = val;
+ }
+ }
+ ref3 = form.find('select');
+ for (n = 0, len2 = ref3.length; n < len2; n++) {
+ o = ref3[n];
+ val = this.getSelectedValue(o);
+ if ((val !== null) && jQuery.trim(val).length > 0) {
+ map[o.name] = val;
+ }
+ }
+ return map;
+ },
+
+ isFileUpload: function (form) {
+ var ref1, l, len, o;
+ var isFileUpload = false;
+ ref1 = form.find('input');
+ for (l = 0, len = ref1.length; l < len; l++) {
+ o = ref1[l];
+ if (o.type === 'file') {
+ isFileUpload = true;
+ }
+ }
+ return isFileUpload;
+ },
+
success: function(response, parent) {
parent.showCompleteStatus(response);
},
@@ -1759,7 +1786,7 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({
// Note: This is compiled code
// TODO: Refactor
handleFileUpload: function(map, form) {
- var bodyParam, el, headerParams, l, len, len1, len2, len3, m, n, o, p, param, params, ref1, ref2, ref3, ref4;
+ var bodyParam, el, headerParams, l, len, len1, len3, m, o, p, param, params, ref1, ref2, ref4;
ref1 = form.serializeArray();
for (l = 0, len = ref1.length; l < len; l++) {
o = ref1[l];
@@ -1778,14 +1805,6 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({
}
}
}
- headerParams = {};
- ref3 = this.model.parameters;
- for (n = 0, len2 = ref3.length; n < len2; n++) {
- param = ref3[n];
- if (param.paramType === 'header') {
- headerParams[param.name] = map[param.name];
- }
- }
ref4 = form.find('input[type~="file"]');
for (p = 0, len3 = ref4.length; p < len3; p++) {
el = ref4[p];
@@ -2083,11 +2102,20 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({
$('.response', $(this.el)).slideDown();
$('.response_hider', $(this.el)).show();
$('.response_throbber', $(this.el)).hide();
- var response_body_el = $('.response_body', $(this.el))[0];
- // only highlight the response if response is less than threshold, default state is highlight response
var opts = this.options.swaggerOptions;
- if (opts.highlightSizeThreshold && response.data.length > opts.highlightSizeThreshold) {
+
+ if (opts.showRequestHeaders) {
+ var form = $('.sandbox', $(this.el)),
+ map = this.getInputMap(form),
+ requestHeaders = this.model.getHeaderParams(map);
+ delete requestHeaders['Content-Type'];
+ $('.request_headers', $(this.el)).html('' + _.escape(JSON.stringify(requestHeaders, null, ' ')).replace(/\n/g, ' ') + ' ');
+ }
+
+ var response_body_el = $('.response_body', $(this.el))[0];
+ // only highlight the response if response is less than threshold, default state is highlight response
+ if (opts.highlightSizeThreshold && typeof response.data !== 'undefined' && response.data.length > opts.highlightSizeThreshold) {
return response_body_el;
} else {
return hljs.highlightBlock(response_body_el);
diff --git a/dist/swagger-ui.min.js b/dist/swagger-ui.min.js
index d41effb3..ba6d9579 100644
--- a/dist/swagger-ui.min.js
+++ b/dist/swagger-ui.min.js
@@ -1,2 +1,4 @@
-(function(){this.Handlebars=this.Handlebars||{},this.Handlebars.templates=this.Handlebars.templates||{},this.Handlebars.templates.apikey_button_view=Handlebars.template({compiler:[6,">= 2.0.0-beta.1"],main:function(e,n,t,a){var i,s="function",l=n.helperMissing,r=this.escapeExpression;return"\n\n\n'},useData:!0}),this.Handlebars.templates.basic_auth_button_view=Handlebars.template({compiler:[6,">= 2.0.0-beta.1"],main:function(e,n,t,a){return'\n\n\n'},useData:!0}),this.Handlebars.templates.content_type=Handlebars.template({1:function(e,n,t,a){var i,s="";return i=n.each.call(e,null!=e?e.produces:e,{name:"each",hash:{},fn:this.program(2,a),inverse:this.noop,data:a}),null!=i&&(s+=i),s},2:function(e,n,t,a){var i,s=this.lambda,l=' ',i=s(e,e),null!=i&&(l+=i),l+" \n"},4:function(e,n,t,a){return' application/json \n'},compiler:[6,">= 2.0.0-beta.1"],main:function(e,n,t,a){var i,s=' \n\n';return i=n["if"].call(e,null!=e?e.produces:e,{name:"if",hash:{},fn:this.program(1,a),inverse:this.program(4,a),data:a}),null!=i&&(s+=i),s+" \n"},useData:!0}),$(function(){$.fn.vAlign=function(){return this.each(function(){var e=$(this).height(),n=$(this).parent().height(),t=(n-e)/2;$(this).css("margin-top",t)})},$.fn.stretchFormtasticInputWidthToParent=function(){return this.each(function(){var e=$(this).closest("form").innerWidth(),n=parseInt($(this).closest("form").css("padding-left"),10)+parseInt($(this).closest("form").css("padding-right"),10),t=parseInt($(this).css("padding-left"),10)+parseInt($(this).css("padding-right"),10);$(this).css("width",e-n-t)})},$("form.formtastic li.string input, form.formtastic textarea").stretchFormtasticInputWidthToParent(),$("ul.downplayed li div.content p").vAlign(),$("form.sandbox").submit(function(){var e=!0;return $(this).find("input.required").each(function(){$(this).removeClass("error"),""===$(this).val()&&($(this).addClass("error"),$(this).wiggle(),e=!1)}),e})}),Function.prototype.bind&&console&&"object"==typeof console.log&&["log","info","warn","error","assert","dir","clear","profile","profileEnd"].forEach(function(e){console[e]=this.bind(console[e],console)},Function.prototype.call),window.Docs={shebang:function(){var e=$.param.fragment().split("/");switch(e.shift(),e.length){case 1:if(e[0].length>0){var n="resource_"+e[0];Docs.expandEndpointListForResource(e[0]),$("#"+n).slideto({highlight:!1})}break;case 2:Docs.expandEndpointListForResource(e[0]),$("#"+n).slideto({highlight:!1});var t=e.join("_"),a=t+"_content";Docs.expandOperation($("#"+a)),$("#"+t).slideto({highlight:!1})}},toggleEndpointListForResource:function(e){var n=$("li#resource_"+Docs.escapeResourceName(e)+" ul.endpoints");n.is(":visible")?Docs.collapseEndpointListForResource(e):Docs.expandEndpointListForResource(e)},expandEndpointListForResource:function(e){var e=Docs.escapeResourceName(e);if(""==e)return void $(".resource ul.endpoints").slideDown();$("li#resource_"+e).addClass("active");var n=$("li#resource_"+e+" ul.endpoints");n.slideDown()},collapseEndpointListForResource:function(e){var e=Docs.escapeResourceName(e);if(""==e)return void $(".resource ul.endpoints").slideUp();$("li#resource_"+e).removeClass("active");var n=$("li#resource_"+e+" ul.endpoints");n.slideUp()},expandOperationsForResource:function(e){return Docs.expandEndpointListForResource(e),""==e?void $(".resource ul.endpoints li.operation div.content").slideDown():void $("li#resource_"+Docs.escapeResourceName(e)+" li.operation div.content").each(function(){Docs.expandOperation($(this))})},collapseOperationsForResource:function(e){return Docs.expandEndpointListForResource(e),""==e?void $(".resource ul.endpoints li.operation div.content").slideUp():void $("li#resource_"+Docs.escapeResourceName(e)+" li.operation div.content").each(function(){Docs.collapseOperation($(this))})},escapeResourceName:function(e){return e.replace(/[!"#$%&'()*+,.\/:;<=>?@\[\\\]\^`{|}~]/g,"\\$&")},expandOperation:function(e){e.slideDown()},collapseOperation:function(e){e.slideUp()}},Handlebars.registerHelper("sanitize",function(e){return e=e.replace(/