Feature: add responseHooks option for callbacks on responses
Add a responseHooks option that allows the user to process the response of an API call. The responseHooks option is an object where key is an operationId and value is a function that receives the XHR response object and the OperationView object. Use case: process authentication requests done with the "Try out!" button to inject apiKey in the AuthView and the router on success.
This commit is contained in:
@@ -788,6 +788,11 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({
|
|||||||
$('.request_headers', $(this.el)).html('<pre>' + _.escape(JSON.stringify(requestHeaders, null, ' ')).replace(/\n/g, '<br>') + '</pre>');
|
$('.request_headers', $(this.el)).html('<pre>' + _.escape(JSON.stringify(requestHeaders, null, ' ')).replace(/\n/g, '<br>') + '</pre>');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Call user-defined hook
|
||||||
|
if (opts.responseHooks && opts.responseHooks[this.nickname]) {
|
||||||
|
opts.responseHooks[this.nickname](response, this);
|
||||||
|
}
|
||||||
|
|
||||||
var response_body_el = $('.response_body', $(this.el))[0];
|
var response_body_el = $('.response_body', $(this.el))[0];
|
||||||
// only highlight the response if response is less than threshold, default state is highlight response
|
// 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) {
|
if (opts.highlightSizeThreshold && typeof response.data !== 'undefined' && response.data.length > opts.highlightSizeThreshold) {
|
||||||
|
|||||||
Reference in New Issue
Block a user