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">
|
||||
$(function () {
|
||||
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",
|
||||
supportedSubmitMethods: ['get', 'post', 'put', 'delete'],
|
||||
onComplete: function(swaggerApi, swaggerUi){
|
||||
@@ -55,9 +55,11 @@
|
||||
log("key: " + key);
|
||||
if(key && key.trim() != "") {
|
||||
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();
|
||||
});
|
||||
</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`.
|
||||
|
||||
var corsetCase = function(string) {
|
||||
return string.toLowerCase()
|
||||
return string;
|
||||
/* return string.toLowerCase()
|
||||
//.replace("_","-")
|
||||
.replace(/(^|-)(\w)/g,
|
||||
function(s) { return s.toUpperCase(); });
|
||||
*/
|
||||
};
|
||||
|
||||
// We suspect that `initializeHeaders` was once more complicated ...
|
||||
|
||||
38
dist/lib/swagger.js
vendored
38
dist/lib/swagger.js
vendored
@@ -432,6 +432,7 @@ SwaggerResource.prototype.addOperations = function(resource_path, ops, consumes,
|
||||
output = [];
|
||||
for (var i = 0; i < ops.length; i++) {
|
||||
o = ops[i];
|
||||
|
||||
consumes = this.consumes;
|
||||
produces = this.produces;
|
||||
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.consumes = consumes;
|
||||
this.produces = produces;
|
||||
|
||||
this.authorizations = authorizations;
|
||||
this["do"] = __bind(this["do"], this);
|
||||
|
||||
@@ -1203,7 +1205,7 @@ var SwaggerRequest = function(type, url, params, opts, successCallback, errorCal
|
||||
} else {
|
||||
e = exports;
|
||||
}
|
||||
status = e.authorizations.apply(obj, this.operation.authorizations);
|
||||
status = e.authorizations.apply(obj, this.operation);
|
||||
if (opts.mock == null) {
|
||||
if (status !== false) {
|
||||
new SwaggerHttp().execute(obj);
|
||||
@@ -1440,16 +1442,32 @@ SwaggerAuthorizations.prototype.remove = function(name) {
|
||||
return delete this.authz[name];
|
||||
};
|
||||
|
||||
SwaggerAuthorizations.prototype.apply = function(obj, authorizations) {
|
||||
SwaggerAuthorizations.prototype.apply = function(obj, operation) {
|
||||
status = null;
|
||||
var key;
|
||||
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];
|
||||
result = value.apply(obj, authorizations);
|
||||
if (result === false)
|
||||
status = false;
|
||||
if (result === true)
|
||||
status = true;
|
||||
if(applyAuth) {
|
||||
console.log('applying auth ' + key);
|
||||
result = value.apply(obj, authorizations);
|
||||
if (result === false)
|
||||
status = false;
|
||||
if (result === true)
|
||||
status = true;
|
||||
}
|
||||
else status = false;
|
||||
}
|
||||
return status;
|
||||
};
|
||||
@@ -1463,7 +1481,7 @@ var ApiKeyAuthorization = function(name, value, type) {
|
||||
this.type = type;
|
||||
};
|
||||
|
||||
ApiKeyAuthorization.prototype.apply = function(obj, authorizations) {
|
||||
ApiKeyAuthorization.prototype.apply = function(obj, operation) {
|
||||
if (this.type === "query") {
|
||||
if (obj.url.indexOf('?') > 0)
|
||||
obj.url = obj.url + "&" + this.name + "=" + this.value;
|
||||
@@ -1480,7 +1498,7 @@ var CookieAuthorization = function(cookie) {
|
||||
this.cookie = cookie;
|
||||
}
|
||||
|
||||
CookieAuthorization.prototype.apply = function(obj, authorizations) {
|
||||
CookieAuthorization.prototype.apply = function(obj, operation) {
|
||||
obj.cookieJar = obj.cookieJar || CookieJar();
|
||||
obj.cookieJar.setCookie(this.cookie);
|
||||
return true;
|
||||
@@ -1500,7 +1518,7 @@ var PasswordAuthorization = function(name, username, password) {
|
||||
this._btoa = require("btoa");
|
||||
};
|
||||
|
||||
PasswordAuthorization.prototype.apply = function(obj, authorizations) {
|
||||
PasswordAuthorization.prototype.apply = function(obj, operation) {
|
||||
var base64encoder = this._btoa;
|
||||
obj.headers["Authorization"] = "Basic " + base64encoder(this.username + ":" + this.password);
|
||||
return true;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<html>
|
||||
<head>
|
||||
<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/screen.css' media='screen' rel='stylesheet' type='text/css'/>
|
||||
<link href='css/reset.css' media='print' rel='stylesheet' type='text/css'/>
|
||||
|
||||
Reference in New Issue
Block a user