updated to support explicit keys
This commit is contained in:
6
dist/index.html
vendored
6
dist/index.html
vendored
@@ -25,7 +25,7 @@
|
|||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$(function () {
|
$(function () {
|
||||||
window.swaggerUi = new SwaggerUi({
|
window.swaggerUi = new SwaggerUi({
|
||||||
url: "http://petstore.swagger.wordnik.com/api/api-docs",
|
url: "http://localhost:8002/api/api-docs",
|
||||||
dom_id: "swagger-ui-container",
|
dom_id: "swagger-ui-container",
|
||||||
supportedSubmitMethods: ['get', 'post', 'put', 'delete'],
|
supportedSubmitMethods: ['get', 'post', 'put', 'delete'],
|
||||||
onComplete: function(swaggerApi, swaggerUi){
|
onComplete: function(swaggerApi, swaggerUi){
|
||||||
@@ -55,9 +55,11 @@
|
|||||||
log("key: " + key);
|
log("key: " + key);
|
||||||
if(key && key.trim() != "") {
|
if(key && key.trim() != "") {
|
||||||
log("added key " + key);
|
log("added key " + key);
|
||||||
window.authorizations.add("key", new ApiKeyAuthorization("api_key", key, "query"));
|
window.authorizations.add("key", new ApiKeyAuthorization("api_key", key, "header"));
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
window.authorizations.add("key1", new ApiKeyAuthorization("key1", "the_key_1", "header"));
|
||||||
|
window.authorizations.add("key2", new ApiKeyAuthorization("key2", "the_key_2", "header"));
|
||||||
window.swaggerUi.load();
|
window.swaggerUi.load();
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
4
dist/lib/shred.bundle.js
vendored
4
dist/lib/shred.bundle.js
vendored
@@ -2131,10 +2131,12 @@ require.define("/shred/mixins/headers.js", function (require, module, exports, _
|
|||||||
// to `Content-Type`.
|
// to `Content-Type`.
|
||||||
|
|
||||||
var corsetCase = function(string) {
|
var corsetCase = function(string) {
|
||||||
return string.toLowerCase()
|
return string;
|
||||||
|
/* return string.toLowerCase()
|
||||||
//.replace("_","-")
|
//.replace("_","-")
|
||||||
.replace(/(^|-)(\w)/g,
|
.replace(/(^|-)(\w)/g,
|
||||||
function(s) { return s.toUpperCase(); });
|
function(s) { return s.toUpperCase(); });
|
||||||
|
*/
|
||||||
};
|
};
|
||||||
|
|
||||||
// We suspect that `initializeHeaders` was once more complicated ...
|
// We suspect that `initializeHeaders` was once more complicated ...
|
||||||
|
|||||||
28
dist/lib/swagger.js
vendored
28
dist/lib/swagger.js
vendored
@@ -432,6 +432,7 @@ SwaggerResource.prototype.addOperations = function(resource_path, ops, consumes,
|
|||||||
output = [];
|
output = [];
|
||||||
for (var i = 0; i < ops.length; i++) {
|
for (var i = 0; i < ops.length; i++) {
|
||||||
o = ops[i];
|
o = ops[i];
|
||||||
|
|
||||||
consumes = this.consumes;
|
consumes = this.consumes;
|
||||||
produces = this.produces;
|
produces = this.produces;
|
||||||
if (o.consumes != null)
|
if (o.consumes != null)
|
||||||
@@ -674,6 +675,7 @@ var SwaggerOperation = function(nickname, path, method, parameters, summary, not
|
|||||||
this.resource = (resource||errors.push("Resource is required"));
|
this.resource = (resource||errors.push("Resource is required"));
|
||||||
this.consumes = consumes;
|
this.consumes = consumes;
|
||||||
this.produces = produces;
|
this.produces = produces;
|
||||||
|
|
||||||
this.authorizations = authorizations;
|
this.authorizations = authorizations;
|
||||||
this["do"] = __bind(this["do"], this);
|
this["do"] = __bind(this["do"], this);
|
||||||
|
|
||||||
@@ -1203,7 +1205,7 @@ var SwaggerRequest = function(type, url, params, opts, successCallback, errorCal
|
|||||||
} else {
|
} else {
|
||||||
e = exports;
|
e = exports;
|
||||||
}
|
}
|
||||||
status = e.authorizations.apply(obj, this.operation.authorizations);
|
status = e.authorizations.apply(obj, this.operation);
|
||||||
if (opts.mock == null) {
|
if (opts.mock == null) {
|
||||||
if (status !== false) {
|
if (status !== false) {
|
||||||
new SwaggerHttp().execute(obj);
|
new SwaggerHttp().execute(obj);
|
||||||
@@ -1440,17 +1442,33 @@ SwaggerAuthorizations.prototype.remove = function(name) {
|
|||||||
return delete this.authz[name];
|
return delete this.authz[name];
|
||||||
};
|
};
|
||||||
|
|
||||||
SwaggerAuthorizations.prototype.apply = function(obj, authorizations) {
|
SwaggerAuthorizations.prototype.apply = function(obj, operation) {
|
||||||
status = null;
|
status = null;
|
||||||
var key;
|
var key;
|
||||||
for (key in this.authz) {
|
for (key in this.authz) {
|
||||||
|
var authorizations = (operation||{}).authorizations
|
||||||
|
var applyAuth = false;
|
||||||
|
if(operation) {
|
||||||
|
if(!operation.authorizations)
|
||||||
|
applyAuth = true;
|
||||||
|
else if(typeof authorizations[key] !== 'undefined')
|
||||||
|
applyAuth = true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
applyAuth = true;
|
||||||
|
}
|
||||||
|
|
||||||
value = this.authz[key];
|
value = this.authz[key];
|
||||||
|
if(applyAuth) {
|
||||||
|
console.log('applying auth ' + key);
|
||||||
result = value.apply(obj, authorizations);
|
result = value.apply(obj, authorizations);
|
||||||
if (result === false)
|
if (result === false)
|
||||||
status = false;
|
status = false;
|
||||||
if (result === true)
|
if (result === true)
|
||||||
status = true;
|
status = true;
|
||||||
}
|
}
|
||||||
|
else status = false;
|
||||||
|
}
|
||||||
return status;
|
return status;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1463,7 +1481,7 @@ var ApiKeyAuthorization = function(name, value, type) {
|
|||||||
this.type = type;
|
this.type = type;
|
||||||
};
|
};
|
||||||
|
|
||||||
ApiKeyAuthorization.prototype.apply = function(obj, authorizations) {
|
ApiKeyAuthorization.prototype.apply = function(obj, operation) {
|
||||||
if (this.type === "query") {
|
if (this.type === "query") {
|
||||||
if (obj.url.indexOf('?') > 0)
|
if (obj.url.indexOf('?') > 0)
|
||||||
obj.url = obj.url + "&" + this.name + "=" + this.value;
|
obj.url = obj.url + "&" + this.name + "=" + this.value;
|
||||||
@@ -1480,7 +1498,7 @@ var CookieAuthorization = function(cookie) {
|
|||||||
this.cookie = cookie;
|
this.cookie = cookie;
|
||||||
}
|
}
|
||||||
|
|
||||||
CookieAuthorization.prototype.apply = function(obj, authorizations) {
|
CookieAuthorization.prototype.apply = function(obj, operation) {
|
||||||
obj.cookieJar = obj.cookieJar || CookieJar();
|
obj.cookieJar = obj.cookieJar || CookieJar();
|
||||||
obj.cookieJar.setCookie(this.cookie);
|
obj.cookieJar.setCookie(this.cookie);
|
||||||
return true;
|
return true;
|
||||||
@@ -1500,7 +1518,7 @@ var PasswordAuthorization = function(name, username, password) {
|
|||||||
this._btoa = require("btoa");
|
this._btoa = require("btoa");
|
||||||
};
|
};
|
||||||
|
|
||||||
PasswordAuthorization.prototype.apply = function(obj, authorizations) {
|
PasswordAuthorization.prototype.apply = function(obj, operation) {
|
||||||
var base64encoder = this._btoa;
|
var base64encoder = this._btoa;
|
||||||
obj.headers["Authorization"] = "Basic " + base64encoder(this.username + ":" + this.password);
|
obj.headers["Authorization"] = "Basic " + base64encoder(this.username + ":" + this.password);
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>Swagger UI</title>
|
<title>Swagger UI</title>
|
||||||
<link href='https://fonts.googleapis.com/css?family=Droid+Sans:400,700' rel='stylesheet' type='text/css'/>
|
<link href='//fonts.googleapis.com/css?family=Droid+Sans:400,700' rel='stylesheet' type='text/css'/>
|
||||||
<link href='css/reset.css' media='screen' rel='stylesheet' type='text/css'/>
|
<link href='css/reset.css' media='screen' rel='stylesheet' type='text/css'/>
|
||||||
<link href='css/screen.css' media='screen' rel='stylesheet' type='text/css'/>
|
<link href='css/screen.css' media='screen' rel='stylesheet' type='text/css'/>
|
||||||
<link href='css/reset.css' media='print' rel='stylesheet' type='text/css'/>
|
<link href='css/reset.css' media='print' rel='stylesheet' type='text/css'/>
|
||||||
|
|||||||
Reference in New Issue
Block a user