From 30017c8242ca73eb9e18feaca833b1e8a5bf4315 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Tue, 11 Aug 2015 18:52:56 +0200 Subject: [PATCH] Upgrade to strong-swagger-ui@21.0 (swagger-ui@2.1) --- index.js | 2 +- package.json | 2 +- public/index.html | 16 +++++++----- public/lib/loadSwaggerUI.js | 50 ++++++++++++++++++++++++++----------- 4 files changed, 47 insertions(+), 23 deletions(-) diff --git a/index.js b/index.js index fbe716d..1fa4d36 100644 --- a/index.js +++ b/index.js @@ -7,7 +7,7 @@ var path = require('path'); var urlJoin = require('./lib/url-join'); var _defaults = require('lodash').defaults; var swagger = require('./lib/swagger'); -var SWAGGER_UI_ROOT = require('strong-swagger-ui').dist; +var SWAGGER_UI_ROOT = require('strong-swagger-ui/index').dist; var STATIC_ROOT = path.join(__dirname, 'public'); module.exports = explorer; diff --git a/package.json b/package.json index d5cb965..3699e1e 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,6 @@ "cors": "^2.7.1", "debug": "^2.2.0", "lodash": "^3.10.0", - "strong-swagger-ui": "^20.0.2" + "strong-swagger-ui": "^21.0.0-dev.1" } } diff --git a/public/index.html b/public/index.html index 68a14b7..c39f26a 100644 --- a/public/index.html +++ b/public/index.html @@ -1,22 +1,26 @@ + StrongLoop API Explorer - - - - + + + + + + + - + - + diff --git a/public/lib/loadSwaggerUI.js b/public/lib/loadSwaggerUI.js index 8cea670..1d4a53d 100644 --- a/public/lib/loadSwaggerUI.js +++ b/public/lib/loadSwaggerUI.js @@ -3,6 +3,11 @@ // Refactoring of inline script from index.html. /*global SwaggerUi, log, ApiKeyAuthorization, hljs, window, $ */ $(function() { + // Pre load translate... + if(window.SwaggerTranslator) { + window.SwaggerTranslator.translate(); + } + var lsKey = 'swagger_accessToken'; $.getJSON('config.json', function(config) { log(config); @@ -16,12 +21,26 @@ $(function() { apiKey: '', dom_id: 'swagger-ui-container', supportHeaderParams: true, - supportedSubmitMethods: ['get', 'post', 'put', 'delete'], onComplete: function(swaggerApi, swaggerUi) { log('Loaded SwaggerUI'); log(swaggerApi); log(swaggerUi); - $('pre code').each(function(i, e) {hljs.highlightBlock(e); }); + + if(window.SwaggerTranslator) { + window.SwaggerTranslator.translate(); + } + + $('pre code').each(function(i, e) { + hljs.highlightBlock(e); + }); + + // Recover accessToken from localStorage if present. + if (window.localStorage) { + var key = window.localStorage.getItem(lsKey); + if (key) { + $('#input_accessToken').val(key).submit(); + } + } }, onFailure: function(data) { log('Unable to Load SwaggerUI'); @@ -36,14 +55,6 @@ $(function() { $('#api_selector').submit(setAccessToken); $('#input_accessToken').keyup(onInputChange); - // Recover accessToken from localStorage if present. - if (window.localStorage) { - var key = window.localStorage.getItem(lsKey); - if (key) { - $('#input_accessToken').val(key).submit(); - } - } - window.swaggerUi.load(); } @@ -54,23 +65,26 @@ $(function() { log('key: ' + key); if(key && key.trim() !== '') { log('added accessToken ' + key); - window.authorizations.add('key', new ApiKeyAuthorization('access_token', key, 'query')); + var apiKeyAuth = new SwaggerClient.ApiKeyAuthorization('access_token', key, 'query'); + window.swaggerUi.api.clientAuthorizations.add('key', apiKeyAuth); accessToken = key; $('.accessTokenDisplay').text('Token Set.').addClass('set'); $('.accessTokenDisplay').attr('data-tooltip', 'Current Token: ' + key); - - // Save this token to localStorage if we can to make it persist on refresh. + + // Save this token to localStorage if we can to make it persist on refresh. if (window.localStorage) { window.localStorage.setItem(lsKey, key); } } - // If submitted with an empty token, remove the current token. Can be + // If submitted with an empty token, remove the current token. Can be // useful to intentionally remove authorization. else { log('removed accessToken.'); $('.accessTokenDisplay').text('Token Not Set.').removeClass('set'); $('.accessTokenDisplay').removeAttr('data-tooltip'); - window.authorizations.remove('key'); + if (window.swaggerUi) { + window.swaggerUi.api.clientAuthorizations.remove('key'); + } if (window.localStorage) { window.localStorage.removeItem(lsKey); } @@ -87,6 +101,12 @@ $(function() { $('.accessTokenDisplay').text('Token Set.'); } } + + function log() { + if ('console' in window) { + console.log.apply(console, arguments); + } + } });