Skip to content

Commit b8e4317

Browse files
committed
updated to support explicit keys
1 parent c2dd77f commit b8e4317

File tree

4 files changed

+36
-14
lines changed

4 files changed

+36
-14
lines changed

dist/index.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<script type="text/javascript">
2626
$(function () {
2727
window.swaggerUi = new SwaggerUi({
28-
url: "http://petstore.swagger.wordnik.com/api/api-docs",
28+
url: "http://localhost:8002/api/api-docs",
2929
dom_id: "swagger-ui-container",
3030
supportedSubmitMethods: ['get', 'post', 'put', 'delete'],
3131
onComplete: function(swaggerApi, swaggerUi){
@@ -55,9 +55,11 @@
5555
log("key: " + key);
5656
if(key && key.trim() != "") {
5757
log("added key " + key);
58-
window.authorizations.add("key", new ApiKeyAuthorization("api_key", key, "query"));
58+
window.authorizations.add("key", new ApiKeyAuthorization("api_key", key, "header"));
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"));
6163
window.swaggerUi.load();
6264
});
6365
</script>

dist/lib/shred.bundle.js

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

21332133
var corsetCase = function(string) {
2134-
return string.toLowerCase()
2134+
return string;
2135+
/* return string.toLowerCase()
21352136
//.replace("_","-")
21362137
.replace(/(^|-)(\w)/g,
21372138
function(s) { return s.toUpperCase(); });
2139+
*/
21382140
};
21392141

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

dist/lib/swagger.js

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ SwaggerResource.prototype.addOperations = function(resource_path, ops, consumes,
432432
output = [];
433433
for (var i = 0; i < ops.length; i++) {
434434
o = ops[i];
435+
435436
consumes = this.consumes;
436437
produces = this.produces;
437438
if (o.consumes != null)
@@ -674,6 +675,7 @@ var SwaggerOperation = function(nickname, path, method, parameters, summary, not
674675
this.resource = (resource||errors.push("Resource is required"));
675676
this.consumes = consumes;
676677
this.produces = produces;
678+
677679
this.authorizations = authorizations;
678680
this["do"] = __bind(this["do"], this);
679681

@@ -1203,7 +1205,7 @@ var SwaggerRequest = function(type, url, params, opts, successCallback, errorCal
12031205
} else {
12041206
e = exports;
12051207
}
1206-
status = e.authorizations.apply(obj, this.operation.authorizations);
1208+
status = e.authorizations.apply(obj, this.operation);
12071209
if (opts.mock == null) {
12081210
if (status !== false) {
12091211
new SwaggerHttp().execute(obj);
@@ -1440,16 +1442,32 @@ SwaggerAuthorizations.prototype.remove = function(name) {
14401442
return delete this.authz[name];
14411443
};
14421444

1443-
SwaggerAuthorizations.prototype.apply = function(obj, authorizations) {
1445+
SwaggerAuthorizations.prototype.apply = function(obj, operation) {
14441446
status = null;
14451447
var key;
14461448
for (key in this.authz) {
1449+
var authorizations = (operation||{}).authorizations
1450+
var applyAuth = false;
1451+
if(operation) {
1452+
if(!operation.authorizations)
1453+
applyAuth = true;
1454+
else if(typeof authorizations[key] !== 'undefined')
1455+
applyAuth = true;
1456+
}
1457+
else {
1458+
applyAuth = true;
1459+
}
1460+
14471461
value = this.authz[key];
1448-
result = value.apply(obj, authorizations);
1449-
if (result === false)
1450-
status = false;
1451-
if (result === true)
1452-
status = true;
1462+
if(applyAuth) {
1463+
console.log('applying auth ' + key);
1464+
result = value.apply(obj, authorizations);
1465+
if (result === false)
1466+
status = false;
1467+
if (result === true)
1468+
status = true;
1469+
}
1470+
else status = false;
14531471
}
14541472
return status;
14551473
};
@@ -1463,7 +1481,7 @@ var ApiKeyAuthorization = function(name, value, type) {
14631481
this.type = type;
14641482
};
14651483

1466-
ApiKeyAuthorization.prototype.apply = function(obj, authorizations) {
1484+
ApiKeyAuthorization.prototype.apply = function(obj, operation) {
14671485
if (this.type === "query") {
14681486
if (obj.url.indexOf('?') > 0)
14691487
obj.url = obj.url + "&" + this.name + "=" + this.value;
@@ -1480,7 +1498,7 @@ var CookieAuthorization = function(cookie) {
14801498
this.cookie = cookie;
14811499
}
14821500

1483-
CookieAuthorization.prototype.apply = function(obj, authorizations) {
1501+
CookieAuthorization.prototype.apply = function(obj, operation) {
14841502
obj.cookieJar = obj.cookieJar || CookieJar();
14851503
obj.cookieJar.setCookie(this.cookie);
14861504
return true;
@@ -1500,7 +1518,7 @@ var PasswordAuthorization = function(name, username, password) {
15001518
this._btoa = require("btoa");
15011519
};
15021520

1503-
PasswordAuthorization.prototype.apply = function(obj, authorizations) {
1521+
PasswordAuthorization.prototype.apply = function(obj, operation) {
15041522
var base64encoder = this._btoa;
15051523
obj.headers["Authorization"] = "Basic " + base64encoder(this.username + ":" + this.password);
15061524
return true;

src/main/html/index.html

Lines changed: 1 addition & 1 deletion
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'/>

0 commit comments

Comments
 (0)