From b579783ba0e7ee88b4998d371f495c30901bed73 Mon Sep 17 00:00:00 2001 From: Mohsen Azimi Date: Wed, 15 Apr 2015 14:44:35 -0700 Subject: [PATCH] Add API Key auth in onComplete callback of SwaggerUI#load call --- dist/index.html | 6 ++++-- dist/lib/swagger-oauth.js | 2 +- src/main/html/index.html | 12 +++++------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/dist/index.html b/dist/index.html index 10a0d902..19b17b8b 100644 --- a/dist/index.html +++ b/dist/index.html @@ -42,9 +42,12 @@ }); */ } + $('pre code').each(function(i, e) { hljs.highlightBlock(e) }); + + addApiKeyAuthorization(); }, onFailure: function(data) { log("Unable to Load SwaggerUI"); @@ -53,9 +56,8 @@ sorter : "alpha" }); - function addApiKeyAuthorization() { + function addApiKeyAuthorization(){ var key = encodeURIComponent($('#input_apiKey')[0].value); - log("key: " + key); if(key && key.trim() != "") { var apiKeyAuth = new SwaggerClient.ApiKeyAuthorization("api_key", key, "query"); window.swaggerUi.api.clientAuthorizations.add("api_key", apiKeyAuth); diff --git a/dist/lib/swagger-oauth.js b/dist/lib/swagger-oauth.js index b2254b7f..3b69fd3d 100644 --- a/dist/lib/swagger-oauth.js +++ b/dist/lib/swagger-oauth.js @@ -277,7 +277,7 @@ window.onOAuthComplete = function onOAuthComplete(token) { } } }); - window.authorizations.add(oauth2KeyName, new ApiKeyAuthorization('Authorization', 'Bearer ' + b, 'header')); + window.swaggerUi.api.clientAuthorizations.add(oauth2KeyName, new SwaggerClient.ApiKeyAuthorization('Authorization', 'Bearer ' + b, 'header')); } } } diff --git a/src/main/html/index.html b/src/main/html/index.html index 4ffdc9b3..19b17b8b 100644 --- a/src/main/html/index.html +++ b/src/main/html/index.html @@ -42,9 +42,12 @@ }); */ } + $('pre code').each(function(i, e) { hljs.highlightBlock(e) }); + + addApiKeyAuthorization(); }, onFailure: function(data) { log("Unable to Load SwaggerUI"); @@ -53,9 +56,8 @@ sorter : "alpha" }); - function addApiKeyAuthorization() { + function addApiKeyAuthorization(){ var key = encodeURIComponent($('#input_apiKey')[0].value); - log("key: " + key); if(key && key.trim() != "") { var apiKeyAuth = new SwaggerClient.ApiKeyAuthorization("api_key", key, "query"); window.swaggerUi.api.clientAuthorizations.add("api_key", apiKeyAuth); @@ -69,15 +71,11 @@ /* var apiKey = "myApiKeyXXXX123456789"; $('#input_apiKey').val(apiKey); + addApiKeyAuthorization(); */ window.swaggerUi.load(); - // Add authorization if auth input is not empty - if ($('#input_apiKey').val().length) { - addApiKeyAuthorization(); - } - function log() { if ('console' in window) { console.log.apply(console, arguments);