');
+ var isLogout = false;
- // Attributes
- options: null,
- api: null,
- headerView: null,
- mainView: null,
+ auths.forEach(function (auth) {
+ var authView = new SwaggerUi.Views.AuthView({data: auth, router: this.router});
+ var authEl = authView.render().el;
+ $el.append(authEl);
+ if (authView.isLogout) {
+ isLogout = true;
+ }
+ }, this);
- // SwaggerUi accepts all the same options as SwaggerApi
- initialize: function(options) {
- options = options || {};
+ this.model.isLogout = isLogout;
- if (options.defaultModelRendering !== 'model') {
- options.defaultModelRendering = 'schema';
+ return $el;
}
- if (!options.highlightSizeThreshold) {
- options.highlightSizeThreshold = 100000;
- }
+});
- // Allow dom_id to be overridden
- if (options.dom_id) {
- this.dom_id = options.dom_id;
- delete options.dom_id;
- }
+'use strict';
- if (!options.supportedSubmitMethods){
- options.supportedSubmitMethods = [
- 'get',
- 'put',
- 'post',
- 'delete',
- 'head',
- 'options',
- 'patch'
- ];
- }
+SwaggerUi.Collections.AuthsCollection = Backbone.Collection.extend({
+ constructor: function() {
+ var args = Array.prototype.slice.call(arguments);
- if (typeof options.oauth2RedirectUrl === 'string') {
- window.oAuthRedirectUrl = options.redirectUrl;
- }
+ args[0] = this.parse(args[0]);
- // Create an empty div which contains the dom_id
- if (! $('#' + this.dom_id).length){
- $('body').append('
') ;
- }
+ Backbone.Collection.apply(this, args);
+ },
- this.options = options;
+ add: function (model) {
+ var args = Array.prototype.slice.call(arguments);
- // set marked options
- marked.setOptions({gfm: true});
+ if (Array.isArray(model)) {
+ args[0] = _.map(model, function(val) {
+ return this.handleOne(val);
+ }, this);
+ } else {
+ args[0] = this.handleOne(model);
+ }
- // Set the callbacks
- var that = this;
- this.options.success = function() { return that.render(); };
- this.options.progress = function(d) { return that.showMessage(d); };
- this.options.failure = function(d) { return that.onLoadFailure(d); };
+ Backbone.Collection.prototype.add.apply(this, args);
+ },
- // Create view to handle the header inputs
- this.headerView = new SwaggerUi.Views.HeaderView({el: $('#header')});
+ handleOne: function (model) {
+ var result = model;
- // Event handler for when the baseUrl/apiKey is entered by user
- this.headerView.on('update-swagger-ui', function(data) {
- return that.updateSwaggerUi(data);
- });
+ if (! (model instanceof Backbone.Model) ) {
+ switch (model.type) {
+ case 'oauth2':
+ result = new SwaggerUi.Models.Oauth2Model(model);
+ break;
+ case 'basic':
+ result = new SwaggerUi.Models.BasicAuthModel(model);
+ break;
+ case 'apiKey':
+ result = new SwaggerUi.Models.ApiKeyAuthModel(model);
+ break;
+ default:
+ result = new Backbone.Model(model);
+ }
+ }
- // JSon Editor custom theming
- JSONEditor.defaults.iconlibs.swagger = JSONEditor.AbstractIconLib.extend({
- mapping: {
- collapse: 'collapse',
- expand: 'expand'
- },
- icon_prefix: 'swagger-'
- });
+ return result;
+ },
- },
+ isValid: function () {
+ var valid = true;
- // Set an option after initializing
- setOption: function(option, value) {
- this.options[option] = value;
- },
+ this.models.forEach(function(model) {
+ if (!model.validate()) {
+ valid = false;
+ }
+ });
- // Get the value of a previously set option
- getOption: function(option) {
- return this.options[option];
- },
+ return valid;
+ },
- // Event handler for when url/key is received from user
- updateSwaggerUi: function(data){
- this.options.url = data.url;
- this.load();
- },
+ isAuthorized: function () {
+ return this.length === this.where({ isLogout: true }).length;
+ },
- // Create an api and render
- load: function(){
- // Initialize the API object
- if (this.mainView) {
- this.mainView.clear();
- }
- var url = this.options.url;
- if (url && url.indexOf('http') !== 0) {
- url = this.buildUrl(window.location.href.toString(), url);
- }
- if(this.api) {
- this.options.authorizations = this.api.clientAuthorizations.authz;
- }
- this.options.url = url;
- this.headerView.update(url);
+ isPartiallyAuthorized: function () {
+ return this.where({ isLogout: true }).length > 0;
+ },
- this.api = new SwaggerClient(this.options);
- },
+ parse: function (data) {
+ var authz = Object.assign({}, window.swaggerUi.api.clientAuthorizations.authz);
- // collapse all sections
- collapseAll: function(){
- Docs.collapseEndpointListForResource('');
- },
+ return _.map(data, function (auth, name) {
+ var isBasic = authz.basic && auth.type === 'basic';
- // list operations for all sections
- listAll: function(){
- Docs.collapseOperationsForResource('');
- },
+ _.extend(auth, {
+ title: name
+ });
- // expand operations for all sections
- expandAll: function(){
- Docs.expandOperationsForResource('');
- },
+ if (authz[name] || isBasic) {
+ _.extend(auth, {
+ isLogout: true,
+ value: isBasic ? undefined : authz[name].value,
+ username: isBasic ? authz.basic.username : undefined,
+ password: isBasic ? authz.basic.password : undefined,
+ valid: true
+ });
+ }
- // This is bound to success handler for SwaggerApi
- // so it gets called when SwaggerApi completes loading
- render: function(){
- this.showMessage('Finished Loading Resource Information. Rendering Swagger UI...');
- this.mainView = new SwaggerUi.Views.MainView({
- model: this.api,
- el: $('#' + this.dom_id),
- swaggerOptions: this.options,
- router: this
- }).render();
- this.showMessage();
- switch (this.options.docExpansion) {
- case 'full':
- this.expandAll(); break;
- case 'list':
- this.listAll(); break;
- default:
- break;
+ return auth;
+ });
}
- this.renderGFM();
+});
+'use strict';
- if (this.options.onComplete){
- this.options.onComplete(this.api, this);
- }
+SwaggerUi.Views.AuthsCollectionView = Backbone.View.extend({
- setTimeout(Docs.shebang.bind(this), 100);
- },
+ initialize: function(opts) {
+ this.options = opts || {};
+ this.options.data = this.options.data || {};
+ this.router = this.options.router;
- buildUrl: function(base, url){
- if (url.indexOf('/') === 0) {
- var parts = base.split('/');
- base = parts[0] + '//' + parts[2];
- return base + url;
- } else {
- var endOfPath = base.length;
+ this.collection = new SwaggerUi.Collections.AuthsCollection(opts.data);
- if (base.indexOf('?') > -1){
- endOfPath = Math.min(endOfPath, base.indexOf('?'));
- }
+ this.$innerEl = $('
');
+ this.authViews = [];
+ },
- if (base.indexOf('#') > -1){
- endOfPath = Math.min(endOfPath, base.indexOf('#'));
- }
+ render: function () {
+ this.collection.each(function (auth) {
+ this.renderOneAuth(auth);
+ }, this);
- base = base.substring(0, endOfPath);
+ this.$el.html(this.$innerEl.html() ? this.$innerEl : '');
- if (base.indexOf('/', base.length - 1 ) !== -1){
- return base + url;
- }
+ return this;
+ },
- return base + '/' + url;
- }
- },
+ renderOneAuth: function (authModel) {
+ var authViewEl, authView, authViewName;
+ var type = authModel.get('type');
- // Shows message on topbar of the ui
- showMessage: function(data){
- if (data === undefined) {
- data = '';
- }
- var $msgbar = $('#message-bar');
- $msgbar.removeClass('message-fail');
- $msgbar.addClass('message-success');
- $msgbar.text(data);
- if(window.SwaggerTranslator) {
- window.SwaggerTranslator.translate($msgbar);
- }
- },
+ if (type === 'apiKey') {
+ authViewName = 'ApiKeyAuthView';
+ } else if (type === 'basic' && this.$innerEl.find('.basic_auth_container').length === 0) {
+ authViewName = 'BasicAuthView';
+ } else if (type === 'oauth2') {
+ authViewName = 'Oauth2View';
+ }
- // shows message in red
- onLoadFailure: function(data){
- if (data === undefined) {
- data = '';
- }
- $('#message-bar').removeClass('message-success');
- $('#message-bar').addClass('message-fail');
+ if (authViewName) {
+ authView = new SwaggerUi.Views[authViewName]({model: authModel, router: this.router});
+ authViewEl = authView.render().el;
+ this.authViews.push(authView);
+ }
- var val = $('#message-bar').text(data);
+ this.$innerEl.append(authViewEl);
+ },
- if (this.options.onFailure) {
- this.options.onFailure(data);
+ highlightInvalid: function () {
+ this.authViews.forEach(function (view) {
+ view.highlightInvalid();
+ }, this);
}
- return val;
- },
+});
- // Renders GFM for elements with 'markdown' class
- renderGFM: function(){
- $('.markdown').each(function(){
- $(this).html(marked($(this).html()));
- });
+'use strict';
- $('.propDesc', '.model-signature .description').each(function () {
- $(this).html(marked($(this).html())).addClass('markdown');
- });
- }
+/* global redirect_uri */
+/* global clientId */
+/* global scopeSeparator */
+/* global additionalQueryStringParams */
+/* global clientSecret */
+/* global onOAuthComplete */
+/* global realm */
+/*jshint unused:false*/
+
+SwaggerUi.Views.AuthView = Backbone.View.extend({
+ events: {
+ 'click .auth_submit__button': 'authorizeClick',
+ 'click .auth_logout__button': 'logoutClick'
+ },
-});
+ tpls: {
+ main: Handlebars.templates.auth_view
+ },
-window.SwaggerUi.Views = {};
-window.SwaggerUi.partials = {};
+ selectors: {
+ innerEl: '.auth_inner',
+ authBtn: '.auth_submit__button'
+ },
-// don't break backward compatibility with previous versions and warn users to upgrade their code
-(function(){
- window.authorizations = {
- add: function() {
- warn('Using window.authorizations is deprecated. Please use SwaggerUi.api.clientAuthorizations.add().');
+ initialize: function(opts) {
+ this.options = opts || {};
+ opts.data = opts.data || {};
+ this.router = this.options.router;
- if (typeof window.swaggerUi === 'undefined') {
- throw new TypeError('window.swaggerUi is not defined');
- }
+ this.authsCollectionView = new SwaggerUi.Views.AuthsCollectionView({data: opts.data});
- if (window.swaggerUi instanceof SwaggerUi) {
- window.swaggerUi.api.clientAuthorizations.add.apply(window.swaggerUi.api.clientAuthorizations, arguments);
- }
- }
- };
+ this.$el.html(this.tpls.main({
+ isLogout: this.authsCollectionView.collection.isAuthorized(),
+ isAuthorized: this.authsCollectionView.collection.isPartiallyAuthorized()
+ }));
+ this.$innerEl = this.$(this.selectors.innerEl);
+ this.isLogout = this.authsCollectionView.collection.isPartiallyAuthorized();
+ },
- window.ApiKeyAuthorization = function() {
- warn('window.ApiKeyAuthorization is deprecated. Please use SwaggerClient.ApiKeyAuthorization.');
- SwaggerClient.ApiKeyAuthorization.apply(window, arguments);
- };
+ render: function () {
+ this.$innerEl.html(this.authsCollectionView.render().el);
- window.PasswordAuthorization = function() {
- warn('window.PasswordAuthorization is deprecated. Please use SwaggerClient.PasswordAuthorization.');
- SwaggerClient.PasswordAuthorization.apply(window, arguments);
- };
+ return this;
+ },
- function warn(message) {
- if ('console' in window && typeof window.console.warn === 'function') {
- console.warn(message);
- }
- }
-})();
+ authorizeClick: function (e) {
+ e.preventDefault();
+ e.stopPropagation();
+ if (this.authsCollectionView.collection.isValid()) {
+ this.authorize();
+ } else {
+ this.authsCollectionView.highlightInvalid();
+ }
+ },
-// UMD
-(function (root, factory) {
- if (typeof define === 'function' && define.amd) {
- // AMD. Register as an anonymous module.
- define(['b'], function (b) {
- return (root.SwaggerUi = factory(b));
- });
- } else if (typeof exports === 'object') {
- // Node. Does not work with strict CommonJS, but
- // only CommonJS-like environments that support module.exports,
- // like Node.
- module.exports = factory(require('b'));
- } else {
- // Browser globals
- root.SwaggerUi = factory(root.b);
- }
-}(this, function () {
- return SwaggerUi;
-}));
+ authorize: function () {
+ this.authsCollectionView.collection.forEach(function (auth) {
+ var keyAuth, basicAuth;
+ var type = auth.get('type');
-'use strict';
+ if (type === 'apiKey') {
+ keyAuth = new SwaggerClient.ApiKeyAuthorization(
+ auth.get('name'),
+ auth.get('value'),
+ auth.get('in')
+ );
-SwaggerUi.Views.ApiKeyButton = Backbone.View.extend({ // TODO: append this to global SwaggerUi
+ this.router.api.clientAuthorizations.add(auth.get('title'), keyAuth);
+ } else if (type === 'basic') {
+ basicAuth = new SwaggerClient.PasswordAuthorization(auth.get('username'), auth.get('password'));
+ this.router.api.clientAuthorizations.add(auth.get('type'), basicAuth);
+ } else if (type === 'oauth2') {
+ this.handleOauth2Login(auth);
+ }
+ }, this);
- events:{
- 'click #apikey_button' : 'toggleApiKeyContainer',
- 'click #apply_api_key' : 'applyApiKey'
- },
+ this.router.load();
+ },
- initialize: function(opts){
- this.options = opts || {};
- this.router = this.options.router;
- },
+ logoutClick: function (e) {
+ e.preventDefault();
- render: function(){
- var template = this.template();
- $(this.el).html(template(this.model));
+ this.authsCollectionView.collection.forEach(function (auth) {
+ var name = auth.get('type') === 'basic' ? 'basic' : auth.get('title');
- return this;
- },
+ window.swaggerUi.api.clientAuthorizations.remove(name);
+ });
+ this.router.load();
+ },
- applyApiKey: function(){
- var keyAuth = new SwaggerClient.ApiKeyAuthorization(
- this.model.name,
- $('#input_apiKey_entry').val(),
- this.model.in
- );
- this.router.api.clientAuthorizations.add(this.model.name, keyAuth);
- this.router.load();
- $('#apikey_container').show();
- },
+ // taken from lib/swagger-oauth.js
+ handleOauth2Login: function (auth) {
+ var host = window.location;
+ var pathname = location.pathname.substring(0, location.pathname.lastIndexOf('/'));
+ var defaultRedirectUrl = host.protocol + '//' + host.host + pathname + '/o2c.html';
+ var redirectUrl = window.oAuthRedirectUrl || defaultRedirectUrl;
+ var url = null;
+ var scopes = _.map(auth.get('scopes'), function (scope) {
+ return scope.scope;
+ });
+ var state, dets, ep;
+ window.OAuthSchemeKey = auth.get('title');
+
+ window.enabledScopes = scopes;
+ var flow = auth.get('flow');
+
+ if(auth.get('type') === 'oauth2' && flow && (flow === 'implicit' || flow === 'accessCode')) {
+ dets = auth.attributes;
+ url = dets.authorizationUrl + '?response_type=' + (flow === 'implicit' ? 'token' : 'code');
+ window.swaggerUi.tokenName = dets.tokenName || 'access_token';
+ window.swaggerUi.tokenUrl = (flow === 'accessCode' ? dets.tokenUrl : null);
+ state = window.OAuthSchemeKey;
+ }
+ else if(auth.get('type') === 'oauth2' && flow && (flow === 'application')) {
+ dets = auth.attributes;
+ window.swaggerUi.tokenName = dets.tokenName || 'access_token';
+ this.clientCredentialsFlow(scopes, dets.tokenUrl, window.OAuthSchemeKey);
+ return;
+ }
+ else if(auth.get('grantTypes')) {
+ // 1.2 support
+ var o = auth.get('grantTypes');
+ for(var t in o) {
+ if(o.hasOwnProperty(t) && t === 'implicit') {
+ dets = o[t];
+ ep = dets.loginEndpoint.url;
+ url = dets.loginEndpoint.url + '?response_type=token';
+ window.swaggerUi.tokenName = dets.tokenName;
+ }
+ else if (o.hasOwnProperty(t) && t === 'accessCode') {
+ dets = o[t];
+ ep = dets.tokenRequestEndpoint.url;
+ url = dets.tokenRequestEndpoint.url + '?response_type=code';
+ window.swaggerUi.tokenName = dets.tokenName;
+ }
+ }
+ }
- toggleApiKeyContainer: function(){
- if ($('#apikey_container').length) {
+ var redirect_uri = redirectUrl;
- var elem = $('#apikey_container').first();
+ url += '&redirect_uri=' + encodeURIComponent(redirectUrl);
+ url += '&realm=' + encodeURIComponent(realm);
+ url += '&client_id=' + encodeURIComponent(clientId);
+ url += '&scope=' + encodeURIComponent(scopes.join(scopeSeparator));
+ url += '&state=' + encodeURIComponent(state);
+ for (var key in additionalQueryStringParams) {
+ url += '&' + key + '=' + encodeURIComponent(additionalQueryStringParams[key]);
+ }
- if (elem.is(':visible')){
- elem.hide();
- } else {
+ window.open(url);
+ },
- // hide others
- $('.auth_container').hide();
- elem.show();
- }
+ // taken from lib/swagger-oauth.js
+ clientCredentialsFlow: function (scopes, tokenUrl, OAuthSchemeKey) {
+ var params = {
+ 'client_id': clientId,
+ 'client_secret': clientSecret,
+ 'scope': scopes.join(' '),
+ 'grant_type': 'client_credentials'
+ };
+ $.ajax({
+ url : tokenUrl,
+ type: 'POST',
+ data: params,
+ success: function (data)
+ {
+ onOAuthComplete(data, OAuthSchemeKey);
+ },
+ error: function ()
+ {
+ onOAuthComplete('');
+ }
+ });
}
- },
- template: function(){
- return Handlebars.templates.apikey_button_view;
- }
+});
+
+'use strict';
+
+SwaggerUi.Models.BasicAuthModel = Backbone.Model.extend({
+ defaults: {
+ username: '',
+ password: '',
+ title: 'basic'
+ },
+
+ initialize: function () {
+ this.on('change', this.validate);
+ },
+
+ validate: function () {
+ var valid = !!this.get('password') && !!this.get('username');
+ this.set('valid', valid);
+
+ return valid;
+ }
});
'use strict';
-SwaggerUi.Views.BasicAuthButton = Backbone.View.extend({
+SwaggerUi.Views.BasicAuthView = Backbone.View.extend({
+ initialize: function (opts) {
+ this.options = opts || {};
+ this.router = this.options.router;
+ },
- initialize: function (opts) {
- this.options = opts || {};
- this.router = this.options.router;
- },
+ events: {
+ 'change .auth_input': 'inputChange'
+ },
- render: function(){
- var template = this.template();
- $(this.el).html(template(this.model));
+ selectors: {
+ usernameInput: '.basic_auth__username',
+ passwordInput: '.basic_auth__password'
+ },
- return this;
- },
+ cls: {
+ error: 'error'
+ },
- events: {
- 'click #basic_auth_button' : 'togglePasswordContainer',
- 'click #apply_basic_auth' : 'applyPassword'
- },
+ template: Handlebars.templates.basic_auth,
- applyPassword: function(event){
- event.preventDefault();
- var username = $('#input_username').val();
- var password = $('#input_password').val();
- var basicAuth = new SwaggerClient.PasswordAuthorization('basic', username, password);
- this.router.api.clientAuthorizations.add(this.model.type, basicAuth);
- this.router.load();
- $('#basic_auth_container').hide();
- },
+ render: function(){
+ $(this.el).html(this.template(this.model.toJSON()));
- togglePasswordContainer: function(){
- if ($('#basic_auth_container').length) {
- var elem = $('#basic_auth_container').show();
- if (elem.is(':visible')){
- elem.slideUp();
- } else {
- // hide others
- $('.auth_container').hide();
- elem.show();
- }
- }
- },
+ return this;
+ },
- template: function(){
- return Handlebars.templates.basic_auth_button_view;
- }
+ inputChange: function (e) {
+ var $el = $(e.target);
+ var val = $el.val();
+ var attr = $el.prop('name');
+
+ if (val) {
+ $el.removeClass(this.cls.error);
+ }
+
+ this.model.set(attr, val);
+ },
+
+ isValid: function () {
+ return this.model.validate();
+ },
+ highlightInvalid: function () {
+ if (!this.model.get('username')) {
+ this.$(this.selectors.usernameInput).addClass(this.cls.error);
+ }
+
+ if (!this.model.get('password')) {
+ this.$(this.selectors.passwordInput).addClass(this.cls.error);
+ }
+ }
});
'use strict';
@@ -19124,8 +19816,7 @@ SwaggerUi.Views.HeaderView = Backbone.View.extend({
}
this.trigger('update-swagger-ui', {
- url: $('#input_baseUrl').val(),
- apiKey: $('#input_apiKey').val()
+ url: $('#input_baseUrl').val()
});
},
@@ -19136,7 +19827,6 @@ SwaggerUi.Views.HeaderView = Backbone.View.extend({
$('#input_baseUrl').val(url);
- //$('#input_apiKey').val(apiKey);
if (trigger) {
this.trigger('update-swagger-ui', {url:url});
}
@@ -19227,26 +19917,9 @@ SwaggerUi.Views.MainView = Backbone.View.extend({
},
- render: function(){
- if (this.model.securityDefinitions) {
- for (var name in this.model.securityDefinitions) {
- var auth = this.model.securityDefinitions[name];
- var button;
-
- if (auth.type === 'apiKey' && $('#apikey_button').length === 0) {
- button = new SwaggerUi.Views.ApiKeyButton({model: auth, router: this.router}).render().el;
- $('.auth_main_container').append(button);
- }
-
- if (auth.type === 'basicAuth' && $('#basic_auth_button').length === 0) {
- button = new SwaggerUi.Views.BasicAuthButton({model: auth, router: this.router}).render().el;
- $('.auth_main_container').append(button);
- }
- }
- }
-
- // Render the outer container for resources
+ render: function () {
$(this.el).html(Handlebars.templates.main(this.model));
+ this.model.securityDefinitions = this.model.securityDefinitions || {};
// Render each resource
@@ -19298,7 +19971,7 @@ SwaggerUi.Views.MainView = Backbone.View.extend({
onLinkClick: function (e) {
var el = e.target;
- if (el.tagName === 'A') {
+ if (el.tagName === 'A' && el.href) {
if (location.hostname !== el.hostname || location.port !== el.port) {
e.preventDefault();
window.open(el.href, '_blank');
@@ -19309,6 +19982,60 @@ SwaggerUi.Views.MainView = Backbone.View.extend({
'use strict';
+SwaggerUi.Models.Oauth2Model = Backbone.Model.extend({
+ defaults: {
+ scopes: {}
+ },
+
+ initialize: function () {
+ this.on('change', this.validate);
+ },
+
+ setScopes: function (name, val) {
+ var auth = _.extend({}, this.attributes);
+ var index = _.findIndex(auth.scopes, function(o) {
+ return o.scope === name;
+ });
+ auth.scopes[index].checked = val;
+
+ this.set(auth);
+ this.validate();
+ },
+
+ validate: function () {
+ var valid = _.findIndex(this.get('scopes'), function (o) {
+ return o.checked === true;
+ }) > -1;
+
+ this.set('valid', valid);
+
+ return valid;
+ }
+});
+'use strict';
+
+SwaggerUi.Views.Oauth2View = Backbone.View.extend({
+ events: {
+ 'change .oauth-scope': 'scopeChange'
+ },
+
+ template: Handlebars.templates.oauth2,
+
+ render: function () {
+ this.$el.html(this.template(this.model.toJSON()));
+
+ return this;
+ },
+
+ scopeChange: function (e) {
+ var val = $(e.target).prop('checked');
+ var scope = $(e.target).data('scope');
+
+ this.model.setScopes(scope, val);
+ }
+});
+'use strict';
+
SwaggerUi.Views.OperationView = Backbone.View.extend({
invocationUrl: null,
@@ -19341,21 +20068,21 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({
},
selectText: function(event) {
- var doc = document,
- text = event.target.firstChild,
- range,
- selection;
- if (doc.body.createTextRange) {
- range = document.body.createTextRange();
- range.moveToElementText(text);
- range.select();
- } else if (window.getSelection) {
- selection = window.getSelection();
- range = document.createRange();
- range.selectNodeContents(text);
- selection.removeAllRanges();
- selection.addRange(range);
- }
+ var doc = document,
+ text = event.target.firstChild,
+ range,
+ selection;
+ if (doc.body.createTextRange) {
+ range = document.body.createTextRange();
+ range.moveToElementText(text);
+ range.select();
+ } else if (window.getSelection) {
+ selection = window.getSelection();
+ range = document.createRange();
+ range.selectNodeContents(text);
+ selection.removeAllRanges();
+ selection.addRange(range);
+ }
},
mouseEnter: function(e) {
@@ -19566,6 +20293,21 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({
this.addStatusCode(statusCode);
}
+ if (Array.isArray(this.model.security)) {
+ var authsModel = SwaggerUi.utils.parseSecurityDefinitions(this.model.security);
+
+ authsModel.isLogout = !_.isEmpty(window.swaggerUi.api.clientAuthorizations.authz);
+ this.authView = new SwaggerUi.Views.AuthButtonView({
+ data: authsModel,
+ router: this.router,
+ isOperation: true,
+ model: {
+ scopes: authsModel.scopes
+ }
+ });
+ this.$('.authorize-wrapper').append(this.authView.render().el);
+ }
+
this.showSnippet();
return this;
},
@@ -19801,7 +20543,7 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({
// wraps a jquery response as a shred response
wrap: function(data) {
- var h, headerArray, headers, i, l, len, o;
+ var h, headerArray, headers, i, l, len, o;
headers = {};
headerArray = data.getAllResponseHeaders().split('\r');
for (l = 0, len = headerArray.length; l < len; l++) {
@@ -19978,7 +20720,7 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({
code = $('
').text('no content');
pre = $('
').append(code);
- // JSON
+ // JSON
} else if (contentType === 'application/json' || /\+json$/.test(contentType)) {
var json = null;
try {
@@ -19989,35 +20731,35 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({
code = $('
').text(json);
pre = $('
').append(code);
- // XML
+ // XML
} else if (contentType === 'application/xml' || /\+xml$/.test(contentType)) {
code = $('
').text(this.formatXml(content));
pre = $('
').append(code);
- // HTML
+ // HTML
} else if (contentType === 'text/html') {
code = $('
').html(_.escape(content));
pre = $('
').append(code);
- // Plain Text
+ // Plain Text
} else if (/text\/plain/.test(contentType)) {
code = $('
').text(content);
pre = $('
').append(code);
- // Image
+ // Image
} else if (/^image\//.test(contentType)) {
pre = $('
').attr('src', url);
- // Audio
+ // Audio
} else if (/^audio\//.test(contentType) && supportsAudioPlayback(contentType)) {
pre = $('
').append($('').attr('src', url).attr('type', contentType));
- // Download
+ // Download
} else if (headers['Content-Disposition'] && (/attachment/).test(headers['Content-Disposition']) ||
- headers['content-disposition'] && (/attachment/).test(headers['content-disposition']) ||
- headers['Content-Description'] && (/File Transfer/).test(headers['Content-Description']) ||
- headers['content-description'] && (/File Transfer/).test(headers['content-description'])) {
+ headers['content-disposition'] && (/attachment/).test(headers['content-disposition']) ||
+ headers['Content-Description'] && (/File Transfer/).test(headers['Content-Description']) ||
+ headers['content-description'] && (/File Transfer/).test(headers['content-description'])) {
if ('Blob' in window) {
var type = contentType || 'text/html';
@@ -20045,11 +20787,11 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({
pre = $(' ').append('Download headers detected but your browser does not support downloading binary via XHR (Blob).');
}
- // Location header based redirect download
+ // Location header based redirect download
} else if(headers.location || headers.Location) {
window.location = response.url;
- // Anything else (CORS)
+ // Anything else (CORS)
} else {
code = $('
').text(content);
pre = $(' ').append(code);
@@ -20075,8 +20817,8 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({
if (opts.showRequestHeaders) {
var form = $('.sandbox', $(this.el)),
- map = this.getInputMap(form),
- requestHeaders = this.model.getHeaderParams(map);
+ map = this.getInputMap(form),
+ requestHeaders = this.model.getHeaderParams(map);
delete requestHeaders['Content-Type'];
$('.request_headers', $(this.el)).html('' + _.escape(JSON.stringify(requestHeaders, null, ' ')).replace(/\n/g, ' ') + ' ');
}
@@ -21303,6 +22045,43 @@ SwaggerUi.partials.signature = (function () {
'use strict';
+SwaggerUi.Views.PopupView = Backbone.View.extend({
+ events: {
+ 'click .api-popup-cancel': 'cancelClick'
+ },
+
+ template: Handlebars.templates.popup,
+ className: 'api-popup-dialog',
+
+ selectors: {
+ content: '.api-popup-content',
+ main : '#swagger-ui-container'
+ },
+
+ initialize: function(){
+ this.$el.html(this.template(this.model));
+ },
+
+ render: function () {
+ this.$(this.selectors.content).append(this.model.content);
+ $(this.selectors.main).first().append(this.el);
+ this.showPopup();
+
+ return this;
+ },
+
+ showPopup: function () {
+ this.$el.show();
+ },
+
+ cancelClick: function () {
+ this.remove();
+ }
+
+});
+
+'use strict';
+
SwaggerUi.Views.ResourceView = Backbone.View.extend({
initialize: function(opts) {
opts = opts || {};
diff --git a/dist/swagger-ui.min.js b/dist/swagger-ui.min.js
index aba97afedca..57b9213abad 100644
--- a/dist/swagger-ui.min.js
+++ b/dist/swagger-ui.min.js
@@ -1,9 +1,9 @@
-(function(){function e(){e.history=e.history||[],e.history.push(arguments),this.console&&console.log(Array.prototype.slice.call(arguments)[0])}this.Handlebars=this.Handlebars||{},this.Handlebars.templates=this.Handlebars.templates||{},this.Handlebars.templates.apikey_button_view=Handlebars.template({compiler:[6,">= 2.0.0-beta.1"],main:function(e,t,n,r){var i,a="function",o=t.helperMissing,s=this.escapeExpression;return"\n\n"},useData:!0}),this.Handlebars.templates.basic_auth_button_view=Handlebars.template({compiler:[6,">= 2.0.0-beta.1"],main:function(e,t,n,r){return'\n\n\n'},useData:!0}),this.Handlebars.templates.content_type=Handlebars.template({1:function(e,t,n,r){var i,a="";return i=t.each.call(e,null!=e?e.produces:e,{name:"each",hash:{},fn:this.program(2,r),inverse:this.noop,data:r}),null!=i&&(a+=i),a},2:function(e,t,n,r){var i=this.lambda,a=this.escapeExpression;return' '+a(i(e,e))+" \n"},4:function(e,t,n,r){return' application/json \n'},compiler:[6,">= 2.0.0-beta.1"],main:function(e,t,n,r){var i,a,o="function",s=t.helperMissing,l=this.escapeExpression,u='Response Content Type \n\n';return i=t["if"].call(e,null!=e?e.produces:e,{name:"if",hash:{},fn:this.program(1,r),inverse:this.program(4,r),data:r}),null!=i&&(u+=i),u+" \n"},useData:!0}),$(function(){$.fn.vAlign=function(){return this.each(function(){var e=$(this).height(),t=$(this).parent().height(),n=(t-e)/2;$(this).css("margin-top",n)})},$.fn.stretchFormtasticInputWidthToParent=function(){return this.each(function(){var e=$(this).closest("form").innerWidth(),t=parseInt($(this).closest("form").css("padding-left"),10)+parseInt($(this).closest("form").css("padding-right"),10),n=parseInt($(this).css("padding-left"),10)+parseInt($(this).css("padding-right"),10);$(this).css("width",e-t-n)})},$("form.formtastic li.string input, form.formtastic textarea").stretchFormtasticInputWidthToParent(),$("ul.downplayed li div.content p").vAlign(),$("form.sandbox").submit(function(){var e=!0;return $(this).find("input.required").each(function(){$(this).removeClass("error"),""===$(this).val()&&($(this).addClass("error"),$(this).wiggle(),e=!1)}),e})}),Function.prototype.bind&&console&&"object"==typeof console.log&&["log","info","warn","error","assert","dir","clear","profile","profileEnd"].forEach(function(e){console[e]=this.bind(console[e],console)},Function.prototype.call),window.Docs={shebang:function(){var e=$.param.fragment().split("/");switch(e.shift(),e.length){case 1:if(e[0].length>0){var t="resource_"+e[0];Docs.expandEndpointListForResource(e[0]),$("#"+t).slideto({highlight:!1})}break;case 2:Docs.expandEndpointListForResource(e[0]),$("#"+t).slideto({highlight:!1});var n=e.join("_"),r=n+"_content";Docs.expandOperation($("#"+r)),$("#"+n).slideto({highlight:!1})}},toggleEndpointListForResource:function(e){var t=$("li#resource_"+Docs.escapeResourceName(e)+" ul.endpoints");t.is(":visible")?($.bbq.pushState("#/",2),Docs.collapseEndpointListForResource(e)):($.bbq.pushState("#/"+e,2),Docs.expandEndpointListForResource(e))},expandEndpointListForResource:function(e){var e=Docs.escapeResourceName(e);if(""==e)return void $(".resource ul.endpoints").slideDown();$("li#resource_"+e).addClass("active");var t=$("li#resource_"+e+" ul.endpoints");t.slideDown()},collapseEndpointListForResource:function(e){var e=Docs.escapeResourceName(e);if(""==e)return void $(".resource ul.endpoints").slideUp();$("li#resource_"+e).removeClass("active");var t=$("li#resource_"+e+" ul.endpoints");t.slideUp()},expandOperationsForResource:function(e){return Docs.expandEndpointListForResource(e),""==e?void $(".resource ul.endpoints li.operation div.content").slideDown():void $("li#resource_"+Docs.escapeResourceName(e)+" li.operation div.content").each(function(){Docs.expandOperation($(this))})},collapseOperationsForResource:function(e){return Docs.expandEndpointListForResource(e),""==e?void $(".resource ul.endpoints li.operation div.content").slideUp():void $("li#resource_"+Docs.escapeResourceName(e)+" li.operation div.content").each(function(){Docs.collapseOperation($(this))})},escapeResourceName:function(e){return e.replace(/[!"#$%&'()*+,.\/:;<=>?@\[\\\]\^`{|}~]/g,"\\$&")},expandOperation:function(e){e.slideDown()},collapseOperation:function(e){e.slideUp()}},Handlebars.registerHelper("sanitize",function(e){return e=e.replace(/