Sha256: a71033326478405d416e0da85d9af188a32630cc26e9cb3156c82c415fe6e373

Contents?: true

Size: 1.82 KB

Versions: 3

Compression:

Stored size: 1.82 KB

Contents

window.log = function(){
  log.history = log.history || [];   // store logs to an array for reference
  log.history.push(arguments);
  if(this.console){
    console.log( Array.prototype.slice.call(arguments) );
  }
};

$(function () {
  var url = window.location.search.match(/url=([^&]+)/);
  if (url && url.length > 1) {
    url = decodeURIComponent(url[1]);
  } else {
    url = location.protocol + "//" + location.host + "/swagger.json";
  }
  window.swaggerUi = new SwaggerUi({
    url: url,
    dom_id: "swagger-ui-container",
    supportedSubmitMethods: ['get', 'post', 'put', 'delete', 'patch'],
    onComplete: function(swaggerApi, swaggerUi){
      $('pre code').each(function(i, e) {
        hljs.highlightBlock(e)
      });

      // set default content type
      $('select[name="responseContentType"]').val(window.default_content_type);
      $('select[name="parameterContentType"]').val(window.default_content_type);
    },
    onFailure: function(data) {
      log("Unable to Load SwaggerUI");
    },
    docExpansion: "none",
    apisSorter : "alpha"
  });

  function addApiKeyAuthorization() {
    var $apiSelectorForm = $('#api_selector');
    var authenticationKey = $apiSelectorForm.data('authenticationKey');
    var authenticationType = $apiSelectorForm.data('authenticationType');

    var key = $('#input_apiKey')[0].value;

    if(key && key.trim() != '') {
      swaggerUi.api.clientAuthorizations.add(
        'key',
        new SwaggerClient.ApiKeyAuthorization(authenticationKey, key, authenticationType)
      );
    }
  }

  var $apiKeyInput = $('#input_apiKey');

  $apiKeyInput.change(function() {
    addApiKeyAuthorization();
  });

  var $apiSelectorForm = $('api_selector');
  var apiKey = $apiSelectorForm.data('authenticationValue');
  $apiKeyInput.val(apiKey);
  addApiKeyAuthorization();

  window.swaggerUi.load();
});

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
swaggard-0.3.0 app/assets/javascripts/swaggard/swaggard.js
swaggard-0.2.1 app/assets/javascripts/swaggard/swaggard.js
swaggard-0.2.0 app/assets/javascripts/swaggard/swaggard.js