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