github.com/qubitproducts/logspray@v0.2.14/server/swagger-ui/src/main/javascript/utils/utils.js (about)

     1  'use strict';
     2  
     3  window.SwaggerUi.utils = {
     4      parseSecurityDefinitions: function (security, securityDefinitions) {
     5          var auths = Object.assign({}, securityDefinitions);
     6          var oauth2Arr = [];
     7          var authsArr = [];
     8          var scopes = [];
     9          var utils = window.SwaggerUi.utils;
    10  
    11          if (!Array.isArray(security)) { return null; }
    12  
    13          security.forEach(function (item) {
    14              var singleSecurity = {};
    15              var singleOauth2Security = {};
    16  
    17              for (var key in item) {
    18                  if (Array.isArray(item[key])) {
    19                      if (!auths[key]) { continue; }
    20                      auths[key] = auths[key] || {};
    21                      if (auths[key].type === 'oauth2') {
    22                          singleOauth2Security[key] = Object.assign({}, auths[key]);
    23                          singleOauth2Security[key].scopes = Object.assign({}, auths[key].scopes);
    24                          for (var i in singleOauth2Security[key].scopes) {
    25                              if (item[key].indexOf(i) < 0) {
    26                                  delete singleOauth2Security[key].scopes[i];
    27                              }
    28                          }
    29                          singleOauth2Security[key].scopes = utils.parseOauth2Scopes(singleOauth2Security[key].scopes);
    30                          scopes = _.merge(scopes, singleOauth2Security[key].scopes);
    31                      } else {
    32                          singleSecurity[key] = Object.assign({}, auths[key]);
    33                      }
    34                  } else {
    35                      if (item[key].type === 'oauth2') {
    36                          singleOauth2Security[key] = Object.assign({}, item[key]);
    37                          singleOauth2Security[key].scopes = utils.parseOauth2Scopes(singleOauth2Security[key].scopes);
    38                          scopes = _.merge(scopes, singleOauth2Security[key].scopes);
    39                      } else {
    40                          singleSecurity[key] = item[key];
    41                      }
    42                  }
    43              }
    44  
    45              if (!_.isEmpty(singleSecurity)) {
    46                  authsArr.push(singleSecurity);
    47              }
    48  
    49              if (!_.isEmpty(singleOauth2Security)){
    50                  oauth2Arr.push(singleOauth2Security);
    51              }
    52          });
    53  
    54          return {
    55              auths : authsArr,
    56              oauth2: oauth2Arr,
    57              scopes: scopes
    58          };
    59      },
    60  
    61      parseOauth2Scopes: function (data) {
    62          var scopes = Object.assign({}, data);
    63          var result = [];
    64          var key;
    65  
    66          for (key in scopes) {
    67              result.push({scope: key, description: scopes[key]});
    68          }
    69  
    70          return result;
    71      },
    72  
    73      sanitize: function(html) {
    74          // Strip the script tags from the html and inline evenhandlers
    75          html = html.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, '');
    76          html = html.replace(/(on\w+="[^"]*")*(on\w+='[^']*')*(on\w+=\w*\(\w*\))*/gi, '');
    77  
    78          return html;
    79      }
    80  };