Skip to content

Commit

Permalink
Merge pull request swagger-api#1254 from swagger-api/develop_2.0
Browse files Browse the repository at this point in the history
Merged from develop_2.0
  • Loading branch information
fehguy committed May 8, 2015
2 parents 6f1b9b6 + 5640bf7 commit 9d8ccc4
Show file tree
Hide file tree
Showing 29 changed files with 738 additions and 254 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ swaggerUi.api.clientAuthorizations.add("key", new SwaggerClient.ApiKeyAuthorizat
Note! You can pass multiple header params on a single request, just use unique names for them (`key` is used in the above example).

### Localization and translation
The localization files are in the dist/lang directory.
The localization files are in the [lang](/lang) directory. Note that language files and translator is not included in SwaggerUI by default. You need to add them manually.

To enable translation you should append next two lines in your Swagger's index.html (or another entry point you use)
```html
Expand Down
3 changes: 3 additions & 0 deletions dist/css/print.css
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@
font-weight: bold;
font-size: 25px;
}
.swagger-section .swagger-ui-wrap .footer {
margin-top: 20px;
}
.swagger-section .swagger-ui-wrap p.big,
.swagger-section .swagger-ui-wrap div.big p {
font-size: 1em;
Expand Down
3 changes: 3 additions & 0 deletions dist/css/screen.css
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@
font-weight: bold;
font-size: 25px;
}
.swagger-section .swagger-ui-wrap .footer {
margin-top: 20px;
}
.swagger-section .swagger-ui-wrap p.big,
.swagger-section .swagger-ui-wrap div.big p {
font-size: 1em;
Expand Down
4 changes: 1 addition & 3 deletions dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<script src='swagger-ui.js' type='text/javascript'></script>
<script src='lib/highlight.7.3.pack.js' type='text/javascript'></script>
<script src='lib/marked.js' type='text/javascript'></script>
<script src='lib/swagger-oauth.js' type='text/javascript'></script>

<script type="text/javascript">
$(function () {
Expand All @@ -34,13 +35,11 @@
supportedSubmitMethods: ['get', 'post', 'put', 'delete', 'patch'],
onComplete: function(swaggerApi, swaggerUi){
if(typeof initOAuth == "function") {
/*
initOAuth({
clientId: "your-client-id",
realm: "your-realms",
appName: "your-app-name"
});
*/
}

$('pre code').each(function(i, e) {
Expand Down Expand Up @@ -71,7 +70,6 @@
/*
var apiKey = "myApiKeyXXXX123456789";
$('#input_apiKey').val(apiKey);
addApiKeyAuthorization();
*/

window.swaggerUi.load();
Expand Down
2 changes: 1 addition & 1 deletion dist/lib/swagger-oauth.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,4 +281,4 @@ window.onOAuthComplete = function onOAuthComplete(token) {
}
}
}
}
}
630 changes: 431 additions & 199 deletions dist/swagger-ui.js

Large diffs are not rendered by default.

19 changes: 11 additions & 8 deletions dist/swagger-ui.min.js

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var connect = require('gulp-connect');
var header = require('gulp-header');
var pkg = require('./package.json');
var order = require('gulp-order');
var jshint = require('gulp-jshint');
var banner = ['/**',
' * <%= pkg.name %> - <%= pkg.description %>',
' * @version v<%= pkg.version %>',
Expand Down Expand Up @@ -48,10 +49,19 @@ function templates() {
.on('error', log);
}

/**
* JShint all *.js files
*/
gulp.task('lint', function () {
return gulp.src('./src/main/javascript/**/*.js')
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'));
});

/**
* Build a distribution
*/
gulp.task('dist', ['clean'], function() {
gulp.task('dist', ['clean','lint'], function() {

return es.merge(
gulp.src([
Expand Down
53 changes: 53 additions & 0 deletions lang/en.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
'use strict';

/* jshint quotmark: double */
window.SwaggerTranslator.learn({
"Warning: Deprecated":"Warning: Deprecated",
"Implementation Notes":"Implementation Notes",
"Response Class":"Response Class",
"Status":"Status",
"Parameters":"Parameters",
"Parameter":"Parameter",
"Value":"Value",
"Description":"Description",
"Parameter Type":"Parameter Type",
"Data Type":"Data Type",
"Response Messages":"Response Messages",
"HTTP Status Code":"HTTP Status Code",
"Reason":"Reason",
"Response Model":"Response Model",
"Request URL":"Request URL",
"Response Body":"Response Body",
"Response Code":"Response Code",
"Response Headers":"Response Headers",
"Hide Response":"Hide Response",
"Try it out!":"Try it out!",
"Show/Hide":"Show/Hide",
"List Operations":"List Operations",
"Expand Operations":"Expand Operations",
"Raw":"Raw",
"can't parse JSON. Raw result":"can't parse JSON. Raw result",
"Model Schema":"Model Schema",
"Model":"Model",
"apply":"apply",
"Username":"Username",
"Password":"Password",
"Terms of service":"Terms of service",
"Created by":"Created by",
"See more at":"See more at",
"Contact the developer":"Contact the developer",
"api version":"api version",
"Response Content Type":"Response Content Type",
"fetching resource":"fetching resource",
"fetching resource list":"fetching resource list",
"Explore":"Explore",
"Show Swagger Petstore Example Apis":"Show Swagger Petstore Example Apis",
"Show Wordnik Developer Apis":"Show Wordnik Developer Apis",
"Can't read from server. It may not have the appropriate access-control-origin settings.":"Can't read from server. It may not have the appropriate access-control-origin settings.",
"Please specify the protocol for":"Please specify the protocol for",
"Can't read swagger JSON from":"Can't read swagger JSON from",
"Finished Loading Resource Information. Rendering Swagger UI":"Finished Loading Resource Information. Rendering Swagger UI",
"Unable to read api":"Unable to read api",
"from path":"from path",
"server returned":"server returned"
});
53 changes: 53 additions & 0 deletions lang/ru.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
'use strict';

/* jshint quotmark: double */
window.SwaggerTranslator.learn({
"Warning: Deprecated":"Ворнинг: Депрекейтед",
"Implementation Notes":"Заметки",
"Response Class":"Пример ответа",
"Status":"Статус",
"Parameters":"Параметры",
"Parameter":"Параметр",
"Value":"Значение",
"Description":"Описание",
"Parameter Type":"Тип параметра",
"Data Type":"Тип данных",
"HTTP Status Code":"HTTP код",
"Reason":"Причина",
"Response Model":"Структура ответа",
"Request URL":"URL запроса",
"Response Body":"Тело ответа",
"Response Code":"HTTP код ответа",
"Response Headers":"Заголовки ответа",
"Hide Response":"Спрятать ответ",
"Response Messages":"Что может прийти в ответ",
"Try it out!":"Попробовать!",
"Show/Hide":"Показать/Скрыть",
"List Operations":"Операции кратко",
"Expand Operations":"Операции подробно",
"Raw":"В сыром виде",
"can't parse JSON. Raw result":"Не удается распарсить ответ:",
"Model Schema":"Структура",
"Model":"Описание",
"apply":"применить",
"Username":"Имя пользователя",
"Password":"Пароль",
"Terms of service":"Условия использования",
"Created by":"Разработано",
"See more at":"Еще тут",
"Contact the developer":"Связаться с разработчиком",
"api version":"Версия API",
"Response Content Type":"Content Type ответа",
"fetching resource":"Получение ресурса",
"fetching resource list":"Получение ресурсов",
"Explore":"Поехали",
"Show Swagger Petstore Example Apis":"Показать примеры АПИ",
"Show Wordnik Developer Apis":"Показать АПИ Wordnik Developer",
"Can't read from server. It may not have the appropriate access-control-origin settings.":"Не удается получить ответ от сервера. Возможно, какая-то лажа с настройками доступа",
"Please specify the protocol for":"Пожалуйста, укажите протогол для",
"Can't read swagger JSON from":"Не получается прочитать swagger json из",
"Finished Loading Resource Information. Rendering Swagger UI":"Загрузка информации о ресурсах завершена. Рендерим",
"Unable to read api":"Не удалось прочитать api",
"from path":"по адресу",
"server returned":"сервер сказал"
});
38 changes: 38 additions & 0 deletions lang/translator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
'use strict';

/**
* Translator for documentation pages.
*
* To enable translation you should include one of language-files in your index.html
* after <script src='lang/translator.js' type='text/javascript'></script>.
* For example - <script src='lang/ru.js' type='text/javascript'></script>
*
* 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 <anyHtmlTag data-sw-translate>New Phrase</anyHtmlTag> or <anyHtmlTag data-sw-translate value='New Phrase'/>.
* 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() {
var $this = this;

$('[data-sw-translate]').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[word] !== undefined ? this._words[word] : word;
},

learn: function(wordsMap) {
this._words = wordsMap;
}
};
2 changes: 1 addition & 1 deletion lib/swagger-oauth.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,4 +281,4 @@ window.onOAuthComplete = function onOAuthComplete(token) {
}
}
}
}
}
17 changes: 11 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
{
"name": "swagger-ui",
"author": "Tony Tam <[email protected]>",
"contributors": [{
"name": "Mohsen Azimi",
"email": "[email protected]"
}],
"contributors": [
{
"name": "Mohsen Azimi",
"email": "[email protected]"
}
],
"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.1-M2",
"version": "2.1.2-M2",
"homepage": "http://swagger.io",
"license": "Apache 2.0",
"main": "dist/swagger-ui.js",
"scripts": {
"build": "gulp",
"serve": "gulp serve",
Expand All @@ -35,16 +38,18 @@
"gulp-declare": "^0.3.0",
"gulp-handlebars": "^3.0.1",
"gulp-header": "^1.2.2",
"gulp-jshint": "^1.10.0",
"gulp-less": "^3.0.1",
"gulp-order": "^1.1.1",
"gulp-rename": "^1.2.0",
"gulp-uglify": "^1.1.0",
"gulp-watch": "^4.1.1",
"gulp-wrap": "^0.11.0",
"http-server": "git+https://github.com/nodeapps/http-server.git",
"jshint-stylish": "^1.0.1",
"less": "^2.4.0",
"mocha": "^2.1.0",
"selenium-webdriver": "^2.45.0",
"swagger-client": "2.1.2-M2"
"swagger-client": "2.1.4-M2"
}
}
3 changes: 3 additions & 0 deletions src/main/html/css/print.css
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@
font-weight: bold;
font-size: 25px;
}
.swagger-section .swagger-ui-wrap .footer {
margin-top: 20px;
}
.swagger-section .swagger-ui-wrap p.big,
.swagger-section .swagger-ui-wrap div.big p {
font-size: 1em;
Expand Down
3 changes: 3 additions & 0 deletions src/main/html/css/screen.css
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@
font-weight: bold;
font-size: 25px;
}
.swagger-section .swagger-ui-wrap .footer {
margin-top: 20px;
}
.swagger-section .swagger-ui-wrap p.big,
.swagger-section .swagger-ui-wrap div.big p {
font-size: 1em;
Expand Down
4 changes: 1 addition & 3 deletions src/main/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<script src='swagger-ui.js' type='text/javascript'></script>
<script src='lib/highlight.7.3.pack.js' type='text/javascript'></script>
<script src='lib/marked.js' type='text/javascript'></script>
<script src='lib/swagger-oauth.js' type='text/javascript'></script>

<script type="text/javascript">
$(function () {
Expand All @@ -34,13 +35,11 @@
supportedSubmitMethods: ['get', 'post', 'put', 'delete', 'patch'],
onComplete: function(swaggerApi, swaggerUi){
if(typeof initOAuth == "function") {
/*
initOAuth({
clientId: "your-client-id",
realm: "your-realms",
appName: "your-app-name"
});
*/
}

$('pre code').each(function(i, e) {
Expand Down Expand Up @@ -71,7 +70,6 @@
/*
var apiKey = "myApiKeyXXXX123456789";
$('#input_apiKey').val(apiKey);
addApiKeyAuthorization();
*/

window.swaggerUi.load();
Expand Down
3 changes: 3 additions & 0 deletions src/main/javascript/SwaggerUi.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ window.SwaggerUi = Backbone.Router.extend({
// SwaggerUi accepts all the same options as SwaggerApi
initialize: function(options) {
options = options || {};
if(!options.highlightSizeThreshold) {
options.highlightSizeThreshold = 100000;
}

// Allow dom_id to be overridden
if (options.dom_id) {
Expand Down
27 changes: 26 additions & 1 deletion src/main/javascript/helpers/handlebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,29 @@ Handlebars.registerHelper('sanitize', function(html) {
// Strip the script tags from the html, and return it as a Handlebars.SafeString
html = html.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, '');
return new Handlebars.SafeString(html);
});
});

Handlebars.registerHelper('renderTextParam', function(param) {
var result, type = 'text';
var isArray = param.type.toLowerCase() === 'array' || param.allowMultiple;
var defaultValue = isArray && Array.isArray(param.default) ? param.default.join('\n') : param.default;

if (typeof defaultValue === 'undefined') {
defaultValue = '';
}

if(param.format && param.format === 'password') {
type = 'password';
}

if(isArray) {
result = '<textarea class=\'body-textarea' + (param.required ? ' required' : '') + '\' name=\'' + param.name + '\'';
result += ' placeholder=\'Provide multiple values in new lines' + (param.required ? ' (at least one required).' : '.') + '\'>';
result += defaultValue + '</textarea>';
} else {
result = '<input class=\'parameter\'' + (param.required ? ' class=\'required\'' : '') + ' minlength=\'' + (param.required ? 1 : 0) + '\'';
result += ' name=\'' + param.name +'\' placeholder=\'' + (param.required ? '(required)' : '') + '\'';
result += ' type=\'' + type + '\' value=\'' + defaultValue + '\'/>';
}
return new Handlebars.SafeString(result);
});
Loading

0 comments on commit 9d8ccc4

Please sign in to comment.