Skip to content

Commit 2cd11ef

Browse files
authored
Merge pull request swagger-api#2506 from swagger-api/issue-2499
Remove globals, regression in v2.2.6
2 parents bf60526 + 81e897a commit 2cd11ef

File tree

10 files changed

+56
-44
lines changed

10 files changed

+56
-44
lines changed

dist/lib/swagger-oauth.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ var additionalQueryStringParams;
1111
function handleLogin() {
1212
var scopes = [];
1313

14-
var auths = window.swaggerUi.api.authSchemes || window.swaggerUi.api.securityDefinitions;
14+
var auths = window.swaggerUiAuth.authSchemes || window.swaggerUiAuth.securityDefinitions;
1515
if(auths) {
1616
var key;
1717
var defs = auths;
@@ -36,8 +36,7 @@ function handleLogin() {
3636
}
3737
}
3838

39-
if(window.swaggerUi.api
40-
&& window.swaggerUi.api.info) {
39+
if(window.swaggerUi.api && window.swaggerUi.api.info) {
4140
appName = window.swaggerUi.api.info.title;
4241
}
4342

@@ -285,7 +284,7 @@ window.processOAuthCode = function processOAuthCode(data) {
285284
});
286285
};
287286

288-
window.onOAuthComplete = function onOAuthComplete(token,OAuthSchemeKey) {
287+
window.onOAuthComplete = function onOAuthComplete(token, OAuthSchemeKey) {
289288
if(token) {
290289
if(token.error) {
291290
var checkbox = $('input[type=checkbox],.secured')
@@ -295,7 +294,7 @@ window.onOAuthComplete = function onOAuthComplete(token,OAuthSchemeKey) {
295294
alert(token.error);
296295
}
297296
else {
298-
var b = token[window.swaggerUi.tokenName];
297+
var b = token[window.swaggerUiAuth.tokenName];
299298
if (!OAuthSchemeKey){
300299
OAuthSchemeKey = token.state;
301300
}
@@ -339,8 +338,10 @@ window.onOAuthComplete = function onOAuthComplete(token,OAuthSchemeKey) {
339338
}
340339
}
341340
});
342-
window.swaggerUi.api.clientAuthorizations.add(window.OAuthSchemeKey, new SwaggerClient.ApiKeyAuthorization('Authorization', 'Bearer ' + b, 'header'));
343-
window.swaggerUi.load();
341+
if(typeof window.swaggerUi !== 'undefined') {
342+
window.swaggerUi.api.clientAuthorizations.add(window.swaggerUiAuth.OAuthSchemeKey, new SwaggerClient.ApiKeyAuthorization('Authorization', 'Bearer ' + b, 'header'));
343+
window.swaggerUi.load();
344+
}
344345
}
345346
}
346347
}

dist/o2c.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
return key===""?value:decodeURIComponent(value) }
1212
):{}
1313

14-
if (window.opener.swaggerUi.tokenUrl)
14+
if (window.opener.swaggerUiAuth.tokenUrl)
1515
window.opener.processOAuthCode(qp);
1616
else
1717
window.opener.onOAuthComplete(qp);

dist/swagger-ui.js

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21935,8 +21935,8 @@ window.SwaggerUi.utils = {};
2193521935
'use strict';
2193621936

2193721937
window.SwaggerUi.utils = {
21938-
parseSecurityDefinitions: function (security) {
21939-
var auths = Object.assign({}, window.swaggerUi.api.authSchemes || window.swaggerUi.api.securityDefinitions);
21938+
parseSecurityDefinitions: function (security, securityDefinitions) {
21939+
var auths = Object.assign({}, securityDefinitions);
2194021940
var oauth2Arr = [];
2194121941
var authsArr = [];
2194221942
var scopes = [];
@@ -22216,7 +22216,11 @@ SwaggerUi.Collections.AuthsCollection = Backbone.Collection.extend({
2221622216
},
2221722217

2221822218
parse: function (data) {
22219-
var authz = Object.assign({}, window.swaggerUi.api.clientAuthorizations.authz);
22219+
var authz = {};
22220+
22221+
if(typeof window.swaggerUi !== 'undefined') {
22222+
authz = Object.assign({}, window.swaggerUi.api.clientAuthorizations.authz);
22223+
}
2222022224

2222122225
return _.map(data, function (auth, name) {
2222222226
var isBasic = authz[name] && auth.type === 'basic' && authz[name].username && authz[name].password;
@@ -22395,23 +22399,24 @@ SwaggerUi.Views.AuthView = Backbone.View.extend({
2239522399
var scopes = _.map(auth.get('scopes'), function (scope) {
2239622400
return scope.scope;
2239722401
});
22402+
var container = window.swaggerUiAuth || (window.swaggerUiAuth = {});
2239822403
var state, dets, ep;
22399-
window.OAuthSchemeKey = auth.get('title');
22404+
container.OAuthSchemeKey = auth.get('title');
2240022405

2240122406
window.enabledScopes = scopes;
2240222407
var flow = auth.get('flow');
2240322408

2240422409
if(auth.get('type') === 'oauth2' && flow && (flow === 'implicit' || flow === 'accessCode')) {
2240522410
dets = auth.attributes;
2240622411
url = dets.authorizationUrl + '?response_type=' + (flow === 'implicit' ? 'token' : 'code');
22407-
window.swaggerUi.tokenName = dets.tokenName || 'access_token';
22408-
window.swaggerUi.tokenUrl = (flow === 'accessCode' ? dets.tokenUrl : null);
22409-
state = window.OAuthSchemeKey;
22412+
container.tokenName = dets.tokenName || 'access_token';
22413+
container.tokenUrl = (flow === 'accessCode' ? dets.tokenUrl : null);
22414+
state = container.OAuthSchemeKey;
2241022415
}
2241122416
else if(auth.get('type') === 'oauth2' && flow && (flow === 'application')) {
2241222417
dets = auth.attributes;
22413-
window.swaggerUi.tokenName = dets.tokenName || 'access_token';
22414-
this.clientCredentialsFlow(scopes, dets.tokenUrl, window.OAuthSchemeKey);
22418+
container.tokenName = dets.tokenName || 'access_token';
22419+
this.clientCredentialsFlow(scopes, dets.tokenUrl, container.OAuthSchemeKey);
2241522420
return;
2241622421
}
2241722422
else if(auth.get('grantTypes')) {
@@ -22422,13 +22427,13 @@ SwaggerUi.Views.AuthView = Backbone.View.extend({
2242222427
dets = o[t];
2242322428
ep = dets.loginEndpoint.url;
2242422429
url = dets.loginEndpoint.url + '?response_type=token';
22425-
window.swaggerUi.tokenName = dets.tokenName;
22430+
container.tokenName = dets.tokenName;
2242622431
}
2242722432
else if (o.hasOwnProperty(t) && t === 'accessCode') {
2242822433
dets = o[t];
2242922434
ep = dets.tokenRequestEndpoint.url;
2243022435
url = dets.tokenRequestEndpoint.url + '?response_type=code';
22431-
window.swaggerUi.tokenName = dets.tokenName;
22436+
container.tokenName = dets.tokenName;
2243222437
}
2243322438
}
2243422439
}
@@ -23075,9 +23080,9 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({
2307523080
}
2307623081

2307723082
if (Array.isArray(this.model.security)) {
23078-
var authsModel = SwaggerUi.utils.parseSecurityDefinitions(this.model.security);
23083+
var authsModel = SwaggerUi.utils.parseSecurityDefinitions(this.model.security, this.model.parent.securityDefinitions);
2307923084

23080-
authsModel.isLogout = !_.isEmpty(window.swaggerUi.api.clientAuthorizations.authz);
23085+
authsModel.isLogout = !_.isEmpty(this.model.clientAuthorizations.authz);
2308123086
this.authView = new SwaggerUi.Views.AuthButtonView({
2308223087
data: authsModel,
2308323088
router: this.router,

dist/swagger-ui.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/swagger-oauth.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ var additionalQueryStringParams;
1111
function handleLogin() {
1212
var scopes = [];
1313

14-
var auths = window.swaggerUi.api.authSchemes || window.swaggerUi.api.securityDefinitions;
14+
var auths = window.swaggerUiAuth.authSchemes || window.swaggerUiAuth.securityDefinitions;
1515
if(auths) {
1616
var key;
1717
var defs = auths;
@@ -36,8 +36,7 @@ function handleLogin() {
3636
}
3737
}
3838

39-
if(window.swaggerUi.api
40-
&& window.swaggerUi.api.info) {
39+
if(window.swaggerUi.api && window.swaggerUi.api.info) {
4140
appName = window.swaggerUi.api.info.title;
4241
}
4342

@@ -285,7 +284,7 @@ window.processOAuthCode = function processOAuthCode(data) {
285284
});
286285
};
287286

288-
window.onOAuthComplete = function onOAuthComplete(token,OAuthSchemeKey) {
287+
window.onOAuthComplete = function onOAuthComplete(token, OAuthSchemeKey) {
289288
if(token) {
290289
if(token.error) {
291290
var checkbox = $('input[type=checkbox],.secured')
@@ -295,7 +294,7 @@ window.onOAuthComplete = function onOAuthComplete(token,OAuthSchemeKey) {
295294
alert(token.error);
296295
}
297296
else {
298-
var b = token[window.swaggerUi.tokenName];
297+
var b = token[window.swaggerUiAuth.tokenName];
299298
if (!OAuthSchemeKey){
300299
OAuthSchemeKey = token.state;
301300
}
@@ -339,8 +338,10 @@ window.onOAuthComplete = function onOAuthComplete(token,OAuthSchemeKey) {
339338
}
340339
}
341340
});
342-
window.swaggerUi.api.clientAuthorizations.add(window.OAuthSchemeKey, new SwaggerClient.ApiKeyAuthorization('Authorization', 'Bearer ' + b, 'header'));
343-
window.swaggerUi.load();
341+
if(typeof window.swaggerUi !== 'undefined') {
342+
window.swaggerUi.api.clientAuthorizations.add(window.swaggerUiAuth.OAuthSchemeKey, new SwaggerClient.ApiKeyAuthorization('Authorization', 'Bearer ' + b, 'header'));
343+
window.swaggerUi.load();
344+
}
344345
}
345346
}
346347
}

src/main/html/o2c.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
return key===""?value:decodeURIComponent(value) }
1212
):{}
1313

14-
if (window.opener.swaggerUi.tokenUrl)
14+
if (window.opener.swaggerUiAuth.tokenUrl)
1515
window.opener.processOAuthCode(qp);
1616
else
1717
window.opener.onOAuthComplete(qp);

src/main/javascript/utils/utils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
'use strict';
22

33
window.SwaggerUi.utils = {
4-
parseSecurityDefinitions: function (security) {
5-
var auths = Object.assign({}, window.swaggerUi.api.authSchemes || window.swaggerUi.api.securityDefinitions);
4+
parseSecurityDefinitions: function (security, securityDefinitions) {
5+
var auths = Object.assign({}, securityDefinitions);
66
var oauth2Arr = [];
77
var authsArr = [];
88
var scopes = [];

src/main/javascript/view/AuthView.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,23 +100,24 @@ SwaggerUi.Views.AuthView = Backbone.View.extend({
100100
var scopes = _.map(auth.get('scopes'), function (scope) {
101101
return scope.scope;
102102
});
103+
var container = window.swaggerUiAuth || (window.swaggerUiAuth = {});
103104
var state, dets, ep;
104-
window.OAuthSchemeKey = auth.get('title');
105+
container.OAuthSchemeKey = auth.get('title');
105106

106107
window.enabledScopes = scopes;
107108
var flow = auth.get('flow');
108109

109110
if(auth.get('type') === 'oauth2' && flow && (flow === 'implicit' || flow === 'accessCode')) {
110111
dets = auth.attributes;
111112
url = dets.authorizationUrl + '?response_type=' + (flow === 'implicit' ? 'token' : 'code');
112-
window.swaggerUi.tokenName = dets.tokenName || 'access_token';
113-
window.swaggerUi.tokenUrl = (flow === 'accessCode' ? dets.tokenUrl : null);
114-
state = window.OAuthSchemeKey;
113+
container.tokenName = dets.tokenName || 'access_token';
114+
container.tokenUrl = (flow === 'accessCode' ? dets.tokenUrl : null);
115+
state = container.OAuthSchemeKey;
115116
}
116117
else if(auth.get('type') === 'oauth2' && flow && (flow === 'application')) {
117118
dets = auth.attributes;
118-
window.swaggerUi.tokenName = dets.tokenName || 'access_token';
119-
this.clientCredentialsFlow(scopes, dets.tokenUrl, window.OAuthSchemeKey);
119+
container.tokenName = dets.tokenName || 'access_token';
120+
this.clientCredentialsFlow(scopes, dets.tokenUrl, container.OAuthSchemeKey);
120121
return;
121122
}
122123
else if(auth.get('grantTypes')) {
@@ -127,13 +128,13 @@ SwaggerUi.Views.AuthView = Backbone.View.extend({
127128
dets = o[t];
128129
ep = dets.loginEndpoint.url;
129130
url = dets.loginEndpoint.url + '?response_type=token';
130-
window.swaggerUi.tokenName = dets.tokenName;
131+
container.tokenName = dets.tokenName;
131132
}
132133
else if (o.hasOwnProperty(t) && t === 'accessCode') {
133134
dets = o[t];
134135
ep = dets.tokenRequestEndpoint.url;
135136
url = dets.tokenRequestEndpoint.url + '?response_type=code';
136-
window.swaggerUi.tokenName = dets.tokenName;
137+
container.tokenName = dets.tokenName;
137138
}
138139
}
139140
}

src/main/javascript/view/AuthsCollection.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,11 @@ SwaggerUi.Collections.AuthsCollection = Backbone.Collection.extend({
6666
},
6767

6868
parse: function (data) {
69-
var authz = Object.assign({}, window.swaggerUi.api.clientAuthorizations.authz);
69+
var authz = {};
70+
71+
if(typeof window.swaggerUi !== 'undefined') {
72+
authz = Object.assign({}, window.swaggerUi.api.clientAuthorizations.authz);
73+
}
7074

7175
return _.map(data, function (auth, name) {
7276
var isBasic = authz[name] && auth.type === 'basic' && authz[name].username && authz[name].password;

src/main/javascript/view/OperationView.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,9 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({
258258
}
259259

260260
if (Array.isArray(this.model.security)) {
261-
var authsModel = SwaggerUi.utils.parseSecurityDefinitions(this.model.security);
261+
var authsModel = SwaggerUi.utils.parseSecurityDefinitions(this.model.security, this.model.parent.securityDefinitions);
262262

263-
authsModel.isLogout = !_.isEmpty(window.swaggerUi.api.clientAuthorizations.authz);
263+
authsModel.isLogout = !_.isEmpty(this.model.clientAuthorizations.authz);
264264
this.authView = new SwaggerUi.Views.AuthButtonView({
265265
data: authsModel,
266266
router: this.router,

0 commit comments

Comments
 (0)