Merge pull request #2506 from swagger-api/issue-2499

Remove globals, regression in v2.2.6
This commit is contained in:
Tony Tam
2016-11-18 09:05:13 -08:00
committed by GitHub
10 changed files with 56 additions and 44 deletions

View File

@@ -11,7 +11,7 @@ var additionalQueryStringParams;
function handleLogin() {
var scopes = [];
var auths = window.swaggerUi.api.authSchemes || window.swaggerUi.api.securityDefinitions;
var auths = window.swaggerUiAuth.authSchemes || window.swaggerUiAuth.securityDefinitions;
if(auths) {
var key;
var defs = auths;
@@ -36,8 +36,7 @@ function handleLogin() {
}
}
if(window.swaggerUi.api
&& window.swaggerUi.api.info) {
if(window.swaggerUi.api && window.swaggerUi.api.info) {
appName = window.swaggerUi.api.info.title;
}
@@ -285,7 +284,7 @@ window.processOAuthCode = function processOAuthCode(data) {
});
};
window.onOAuthComplete = function onOAuthComplete(token,OAuthSchemeKey) {
window.onOAuthComplete = function onOAuthComplete(token, OAuthSchemeKey) {
if(token) {
if(token.error) {
var checkbox = $('input[type=checkbox],.secured')
@@ -295,7 +294,7 @@ window.onOAuthComplete = function onOAuthComplete(token,OAuthSchemeKey) {
alert(token.error);
}
else {
var b = token[window.swaggerUi.tokenName];
var b = token[window.swaggerUiAuth.tokenName];
if (!OAuthSchemeKey){
OAuthSchemeKey = token.state;
}
@@ -339,9 +338,11 @@ window.onOAuthComplete = function onOAuthComplete(token,OAuthSchemeKey) {
}
}
});
window.swaggerUi.api.clientAuthorizations.add(window.OAuthSchemeKey, new SwaggerClient.ApiKeyAuthorization('Authorization', 'Bearer ' + b, 'header'));
if(typeof window.swaggerUi !== 'undefined') {
window.swaggerUi.api.clientAuthorizations.add(window.swaggerUiAuth.OAuthSchemeKey, new SwaggerClient.ApiKeyAuthorization('Authorization', 'Bearer ' + b, 'header'));
window.swaggerUi.load();
}
}
}
}
};

2
dist/o2c.html vendored
View File

@@ -11,7 +11,7 @@ qp = qp ? JSON.parse('{"' + qp.replace(/&/g, '","').replace(/=/g,'":"') + '"}',
return key===""?value:decodeURIComponent(value) }
):{}
if (window.opener.swaggerUi.tokenUrl)
if (window.opener.swaggerUiAuth.tokenUrl)
window.opener.processOAuthCode(qp);
else
window.opener.onOAuthComplete(qp);

31
dist/swagger-ui.js vendored
View File

@@ -21935,8 +21935,8 @@ window.SwaggerUi.utils = {};
'use strict';
window.SwaggerUi.utils = {
parseSecurityDefinitions: function (security) {
var auths = Object.assign({}, window.swaggerUi.api.authSchemes || window.swaggerUi.api.securityDefinitions);
parseSecurityDefinitions: function (security, securityDefinitions) {
var auths = Object.assign({}, securityDefinitions);
var oauth2Arr = [];
var authsArr = [];
var scopes = [];
@@ -22216,7 +22216,11 @@ SwaggerUi.Collections.AuthsCollection = Backbone.Collection.extend({
},
parse: function (data) {
var authz = Object.assign({}, window.swaggerUi.api.clientAuthorizations.authz);
var authz = {};
if(typeof window.swaggerUi !== 'undefined') {
authz = Object.assign({}, window.swaggerUi.api.clientAuthorizations.authz);
}
return _.map(data, function (auth, name) {
var isBasic = authz[name] && auth.type === 'basic' && authz[name].username && authz[name].password;
@@ -22395,8 +22399,9 @@ SwaggerUi.Views.AuthView = Backbone.View.extend({
var scopes = _.map(auth.get('scopes'), function (scope) {
return scope.scope;
});
var container = window.swaggerUiAuth || (window.swaggerUiAuth = {});
var state, dets, ep;
window.OAuthSchemeKey = auth.get('title');
container.OAuthSchemeKey = auth.get('title');
window.enabledScopes = scopes;
var flow = auth.get('flow');
@@ -22404,14 +22409,14 @@ SwaggerUi.Views.AuthView = Backbone.View.extend({
if(auth.get('type') === 'oauth2' && flow && (flow === 'implicit' || flow === 'accessCode')) {
dets = auth.attributes;
url = dets.authorizationUrl + '?response_type=' + (flow === 'implicit' ? 'token' : 'code');
window.swaggerUi.tokenName = dets.tokenName || 'access_token';
window.swaggerUi.tokenUrl = (flow === 'accessCode' ? dets.tokenUrl : null);
state = window.OAuthSchemeKey;
container.tokenName = dets.tokenName || 'access_token';
container.tokenUrl = (flow === 'accessCode' ? dets.tokenUrl : null);
state = container.OAuthSchemeKey;
}
else if(auth.get('type') === 'oauth2' && flow && (flow === 'application')) {
dets = auth.attributes;
window.swaggerUi.tokenName = dets.tokenName || 'access_token';
this.clientCredentialsFlow(scopes, dets.tokenUrl, window.OAuthSchemeKey);
container.tokenName = dets.tokenName || 'access_token';
this.clientCredentialsFlow(scopes, dets.tokenUrl, container.OAuthSchemeKey);
return;
}
else if(auth.get('grantTypes')) {
@@ -22422,13 +22427,13 @@ SwaggerUi.Views.AuthView = Backbone.View.extend({
dets = o[t];
ep = dets.loginEndpoint.url;
url = dets.loginEndpoint.url + '?response_type=token';
window.swaggerUi.tokenName = dets.tokenName;
container.tokenName = dets.tokenName;
}
else if (o.hasOwnProperty(t) && t === 'accessCode') {
dets = o[t];
ep = dets.tokenRequestEndpoint.url;
url = dets.tokenRequestEndpoint.url + '?response_type=code';
window.swaggerUi.tokenName = dets.tokenName;
container.tokenName = dets.tokenName;
}
}
}
@@ -23075,9 +23080,9 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({
}
if (Array.isArray(this.model.security)) {
var authsModel = SwaggerUi.utils.parseSecurityDefinitions(this.model.security);
var authsModel = SwaggerUi.utils.parseSecurityDefinitions(this.model.security, this.model.parent.securityDefinitions);
authsModel.isLogout = !_.isEmpty(window.swaggerUi.api.clientAuthorizations.authz);
authsModel.isLogout = !_.isEmpty(this.model.clientAuthorizations.authz);
this.authView = new SwaggerUi.Views.AuthButtonView({
data: authsModel,
router: this.router,

File diff suppressed because one or more lines are too long

View File

@@ -11,7 +11,7 @@ var additionalQueryStringParams;
function handleLogin() {
var scopes = [];
var auths = window.swaggerUi.api.authSchemes || window.swaggerUi.api.securityDefinitions;
var auths = window.swaggerUiAuth.authSchemes || window.swaggerUiAuth.securityDefinitions;
if(auths) {
var key;
var defs = auths;
@@ -36,8 +36,7 @@ function handleLogin() {
}
}
if(window.swaggerUi.api
&& window.swaggerUi.api.info) {
if(window.swaggerUi.api && window.swaggerUi.api.info) {
appName = window.swaggerUi.api.info.title;
}
@@ -285,7 +284,7 @@ window.processOAuthCode = function processOAuthCode(data) {
});
};
window.onOAuthComplete = function onOAuthComplete(token,OAuthSchemeKey) {
window.onOAuthComplete = function onOAuthComplete(token, OAuthSchemeKey) {
if(token) {
if(token.error) {
var checkbox = $('input[type=checkbox],.secured')
@@ -295,7 +294,7 @@ window.onOAuthComplete = function onOAuthComplete(token,OAuthSchemeKey) {
alert(token.error);
}
else {
var b = token[window.swaggerUi.tokenName];
var b = token[window.swaggerUiAuth.tokenName];
if (!OAuthSchemeKey){
OAuthSchemeKey = token.state;
}
@@ -339,9 +338,11 @@ window.onOAuthComplete = function onOAuthComplete(token,OAuthSchemeKey) {
}
}
});
window.swaggerUi.api.clientAuthorizations.add(window.OAuthSchemeKey, new SwaggerClient.ApiKeyAuthorization('Authorization', 'Bearer ' + b, 'header'));
if(typeof window.swaggerUi !== 'undefined') {
window.swaggerUi.api.clientAuthorizations.add(window.swaggerUiAuth.OAuthSchemeKey, new SwaggerClient.ApiKeyAuthorization('Authorization', 'Bearer ' + b, 'header'));
window.swaggerUi.load();
}
}
}
}
};

View File

@@ -11,7 +11,7 @@ qp = qp ? JSON.parse('{"' + qp.replace(/&/g, '","').replace(/=/g,'":"') + '"}',
return key===""?value:decodeURIComponent(value) }
):{}
if (window.opener.swaggerUi.tokenUrl)
if (window.opener.swaggerUiAuth.tokenUrl)
window.opener.processOAuthCode(qp);
else
window.opener.onOAuthComplete(qp);

View File

@@ -1,8 +1,8 @@
'use strict';
window.SwaggerUi.utils = {
parseSecurityDefinitions: function (security) {
var auths = Object.assign({}, window.swaggerUi.api.authSchemes || window.swaggerUi.api.securityDefinitions);
parseSecurityDefinitions: function (security, securityDefinitions) {
var auths = Object.assign({}, securityDefinitions);
var oauth2Arr = [];
var authsArr = [];
var scopes = [];

View File

@@ -100,8 +100,9 @@ SwaggerUi.Views.AuthView = Backbone.View.extend({
var scopes = _.map(auth.get('scopes'), function (scope) {
return scope.scope;
});
var container = window.swaggerUiAuth || (window.swaggerUiAuth = {});
var state, dets, ep;
window.OAuthSchemeKey = auth.get('title');
container.OAuthSchemeKey = auth.get('title');
window.enabledScopes = scopes;
var flow = auth.get('flow');
@@ -109,14 +110,14 @@ SwaggerUi.Views.AuthView = Backbone.View.extend({
if(auth.get('type') === 'oauth2' && flow && (flow === 'implicit' || flow === 'accessCode')) {
dets = auth.attributes;
url = dets.authorizationUrl + '?response_type=' + (flow === 'implicit' ? 'token' : 'code');
window.swaggerUi.tokenName = dets.tokenName || 'access_token';
window.swaggerUi.tokenUrl = (flow === 'accessCode' ? dets.tokenUrl : null);
state = window.OAuthSchemeKey;
container.tokenName = dets.tokenName || 'access_token';
container.tokenUrl = (flow === 'accessCode' ? dets.tokenUrl : null);
state = container.OAuthSchemeKey;
}
else if(auth.get('type') === 'oauth2' && flow && (flow === 'application')) {
dets = auth.attributes;
window.swaggerUi.tokenName = dets.tokenName || 'access_token';
this.clientCredentialsFlow(scopes, dets.tokenUrl, window.OAuthSchemeKey);
container.tokenName = dets.tokenName || 'access_token';
this.clientCredentialsFlow(scopes, dets.tokenUrl, container.OAuthSchemeKey);
return;
}
else if(auth.get('grantTypes')) {
@@ -127,13 +128,13 @@ SwaggerUi.Views.AuthView = Backbone.View.extend({
dets = o[t];
ep = dets.loginEndpoint.url;
url = dets.loginEndpoint.url + '?response_type=token';
window.swaggerUi.tokenName = dets.tokenName;
container.tokenName = dets.tokenName;
}
else if (o.hasOwnProperty(t) && t === 'accessCode') {
dets = o[t];
ep = dets.tokenRequestEndpoint.url;
url = dets.tokenRequestEndpoint.url + '?response_type=code';
window.swaggerUi.tokenName = dets.tokenName;
container.tokenName = dets.tokenName;
}
}
}

View File

@@ -66,7 +66,11 @@ SwaggerUi.Collections.AuthsCollection = Backbone.Collection.extend({
},
parse: function (data) {
var authz = Object.assign({}, window.swaggerUi.api.clientAuthorizations.authz);
var authz = {};
if(typeof window.swaggerUi !== 'undefined') {
authz = Object.assign({}, window.swaggerUi.api.clientAuthorizations.authz);
}
return _.map(data, function (auth, name) {
var isBasic = authz[name] && auth.type === 'basic' && authz[name].username && authz[name].password;

View File

@@ -258,9 +258,9 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({
}
if (Array.isArray(this.model.security)) {
var authsModel = SwaggerUi.utils.parseSecurityDefinitions(this.model.security);
var authsModel = SwaggerUi.utils.parseSecurityDefinitions(this.model.security, this.model.parent.securityDefinitions);
authsModel.isLogout = !_.isEmpty(window.swaggerUi.api.clientAuthorizations.authz);
authsModel.isLogout = !_.isEmpty(this.model.clientAuthorizations.authz);
this.authView = new SwaggerUi.Views.AuthButtonView({
data: authsModel,
router: this.router,