Skip to content

Commit 011f709

Browse files
committed
fixed #340 with empty body, updated swagger-js
1 parent f0a0997 commit 011f709

File tree

6 files changed

+196
-131
lines changed

6 files changed

+196
-131
lines changed

dist/index.html

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html>
33
<head>
44
<title>Swagger UI</title>
5-
<link href='https://fonts.googleapis.com/css?family=Droid+Sans:400,700' rel='stylesheet' type='text/css'/>
5+
<link href='//fonts.googleapis.com/css?family=Droid+Sans:400,700' rel='stylesheet' type='text/css'/>
66
<link href='css/reset.css' media='screen' rel='stylesheet' type='text/css'/>
77
<link href='css/screen.css' media='screen' rel='stylesheet' type='text/css'/>
88
<link href='css/reset.css' media='print' rel='stylesheet' type='text/css'/>
@@ -25,7 +25,7 @@
2525
<script type="text/javascript">
2626
$(function () {
2727
window.swaggerUi = new SwaggerUi({
28-
url: "http://localhost:8002/api/api-docs",
28+
url: "http://petstore.swagger.wordnik.com/api/api-docs",
2929
dom_id: "swagger-ui-container",
3030
supportedSubmitMethods: ['get', 'post', 'put', 'delete'],
3131
onComplete: function(swaggerApi, swaggerUi){
@@ -55,11 +55,9 @@
5555
log("key: " + key);
5656
if(key && key.trim() != "") {
5757
log("added key " + key);
58-
window.authorizations.add("key", new ApiKeyAuthorization("api_key", key, "header"));
58+
window.authorizations.add("key", new ApiKeyAuthorization("api_key", key, "query"));
5959
}
6060
})
61-
window.authorizations.add("key1", new ApiKeyAuthorization("key1", "the_key_1", "header"));
62-
window.authorizations.add("key2", new ApiKeyAuthorization("key2", "the_key_2", "header"));
6361
window.swaggerUi.load();
6462
});
6563
</script>

dist/lib/shred.bundle.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2131,12 +2131,10 @@ require.define("/shred/mixins/headers.js", function (require, module, exports, _
21312131
// to `Content-Type`.
21322132

21332133
var corsetCase = function(string) {
2134-
return string;
2135-
/* return string.toLowerCase()
2134+
return string.toLowerCase()
21362135
//.replace("_","-")
21372136
.replace(/(^|-)(\w)/g,
21382137
function(s) { return s.toUpperCase(); });
2139-
*/
21402138
};
21412139

21422140
// We suspect that `initializeHeaders` was once more complicated ...

dist/lib/swagger-oauth.js

Lines changed: 60 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -48,65 +48,72 @@ function handleLogin() {
4848
str += '</label></li>';
4949
popup.append(str);
5050
}
51-
}
52-
53-
var $win = $(window),
54-
dw = $win.width(),
55-
dh = $win.height(),
56-
st = $win.scrollTop(),
57-
dlgWd = popupDialog.outerWidth(),
58-
dlgHt = popupDialog.outerHeight(),
59-
top = (dh -dlgHt)/2 + st,
60-
left = (dw - dlgWd)/2;
61-
62-
popupDialog.css({
63-
top: (top < 0? 0 : top) + 'px',
64-
left: (left < 0? 0 : left) + 'px'
65-
});
66-
67-
popupDialog.find('button.api-popup-cancel').click(function() {
68-
popupMask.hide();
69-
popupDialog.hide();
70-
});
71-
popupDialog.find('button.api-popup-authbtn').click(function() {
72-
popupMask.hide();
73-
popupDialog.hide();
74-
75-
var authSchemes = window.swaggerUi.api.authSchemes;
76-
var host = window.location;
77-
var redirectUrl = host.protocol + '//' + host.host + "/o2c.html";
78-
var url = null;
79-
80-
var p = window.swaggerUi.api.authSchemes;
81-
for (var key in p) {
82-
if (p.hasOwnProperty(key)) {
83-
var o = p[key].grantTypes;
84-
for(var t in o) {
85-
if(o.hasOwnProperty(t) && t === 'implicit') {
86-
var dets = o[t];
87-
url = dets.loginEndpoint.url + "?response_type=token";
88-
window.swaggerUi.tokenName = dets.tokenName;
51+
52+
53+
var $win = $(window),
54+
dw = $win.width(),
55+
dh = $win.height(),
56+
st = $win.scrollTop(),
57+
dlgWd = popupDialog.outerWidth(),
58+
dlgHt = popupDialog.outerHeight(),
59+
top = (dh -dlgHt)/2 + st,
60+
left = (dw - dlgWd)/2;
61+
62+
popupDialog.css({
63+
top: (top < 0? 0 : top) + 'px',
64+
left: (left < 0? 0 : left) + 'px'
65+
});
66+
67+
popupDialog.find('button.api-popup-cancel').click(function() {
68+
popupMask.hide();
69+
popupDialog.hide();
70+
});
71+
popupDialog.find('button.api-popup-authbtn').click(function() {
72+
popupMask.hide();
73+
popupDialog.hide();
74+
75+
var authSchemes = window.swaggerUi.api.authSchemes;
76+
var location = window.location;
77+
var locationUrl = location.protocol + '//' + location.host + location.pathname;
78+
var redirectUrl = locationUrl.replace("index.html","").concat("/o2c.html").replace("//o2c.html","/o2c.html");
79+
var url = null;
80+
81+
var p = window.swaggerUi.api.authSchemes;
82+
for (var key in p) {
83+
if (p.hasOwnProperty(key)) {
84+
var o = p[key].grantTypes;
85+
for(var t in o) {
86+
if(o.hasOwnProperty(t) && t === 'implicit') {
87+
var dets = o[t];
88+
url = dets.loginEndpoint.url + "?response_type=token";
89+
window.swaggerUi.tokenName = dets.tokenName;
90+
}
8991
}
9092
}
9193
}
92-
}
93-
var scopes = []
94-
var o = $('.api-popup-scopes').find('input:checked');
95-
96-
for(k =0; k < o.length; k++) {
97-
scopes.push($(o[k]).attr("scope"));
98-
}
99-
100-
window.enabledScopes=scopes;
94+
var scopes = [];
95+
var scopeForUrl='';
96+
var o = $('.api-popup-scopes').find('input:checked');
97+
98+
for(var k =0; k < o.length; k++) {
99+
scopes.push($(o[k]).attr("scope"));
100+
if(k > 0){
101+
scopeForUrl+=' ';
102+
}
103+
scopeForUrl+=$(o[k]).attr("scope");
104+
}
101105

102-
url += '&redirect_uri=' + encodeURIComponent(redirectUrl);
103-
url += '&realm=' + encodeURIComponent(realm);
104-
url += '&client_id=' + encodeURIComponent(clientId);
105-
url += '&scope=' + encodeURIComponent(scopes);
106+
window.enabledScopes=scopes;
107+
106108

107-
window.open(url);
108-
});
109+
url += '&redirect_uri=' + encodeURIComponent(redirectUrl);
110+
url += '&realm=' + encodeURIComponent(realm);
111+
url += '&client_id=' + encodeURIComponent(clientId);
112+
url += '&scope=' + encodeURIComponent(scopeForUrl);
109113

114+
window.open(url);
115+
});
116+
}
110117
popupMask.show();
111118
popupDialog.show();
112119
return;

dist/lib/swagger.js

Lines changed: 50 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// swagger.js
2-
// version 2.0.30
2+
// version 2.0.31
33

44
var __bind = function(fn, me){
55
return function(){
@@ -57,24 +57,24 @@ Object.keys = Object.keys || (function () {
5757
'constructor'
5858
],
5959
DontEnumsLength = DontEnums.length;
60-
60+
6161
return function (o) {
6262
if (typeof o != "object" && typeof o != "function" || o === null)
6363
throw new TypeError("Object.keys called on a non-object");
64-
64+
6565
var result = [];
6666
for (var name in o) {
6767
if (hasOwnProperty.call(o, name))
6868
result.push(name);
6969
}
70-
70+
7171
if (hasDontEnumBug) {
7272
for (var i = 0; i < DontEnumsLength; i++) {
7373
if (hasOwnProperty.call(o, DontEnums[i]))
7474
result.push(DontEnums[i]);
75-
}
75+
}
7676
}
77-
77+
7878
return result;
7979
};
8080
})();
@@ -87,6 +87,7 @@ var SwaggerApi = function(url, options) {
8787
this.authorizations = null;
8888
this.authorizationScheme = null;
8989
this.info = null;
90+
this.useJQuery = false;
9091

9192
options = (options||{});
9293
if (url)
@@ -103,6 +104,9 @@ var SwaggerApi = function(url, options) {
103104
if (options.success != null)
104105
this.success = options.success;
105106

107+
if (typeof options.useJQuery === 'boolean')
108+
this.useJQuery = options.useJQuery;
109+
106110
this.failure = options.failure != null ? options.failure : function() {};
107111
this.progress = options.progress != null ? options.progress : function() {};
108112
if (options.success != null)
@@ -432,7 +436,6 @@ SwaggerResource.prototype.addOperations = function(resource_path, ops, consumes,
432436
output = [];
433437
for (var i = 0; i < ops.length; i++) {
434438
o = ops[i];
435-
436439
consumes = this.consumes;
437440
produces = this.produces;
438441
if (o.consumes != null)
@@ -479,8 +482,7 @@ SwaggerResource.prototype.addOperations = function(resource_path, ops, consumes,
479482

480483
SwaggerResource.prototype.sanitize = function(nickname) {
481484
var op;
482-
op = nickname.replace(/[\s!@#$%^&*()_+=\[{\]};:<>|./?,\\'""-]/g, '_');
483-
//'
485+
op = nickname.replace(/[\s!@#$%^&*()_+=\[{\]};:<>|.\/?,\\'""-]/g, '_');
484486
op = op.replace(/((_){2,})/g, '_');
485487
op = op.replace(/^(_)*/g, '');
486488
op = op.replace(/([_])*$/g, '');
@@ -675,7 +677,6 @@ var SwaggerOperation = function(nickname, path, method, parameters, summary, not
675677
this.resource = (resource||errors.push("Resource is required"));
676678
this.consumes = consumes;
677679
this.produces = produces;
678-
679680
this.authorizations = authorizations;
680681
this["do"] = __bind(this["do"], this);
681682

@@ -814,7 +815,7 @@ SwaggerOperation.prototype.getSampleJSON = function(type, models) {
814815
else
815816
return JSON.stringify(val, null, 2);
816817
}
817-
else
818+
else
818819
return val;
819820
}
820821
};
@@ -1075,7 +1076,7 @@ SwaggerOperation.prototype.formatXml = function(xml) {
10751076
var SwaggerRequest = function(type, url, params, opts, successCallback, errorCallback, operation, execution) {
10761077
var _this = this;
10771078
var errors = [];
1078-
this.useJQuery = (typeof operation.useJQuery !== 'undefined' ? operation.useJQuery : null);
1079+
this.useJQuery = (typeof operation.resource.useJQuery !== 'undefined' ? operation.resource.useJQuery : null);
10791080
this.type = (type||errors.push("SwaggerRequest type is required (get/post/put/delete/patch/options)."));
10801081
this.url = (url||errors.push("SwaggerRequest url is required."));
10811082
this.params = params;
@@ -1123,6 +1124,8 @@ var SwaggerRequest = function(type, url, params, opts, successCallback, errorCal
11231124
else
11241125
requestContentType = "application/x-www-form-urlencoded";
11251126
}
1127+
else if (this.type == "DELETE")
1128+
body = "{}";
11261129
else if (this.type != "DELETE")
11271130
requestContentType = null;
11281131
}
@@ -1205,7 +1208,7 @@ var SwaggerRequest = function(type, url, params, opts, successCallback, errorCal
12051208
} else {
12061209
e = exports;
12071210
}
1208-
status = e.authorizations.apply(obj, this.operation);
1211+
status = e.authorizations.apply(obj, this.operation.authorizations);
12091212
if (opts.mock == null) {
12101213
if (status !== false) {
12111214
new SwaggerHttp().execute(obj);
@@ -1261,9 +1264,16 @@ SwaggerHttp.prototype.isIE8 = function() {
12611264
};
12621265

12631266
/*
1264-
* JQueryHttpClient lets a browser take advantage of JQuery's cross-browser magic
1267+
* JQueryHttpClient lets a browser take advantage of JQuery's cross-browser magic.
1268+
* NOTE: when jQuery is available it will export both '$' and 'jQuery' to the global space.
1269+
* Since we are using closures here we need to alias it for internal use.
12651270
*/
1266-
var JQueryHttpClient = function(options) {}
1271+
var JQueryHttpClient = function(options) {
1272+
"use strict";
1273+
if(!jQuery){
1274+
var jQuery = window.jQuery;
1275+
}
1276+
}
12671277

12681278
JQueryHttpClient.prototype.execute = function(obj) {
12691279
var cb = obj.on;
@@ -1336,9 +1346,9 @@ JQueryHttpClient.prototype.execute = function(obj) {
13361346
else
13371347
return cb.response(out);
13381348
};
1339-
1340-
$.support.cors = true;
1341-
return $.ajax(obj);
1349+
1350+
jQuery.support.cors = true;
1351+
return jQuery.ajax(obj);
13421352
}
13431353

13441354
/*
@@ -1453,33 +1463,32 @@ SwaggerAuthorizations.prototype.remove = function(name) {
14531463
return delete this.authz[name];
14541464
};
14551465

1456-
SwaggerAuthorizations.prototype.apply = function(obj, operation) {
1457-
status = null;
1466+
SwaggerAuthorizations.prototype.apply = function(obj, authorizations) {
1467+
var status = null;
14581468
var key;
1459-
for (key in this.authz) {
1460-
var authorizations = (operation||{}).authorizations
1461-
var applyAuth = false;
1462-
if(operation) {
1463-
if(!operation.authorizations)
1464-
applyAuth = true;
1465-
else if(typeof authorizations[key] !== 'undefined')
1466-
applyAuth = true;
1467-
}
1468-
else {
1469-
applyAuth = true;
1470-
}
14711469

1472-
value = this.authz[key];
1473-
if(applyAuth) {
1474-
console.log('applying auth ' + key);
1470+
if(typeof authorizations === 'undefined') {
1471+
// apply all keys since no authorizations hash is defined
1472+
for (key in this.authz) {
1473+
value = this.authz[key];
14751474
result = value.apply(obj, authorizations);
1476-
if (result === false)
1477-
status = false;
14781475
if (result === true)
14791476
status = true;
14801477
}
1481-
else status = false;
14821478
}
1479+
else {
1480+
for(name in authorizations) {
1481+
for (key in this.authz) {
1482+
if(key == name) {
1483+
value = this.authz[key];
1484+
result = value.apply(obj, authorizations);
1485+
if (result === true)
1486+
status = true;
1487+
}
1488+
}
1489+
}
1490+
}
1491+
14831492
return status;
14841493
};
14851494

@@ -1492,7 +1501,7 @@ var ApiKeyAuthorization = function(name, value, type) {
14921501
this.type = type;
14931502
};
14941503

1495-
ApiKeyAuthorization.prototype.apply = function(obj, operation) {
1504+
ApiKeyAuthorization.prototype.apply = function(obj, authorizations) {
14961505
if (this.type === "query") {
14971506
if (obj.url.indexOf('?') > 0)
14981507
obj.url = obj.url + "&" + this.name + "=" + this.value;
@@ -1509,7 +1518,7 @@ var CookieAuthorization = function(cookie) {
15091518
this.cookie = cookie;
15101519
}
15111520

1512-
CookieAuthorization.prototype.apply = function(obj, operation) {
1521+
CookieAuthorization.prototype.apply = function(obj, authorizations) {
15131522
obj.cookieJar = obj.cookieJar || CookieJar();
15141523
obj.cookieJar.setCookie(this.cookie);
15151524
return true;
@@ -1529,7 +1538,7 @@ var PasswordAuthorization = function(name, username, password) {
15291538
this._btoa = require("btoa");
15301539
};
15311540

1532-
PasswordAuthorization.prototype.apply = function(obj, operation) {
1541+
PasswordAuthorization.prototype.apply = function(obj, authorizations) {
15331542
var base64encoder = this._btoa;
15341543
obj.headers["Authorization"] = "Basic " + base64encoder(this.username + ":" + this.password);
15351544
return true;

0 commit comments

Comments
 (0)