updated oauth2 support into a single config
This commit is contained in:
14
dist/index.html
vendored
14
dist/index.html
vendored
@@ -17,12 +17,9 @@
|
||||
<script src='swagger-ui.js' type='text/javascript'></script>
|
||||
<script src='lib/highlight.7.3.pack.js' type='text/javascript'></script>
|
||||
|
||||
<!--script src='lib/swagger-oauth.js' type='text/javascript'></script-->
|
||||
<script src='lib/swagger-oauth.js' type='text/javascript'></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
// var clientId = "your-client-id";
|
||||
// var realm = "your-realm";
|
||||
|
||||
$(function () {
|
||||
window.swaggerUi = new SwaggerUi({
|
||||
url: "http://petstore.swagger.wordnik.com/api/api-docs",
|
||||
@@ -30,9 +27,12 @@
|
||||
supportedSubmitMethods: ['get', 'post', 'put', 'delete'],
|
||||
onComplete: function(swaggerApi, swaggerUi){
|
||||
log("Loaded SwaggerUI");
|
||||
/*if(typeof initOAuth == "function")
|
||||
initOAuth();
|
||||
*/
|
||||
|
||||
if(typeof initOAuth == "function")
|
||||
initOAuth({
|
||||
clientId: "me",
|
||||
realm: "realms"
|
||||
});
|
||||
$('pre code').each(function(i, e) {hljs.highlightBlock(e)});
|
||||
},
|
||||
onFailure: function(data) {
|
||||
|
||||
26
dist/lib/swagger-oauth.js
vendored
26
dist/lib/swagger-oauth.js
vendored
@@ -1,10 +1,10 @@
|
||||
function handleLogin() {
|
||||
var scopes = [];
|
||||
var appName = "unknown-app";
|
||||
var popupMask = $('#api-common-mask');
|
||||
var popupDialog = $('.api-popup-dialog');
|
||||
var clientId = "your-client-id";
|
||||
var realm = "your-realm";
|
||||
var appName;
|
||||
var popupMask;
|
||||
var popupDialog;
|
||||
var clientId;
|
||||
var realm;
|
||||
|
||||
if(window.swaggerUi.api.authSchemes
|
||||
&& window.swaggerUi.api.authSchemes.oauth2
|
||||
@@ -124,7 +124,21 @@ function handleLogout() {
|
||||
$('.api-ic.ic-warning').removeClass('ic-warning');
|
||||
}
|
||||
|
||||
function initOAuth() {
|
||||
function initOAuth(opts) {
|
||||
var o = (opts||{});
|
||||
var errors = [];
|
||||
|
||||
appName = (o.appName||errors.push("missing appName"));
|
||||
popupMask = (o.popupMask||$('#api-common-mask'));
|
||||
popupDialog = (o.popupDialog||$('.api-popup-dialog'));
|
||||
clientId = (o.clientId||errors.push("missing client id"));
|
||||
realm = (o.realm||errors.push("missing realm"));
|
||||
|
||||
if(errors.length > 0){
|
||||
log("auth unable initialize oauth: " + errors);
|
||||
return;
|
||||
}
|
||||
|
||||
$('pre code').each(function(i, e) {hljs.highlightBlock(e)});
|
||||
$('.api-ic').click(function(s) {
|
||||
if($(s.target).hasClass('ic-off'))
|
||||
|
||||
19
dist/lib/swagger.js
vendored
19
dist/lib/swagger.js
vendored
@@ -1,5 +1,5 @@
|
||||
// swagger.js
|
||||
// version 2.0.26
|
||||
// version 2.0.27
|
||||
|
||||
var __bind = function(fn, me){
|
||||
return function(){
|
||||
@@ -882,6 +882,21 @@ SwaggerOperation.prototype.pathXml = function() {
|
||||
return this.path.replace("{format}", "xml");
|
||||
};
|
||||
|
||||
SwaggerOperation.prototype.encodePathParam = function(pathParam) {
|
||||
var encParts, part, parts, _i, _len;
|
||||
if (pathParam.indexOf("/") === -1) {
|
||||
return encodeURIComponent(pathParam);
|
||||
} else {
|
||||
parts = pathParam.split("/");
|
||||
encParts = [];
|
||||
for (_i = 0, _len = parts.length; _i < _len; _i++) {
|
||||
part = parts[_i];
|
||||
encParts.push(encodeURIComponent(part));
|
||||
}
|
||||
return encParts.join("/");
|
||||
}
|
||||
};
|
||||
|
||||
SwaggerOperation.prototype.urlify = function(args) {
|
||||
var url = this.resource.basePath + this.pathJson();
|
||||
var params = this.parameters;
|
||||
@@ -891,7 +906,7 @@ SwaggerOperation.prototype.urlify = function(args) {
|
||||
if(args[param.name]) {
|
||||
// apply path params and remove from args
|
||||
var reg = new RegExp('\{' + param.name + '[^\}]*\}', 'gi');
|
||||
url = url.replace(reg, encodeURIComponent(args[param.name]));
|
||||
url = url.replace(reg, this.encodePathParam(args[param.name]));
|
||||
delete args[param.name];
|
||||
}
|
||||
else
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
var appName;
|
||||
var popupMask;
|
||||
var popupDialog;
|
||||
var clientId;
|
||||
var realm;
|
||||
|
||||
function handleLogin() {
|
||||
var scopes = [];
|
||||
var appName = "unknown-app";
|
||||
var popupMask = $('#api-common-mask');
|
||||
var popupDialog = $('.api-popup-dialog');
|
||||
var clientId = "your-client-id";
|
||||
var realm = "your-realm";
|
||||
|
||||
if(window.swaggerUi.api.authSchemes
|
||||
&& window.swaggerUi.api.authSchemes.oauth2
|
||||
@@ -17,7 +18,8 @@ function handleLogin() {
|
||||
appName = window.swaggerUi.api.info.title;
|
||||
}
|
||||
|
||||
if(popupDialog.length > 0) popupDialog = popupDialog.last();
|
||||
if(popupDialog.length > 0)
|
||||
popupDialog = popupDialog.last();
|
||||
else {
|
||||
popupDialog = $(
|
||||
[
|
||||
@@ -124,7 +126,21 @@ function handleLogout() {
|
||||
$('.api-ic.ic-warning').removeClass('ic-warning');
|
||||
}
|
||||
|
||||
function initOAuth() {
|
||||
function initOAuth(opts) {
|
||||
var o = (opts||{});
|
||||
var errors = [];
|
||||
|
||||
appName = (o.appName||errors.push("missing appName"));
|
||||
popupMask = (o.popupMask||$('#api-common-mask'));
|
||||
popupDialog = (o.popupDialog||$('.api-popup-dialog'));
|
||||
clientId = (o.clientId||errors.push("missing client id"));
|
||||
realm = (o.realm||errors.push("missing realm"));
|
||||
|
||||
if(errors.length > 0){
|
||||
log("auth unable initialize oauth: " + errors);
|
||||
return;
|
||||
}
|
||||
|
||||
$('pre code').each(function(i, e) {hljs.highlightBlock(e)});
|
||||
$('.api-ic').click(function(s) {
|
||||
if($(s.target).hasClass('ic-off'))
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// swagger.js
|
||||
// version 2.0.26
|
||||
// version 2.0.27
|
||||
|
||||
var __bind = function(fn, me){
|
||||
return function(){
|
||||
@@ -882,6 +882,21 @@ SwaggerOperation.prototype.pathXml = function() {
|
||||
return this.path.replace("{format}", "xml");
|
||||
};
|
||||
|
||||
SwaggerOperation.prototype.encodePathParam = function(pathParam) {
|
||||
var encParts, part, parts, _i, _len;
|
||||
if (pathParam.indexOf("/") === -1) {
|
||||
return encodeURIComponent(pathParam);
|
||||
} else {
|
||||
parts = pathParam.split("/");
|
||||
encParts = [];
|
||||
for (_i = 0, _len = parts.length; _i < _len; _i++) {
|
||||
part = parts[_i];
|
||||
encParts.push(encodeURIComponent(part));
|
||||
}
|
||||
return encParts.join("/");
|
||||
}
|
||||
};
|
||||
|
||||
SwaggerOperation.prototype.urlify = function(args) {
|
||||
var url = this.resource.basePath + this.pathJson();
|
||||
var params = this.parameters;
|
||||
@@ -891,7 +906,7 @@ SwaggerOperation.prototype.urlify = function(args) {
|
||||
if(args[param.name]) {
|
||||
// apply path params and remove from args
|
||||
var reg = new RegExp('\{' + param.name + '[^\}]*\}', 'gi');
|
||||
url = url.replace(reg, encodeURIComponent(args[param.name]));
|
||||
url = url.replace(reg, this.encodePathParam(args[param.name]));
|
||||
delete args[param.name];
|
||||
}
|
||||
else
|
||||
|
||||
@@ -17,12 +17,10 @@
|
||||
<script src='swagger-ui.js' type='text/javascript'></script>
|
||||
<script src='lib/highlight.7.3.pack.js' type='text/javascript'></script>
|
||||
|
||||
<!--script src='lib/swagger-oauth.js' type='text/javascript'></script-->
|
||||
<!-- enabling this will enable oauth2 implicit scope support -->
|
||||
<script src='lib/swagger-oauth.js' type='text/javascript'></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
// var clientId = "your-client-id";
|
||||
// var realm = "your-realm";
|
||||
|
||||
$(function () {
|
||||
window.swaggerUi = new SwaggerUi({
|
||||
url: "http://petstore.swagger.wordnik.com/api/api-docs",
|
||||
@@ -30,10 +28,19 @@
|
||||
supportedSubmitMethods: ['get', 'post', 'put', 'delete'],
|
||||
onComplete: function(swaggerApi, swaggerUi){
|
||||
log("Loaded SwaggerUI");
|
||||
/*if(typeof initOAuth == "function")
|
||||
initOAuth();
|
||||
*/
|
||||
$('pre code').each(function(i, e) {hljs.highlightBlock(e)});
|
||||
|
||||
if(typeof initOAuth == "function") {
|
||||
/*
|
||||
initOAuth({
|
||||
clientId: "your-client-id",
|
||||
realm: "your-realms",
|
||||
appName: "your-app-name"
|
||||
});
|
||||
*/
|
||||
}
|
||||
$('pre code').each(function(i, e) {
|
||||
hljs.highlightBlock(e)
|
||||
});
|
||||
},
|
||||
onFailure: function(data) {
|
||||
log("Unable to Load SwaggerUI");
|
||||
@@ -51,7 +58,6 @@
|
||||
})
|
||||
window.swaggerUi.load();
|
||||
});
|
||||
|
||||
</script>
|
||||
</head>
|
||||
|
||||
@@ -59,7 +65,6 @@
|
||||
<div id='header'>
|
||||
<div class="swagger-ui-wrap">
|
||||
<a id="logo" href="http://swagger.wordnik.com">swagger</a>
|
||||
|
||||
<form id='api_selector'>
|
||||
<div class='input icon-btn'>
|
||||
<img id="show-pet-store-icon" src="images/pet_store_api.png" title="Show Swagger Petstore Example Apis">
|
||||
@@ -75,7 +80,6 @@
|
||||
</div>
|
||||
|
||||
<div id="message-bar" class="swagger-ui-wrap"> </div>
|
||||
|
||||
<div id="swagger-ui-container" class="swagger-ui-wrap"></div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user