diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index edf33e53..2167f06f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,5 +1,5 @@ ## Pull Requests -Plase make your pull requests are made to the [**`develop_2.0`**](https://github.com/swagger-api/swagger-ui/tree/develop_2.0) branch at this time. +Please open your pull requests against the [**`develop_2.0`**](https://github.com/swagger-api/swagger-ui/tree/develop_2.0) branch at this time. ## Issues SwaggerUI uses [SwaggerJS](https://github.com/swagger-api/swagger-js) library for many internal operations. If you see errors in diff --git a/bower.json b/bower.json index da275f56..a8c047b8 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,6 @@ { "name": "swagger-ui", "main": "dist/index.html", - "version": "2.1.0", "authors": [ "Mohsen Azimi " ], diff --git a/dist/css/screen.css b/dist/css/screen.css index d6ed90bb..436cc28e 100644 --- a/dist/css/screen.css +++ b/dist/css/screen.css @@ -1155,8 +1155,16 @@ .swagger-section .auth { float: right; } -.swagger-section #api_information_panel { - position: absolute; +.swagger-section .api-ic { + height: 18px; + vertical-align: middle; + display: inline-block; + background: url(../images/explorer_icons.png) no-repeat; +} +.swagger-section .api-ic .api_information_panel { + position: relative; + margin-top: 20px; + margin-left: -5px; background: #FFF; border: 1px solid #ccc; border-radius: 5px; @@ -1167,34 +1175,32 @@ color: black; padding: 5px; } -.swagger-section #api_information_panel p .api-msg-enabled { +.swagger-section .api-ic .api_information_panel p .api-msg-enabled { color: green; } -.swagger-section #api_information_panel p .api-msg-disabled { +.swagger-section .api-ic .api_information_panel p .api-msg-disabled { color: red; } -.swagger-section .api-ic { - height: 18px; - vertical-align: middle; - display: inline-block; - background: url(../images/explorer_icons.png) no-repeat; +.swagger-section .api-ic:hover .api_information_panel { + position: absolute; + display: block; } .swagger-section .ic-info { background-position: 0 0; width: 18px; - margin-top: -7px; + margin-top: -6px; margin-left: 4px; } .swagger-section .ic-warning { background-position: -60px 0; width: 18px; - margin-top: -7px; + margin-top: -6px; margin-left: 4px; } .swagger-section .ic-error { background-position: -30px 0; width: 18px; - margin-top: -7px; + margin-top: -6px; margin-left: 4px; } .swagger-section .ic-off { diff --git a/dist/index.html b/dist/index.html index 764117a7..3e47f2b8 100644 --- a/dist/index.html +++ b/dist/index.html @@ -22,6 +22,11 @@ + + + + + . + * For example - + * + * If you wish to translate some new texsts you should do two things: + * 1. Add a new phrase pair ("New Phrase": "New Translation") into your language file (for example lang/ru.js). It will be great if you add it in other language files too. + * 2. Mark that text it templates this way New Phrase or . + * The main thing here is attribute data-sw-translate. Only inner html, title-attribute and value-attribute are going to translate. + * + */ +window.SwaggerTranslator = { + + _words:[], + + translate: function(sel) { + var $this = this; + sel = sel || '[data-sw-translate]'; + + $(sel).each(function() { + $(this).html($this._tryTranslate($(this).html())); + + $(this).val($this._tryTranslate($(this).val())); + $(this).attr('title', $this._tryTranslate($(this).attr('title'))); + }); + }, + + _tryTranslate: function(word) { + return this._words[$.trim(word)] !== undefined ? this._words[$.trim(word)] : word; + }, + + learn: function(wordsMap) { + this._words = wordsMap; + } +}; diff --git a/dist/lib/swagger-oauth.js b/dist/lib/swagger-oauth.js index fed588c6..3bf32647 100644 --- a/dist/lib/swagger-oauth.js +++ b/dist/lib/swagger-oauth.js @@ -5,6 +5,8 @@ var clientId; var realm; var oauth2KeyName; var redirect_uri; +var clientSecret; +var scopeSeparator; function handleLogin() { var scopes = []; @@ -40,6 +42,7 @@ function handleLogin() { appName = window.swaggerUi.api.info.title; } + $('.api-popup-dialog').remove(); popupDialog = $( [ '
', @@ -151,7 +154,7 @@ function handleLogin() { url += '&redirect_uri=' + encodeURIComponent(redirectUrl); url += '&realm=' + encodeURIComponent(realm); url += '&client_id=' + encodeURIComponent(clientId); - url += '&scope=' + encodeURIComponent(scopes.join(' ')); + url += '&scope=' + encodeURIComponent(scopes.join(scopeSeparator)); url += '&state=' + encodeURIComponent(state); window.open(url); @@ -184,7 +187,9 @@ function initOAuth(opts) { popupMask = (o.popupMask||$('#api-common-mask')); popupDialog = (o.popupDialog||$('.api-popup-dialog')); clientId = (o.clientId||errors.push('missing client id')); + clientSecret = (o.clientSecret||errors.push('missing client secret')); realm = (o.realm||errors.push('missing realm')); + scopeSeparator = (o.scopeSeparator||' '); if(errors.length > 0){ log('auth unable initialize oauth: ' + errors); @@ -206,6 +211,7 @@ function initOAuth(opts) { window.processOAuthCode = function processOAuthCode(data) { var params = { 'client_id': clientId, + 'client_secret': clientSecret, 'code': data.code, 'grant_type': 'authorization_code', 'redirect_uri': redirect_uri @@ -240,7 +246,7 @@ window.onOAuthComplete = function onOAuthComplete(token) { if(b){ // if all roles are satisfied var o = null; - $.each($('.auth #api_information_panel'), function(k, v) { + $.each($('.auth .api-ic .api_information_panel'), function(k, v) { var children = v; if(children && children.childNodes) { var requiredScopes = []; @@ -257,7 +263,7 @@ window.onOAuthComplete = function onOAuthComplete(token) { } } if(diff.length > 0){ - o = v.parentNode; + o = v.parentNode.parentNode; $(o.parentNode).find('.api-ic.ic-on').addClass('ic-off'); $(o.parentNode).find('.api-ic.ic-on').removeClass('ic-on'); @@ -266,7 +272,7 @@ window.onOAuthComplete = function onOAuthComplete(token) { $(o).find('.api-ic').removeClass('ic-error'); } else { - o = v.parentNode; + o = v.parentNode.parentNode; $(o.parentNode).find('.api-ic.ic-off').addClass('ic-on'); $(o.parentNode).find('.api-ic.ic-off').removeClass('ic-off'); diff --git a/gulpfile.js b/gulpfile.js index 7422ffda..d9434e8b 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -113,6 +113,12 @@ gulp.task('copy', ['less'], function() { .pipe(gulp.dest('./dist/lib')) .on('error', log); + // copy `lang` for translations + gulp + .src(['./lang/**/*.js']) + .pipe(gulp.dest('./dist/lang')) + .on('error', log); + // copy all files inside html folder gulp .src(['./src/main/html/**/*']) diff --git a/lang/es.js b/lang/es.js new file mode 100644 index 00000000..a8dff60b --- /dev/null +++ b/lang/es.js @@ -0,0 +1,52 @@ +'use strict'; + +/* jshint quotmark: double */ +window.SwaggerTranslator.learn({ + "Warning: Deprecated":"Advertencia: Obsoleto", + "Implementation Notes":"Notas de implementación", + "Response Class":"Clase de la Respuesta", + "Status":"Status", + "Parameters":"Parámetros", + "Parameter":"Parámetro", + "Value":"Valor", + "Description":"Descripción", + "Parameter Type":"Tipo del Parámetro", + "Data Type":"Tipo del Dato", + "Response Messages":"Mensajes de la Respuesta", + "HTTP Status Code":"Código de Status HTTP", + "Reason":"Razón", + "Response Model":"Modelo de la Respuesta", + "Request URL":"URL de la Solicitud", + "Response Body":"Cuerpo de la Respuesta", + "Response Code":"Código de la Respuesta", + "Response Headers":"Encabezados de la Respuesta", + "Hide Response":"Ocultar Respuesta", + "Try it out!":"Pruébalo!", + "Show/Hide":"Mostrar/Ocultar", + "List Operations":"Listar Operaciones", + "Expand Operations":"Expandir Operaciones", + "Raw":"Crudo", + "can't parse JSON. Raw result":"no puede parsear el JSON. Resultado crudo", + "Model Schema":"Esquema del Modelo", + "Model":"Modelo", + "apply":"aplicar", + "Username":"Nombre de usuario", + "Password":"Contraseña", + "Terms of service":"Términos de Servicio", + "Created by":"Creado por", + "See more at":"Ver más en", + "Contact the developer":"Contactar al desarrollador", + "api version":"versión de la api", + "Response Content Type":"Tipo de Contenido (Content Type) de la Respuesta", + "fetching resource":"buscando recurso", + "fetching resource list":"buscando lista del recurso", + "Explore":"Explorar", + "Show Swagger Petstore Example Apis":"Mostrar Api Ejemplo de Swagger Petstore", + "Can't read from server. It may not have the appropriate access-control-origin settings.":"No se puede leer del servidor. Tal vez no tiene la configuración de control de acceso de origen (access-control-origin) apropiado.", + "Please specify the protocol for":"Por favor, especificar el protocola para", + "Can't read swagger JSON from":"No se puede leer el JSON de swagger desde", + "Finished Loading Resource Information. Rendering Swagger UI":"Finalizada la carga del recurso de Información. Mostrando Swagger UI", + "Unable to read api":"No se puede leer la api", + "from path":"desde ruta", + "server returned":"el servidor retornó" +}); diff --git a/lang/translator.js b/lang/translator.js index 8a38b687..591f6d40 100644 --- a/lang/translator.js +++ b/lang/translator.js @@ -17,10 +17,11 @@ window.SwaggerTranslator = { _words:[], - translate: function() { + translate: function(sel) { var $this = this; + sel = sel || '[data-sw-translate]'; - $('[data-sw-translate]').each(function() { + $(sel).each(function() { $(this).html($this._tryTranslate($(this).html())); $(this).val($this._tryTranslate($(this).val())); diff --git a/lib/swagger-oauth.js b/lib/swagger-oauth.js index fed588c6..3bf32647 100644 --- a/lib/swagger-oauth.js +++ b/lib/swagger-oauth.js @@ -5,6 +5,8 @@ var clientId; var realm; var oauth2KeyName; var redirect_uri; +var clientSecret; +var scopeSeparator; function handleLogin() { var scopes = []; @@ -40,6 +42,7 @@ function handleLogin() { appName = window.swaggerUi.api.info.title; } + $('.api-popup-dialog').remove(); popupDialog = $( [ '
', @@ -151,7 +154,7 @@ function handleLogin() { url += '&redirect_uri=' + encodeURIComponent(redirectUrl); url += '&realm=' + encodeURIComponent(realm); url += '&client_id=' + encodeURIComponent(clientId); - url += '&scope=' + encodeURIComponent(scopes.join(' ')); + url += '&scope=' + encodeURIComponent(scopes.join(scopeSeparator)); url += '&state=' + encodeURIComponent(state); window.open(url); @@ -184,7 +187,9 @@ function initOAuth(opts) { popupMask = (o.popupMask||$('#api-common-mask')); popupDialog = (o.popupDialog||$('.api-popup-dialog')); clientId = (o.clientId||errors.push('missing client id')); + clientSecret = (o.clientSecret||errors.push('missing client secret')); realm = (o.realm||errors.push('missing realm')); + scopeSeparator = (o.scopeSeparator||' '); if(errors.length > 0){ log('auth unable initialize oauth: ' + errors); @@ -206,6 +211,7 @@ function initOAuth(opts) { window.processOAuthCode = function processOAuthCode(data) { var params = { 'client_id': clientId, + 'client_secret': clientSecret, 'code': data.code, 'grant_type': 'authorization_code', 'redirect_uri': redirect_uri @@ -240,7 +246,7 @@ window.onOAuthComplete = function onOAuthComplete(token) { if(b){ // if all roles are satisfied var o = null; - $.each($('.auth #api_information_panel'), function(k, v) { + $.each($('.auth .api-ic .api_information_panel'), function(k, v) { var children = v; if(children && children.childNodes) { var requiredScopes = []; @@ -257,7 +263,7 @@ window.onOAuthComplete = function onOAuthComplete(token) { } } if(diff.length > 0){ - o = v.parentNode; + o = v.parentNode.parentNode; $(o.parentNode).find('.api-ic.ic-on').addClass('ic-off'); $(o.parentNode).find('.api-ic.ic-on').removeClass('ic-on'); @@ -266,7 +272,7 @@ window.onOAuthComplete = function onOAuthComplete(token) { $(o).find('.api-ic').removeClass('ic-error'); } else { - o = v.parentNode; + o = v.parentNode.parentNode; $(o.parentNode).find('.api-ic.ic-off').addClass('ic-on'); $(o.parentNode).find('.api-ic.ic-off').removeClass('ic-off'); diff --git a/package.json b/package.json index e4c6236b..241778f1 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "description": "Swagger UI is a dependency-free collection of HTML, JavaScript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API", "version": "2.1.0", "homepage": "http://swagger.io", - "license": "Apache 2.0", + "license": "Apache-2.0", "main": "dist/swagger-ui.js", "scripts": { "build": "gulp", diff --git a/src/main/html/css/screen.css b/src/main/html/css/screen.css index d6ed90bb..436cc28e 100644 --- a/src/main/html/css/screen.css +++ b/src/main/html/css/screen.css @@ -1155,8 +1155,16 @@ .swagger-section .auth { float: right; } -.swagger-section #api_information_panel { - position: absolute; +.swagger-section .api-ic { + height: 18px; + vertical-align: middle; + display: inline-block; + background: url(../images/explorer_icons.png) no-repeat; +} +.swagger-section .api-ic .api_information_panel { + position: relative; + margin-top: 20px; + margin-left: -5px; background: #FFF; border: 1px solid #ccc; border-radius: 5px; @@ -1167,34 +1175,32 @@ color: black; padding: 5px; } -.swagger-section #api_information_panel p .api-msg-enabled { +.swagger-section .api-ic .api_information_panel p .api-msg-enabled { color: green; } -.swagger-section #api_information_panel p .api-msg-disabled { +.swagger-section .api-ic .api_information_panel p .api-msg-disabled { color: red; } -.swagger-section .api-ic { - height: 18px; - vertical-align: middle; - display: inline-block; - background: url(../images/explorer_icons.png) no-repeat; +.swagger-section .api-ic:hover .api_information_panel { + position: absolute; + display: block; } .swagger-section .ic-info { background-position: 0 0; width: 18px; - margin-top: -7px; + margin-top: -6px; margin-left: 4px; } .swagger-section .ic-warning { background-position: -60px 0; width: 18px; - margin-top: -7px; + margin-top: -6px; margin-left: 4px; } .swagger-section .ic-error { background-position: -30px 0; width: 18px; - margin-top: -7px; + margin-top: -6px; margin-left: 4px; } .swagger-section .ic-off { diff --git a/src/main/html/index.html b/src/main/html/index.html index 764117a7..3e47f2b8 100644 --- a/src/main/html/index.html +++ b/src/main/html/index.html @@ -22,6 +22,11 @@ + + + + +