SanSYS

swagger custom headers

Sep 27th, 2015
24,560
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; (function swaggerAddCustomHeaders() {
  2.     var addAuthorization = function () {
  3.         var self = $(this),
  4.             val = self.val();
  5.  
  6.             if (val) {
  7.                 var headerName = self.data('header');
  8.  
  9.                 swaggerUi.api.clientAuthorizations.add(headerName, new SwaggerClient.ApiKeyAuthorization(headerName, val, "header"));
  10.             }
  11.         },
  12.         addCustomHeaderEditor = function (name) {
  13.             $('<div class="input"><input placeholder="' + name + '" id="' + name + '" data-header="' + name + '" type="text" size="10"></div>')
  14.                 .insertBefore('#api_selector div.input:last-child');
  15.  
  16.             $('#' + name).change(addAuthorization);
  17.  
  18.             if (window.localStorage) {
  19.                 if (window.localStorage[name]) {
  20.                     $('#' + name).val(window.localStorage[name]);
  21.                     $('#' + name).change();
  22.                 }
  23.             }
  24.         };
  25.  
  26.     $("#input_apiKey, #explore").hide();
  27.  
  28.     addCustomHeaderEditor('X-TOKEN');
  29.     addCustomHeaderEditor('Company');
  30.     addCustomHeaderEditor('Mobile');
  31. })();
Advertisement
Add Comment
Please, Sign In to add comment