Skip to content

Commit 6254644

Browse files
committed
Merge pull request #1095 from swagger-api/develop_2.0
merge from develop 2.0 for release
2 parents 9ba4683 + 1ea7786 commit 6254644

File tree

93 files changed

+25448
-15435
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+25448
-15435
lines changed

.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
* text eol=lf
2+
3+
dist/**/* binary

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ swagger-ui.sublime-workspace
1010
.idea
1111
.project
1212
node_modules/*
13+
/nbproject/private/

.jshintignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
src/main/javascript/doc.js
3+
dist
4+
lib
5+
.log

.jshintrc

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"node": true,
3+
"browser": true,
4+
"esnext": true,
5+
"bitwise": true,
6+
"curly": true,
7+
"eqeqeq": true,
8+
"immed": true,
9+
"indent": 2,
10+
"latedef": false,
11+
"newcap": true,
12+
"noarg": true,
13+
"quotmark": "single",
14+
"regexp": true,
15+
"undef": true,
16+
"unused": true,
17+
"strict": true,
18+
"trailing": true,
19+
"smarttabs": true,
20+
"validthis": true,
21+
"globals": {
22+
23+
// Libraries
24+
"_": false,
25+
"$": false,
26+
"Backbone": false,
27+
"Handlebars": false,
28+
"jQuery": false,
29+
"marked": false,
30+
"SwaggerClient": false,
31+
"hljs": false,
32+
"SwaggerUi": false,
33+
"define": false,
34+
35+
// Global object
36+
// TODO: remove these
37+
"Docs": false
38+
}
39+
}

.travis.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
sudo: false
12
language: node_js
23
node_js:
34
- '0.10'
5+
- '0.12'
46
install:
57
- export DISPLAY=:99.0
68
- sh -e /etc/init.d/xvfb start
7-
- npm install
9+
- npm i -g jshint
10+
- npm install

README.md

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ Swagger UI Version | Release Date | Swagger Spec compatibility | Notes | Status
3030
### Download
3131
You can use the swagger-ui code AS-IS! No need to build or recompile--just clone this repo and use the pre-built files in the `dist` folder. If you like swagger-ui as-is, stop here.
3232

33+
##### Browser support
34+
Swagger UI works in all evergreen desktop browsers (Chrome, Safari, Firefox). Internet Explorer support is version 8 (IE8) and above.
35+
3336
### Build
3437
You can rebuild swagger-ui on your own to tweak it or just so you can say you did. To do so, follow these steps:
3538

@@ -57,24 +60,24 @@ Once you open the Swagger UI, it will load the [Swagger Petstore](http://petstor
5760
You may choose to customize Swagger UI for your organization. Here is an overview of whats in its various directories:
5861

5962
- dist: Contains a distribution which you can deploy on a server or load from your local machine.
63+
- dist/lang: The swagger localisation
6064
- lib: Contains javascript dependencies which swagger-ui depends on
6165
- node_modules: Contains node modules which swagger-ui uses for its development.
6266
- src
63-
- src/main/coffeescript: main code in CoffeeScript
6467
- src/main/templates: [handlebars](http://handlebarsjs.com/) templates used to render swagger-ui
6568
- src/main/html: the html files, some images and css
66-
- src/main/javascript: some legacy javascript referenced by CoffeeScript code
69+
- src/main/javascript: main code
6770

6871
### SwaggerUi
6972
To use swagger-ui you should take a look at the [source of swagger-ui html page](https://github.com/swagger-api/swagger-ui/blob/master/dist/index.html) and customize it. This basically requires you to instantiate a SwaggerUi object and call load() on it as below:
7073

7174
```javascript
72-
window.swaggerUi = new SwaggerUi({
75+
var swaggerUi = new SwaggerUi({
7376
url:"http://petstore.swagger.io/v2/swagger.json",
7477
dom_id:"swagger-ui-container"
7578
});
7679

77-
window.swaggerUi.load();
80+
swaggerUi.load();
7881
```
7982

8083
##### Parameters
@@ -87,11 +90,13 @@ validatorUrl | By default, Swagger-UI attempts to validate specs against swagger
8790
dom_id | The id of a dom element inside which SwaggerUi will put the user interface for swagger.
8891
booleanValues | SwaggerUI renders boolean data types as a dropdown. By default it provides a 'true' and 'false' string as the possible choices. You can use this parameter to change the values in dropdown to be something else, for example 0 and 1 by setting booleanValues to new Array(0, 1).
8992
docExpansion | Controls how the API listing is displayed. It can be set to 'none' (default), 'list' (shows operations for each resource), or 'full' (fully expanded: shows operations and their details).
90-
sorter | Apply a sort to the API list. It can be 'alpha' (sort paths alphanumerically) or 'method' (sort operations by HTTP method). Default is the order returned by the server unchanged.
93+
apisSorter | Apply a sort to the API/tags list. It can be 'alpha' (sort by name) or a function (see Array.prototype.sort() to know how sort function works). Default is the order returned by the server unchanged.
94+
operationsSorter | Apply a sort to the operation list of each API. It can be 'alpha' (sort by paths alphanumerically), 'method' (sort by HTTP method) or a function (see Array.prototype.sort() to know how sort function works). Default is the order returned by the server unchanged.
9195
onComplete | This is a callback function parameter which can be passed to be notified of when SwaggerUI has completed rendering successfully.
9296
onFailure | This is a callback function parameter which can be passed to be notified of when SwaggerUI encountered a failure was unable to render.
9397
highlightSizeThreshold | Any size response below this threshold will be highlighted syntactically, attempting to highlight large responses can lead to browser hangs, not including a threshold will default to highlight all returned responses.
9498
supportedSubmitMethods | An array of of the HTTP operations that will have the 'Try it out!` option. An empty array disables all operations. This does not filter the operations from the display.
99+
oauth2RedirectUrl | OAuth redirect URL
95100

96101
* All other parameters are explained in greater detail below
97102

@@ -104,11 +109,11 @@ swagger-ui supports invocation of all HTTP methods APIs including GET, PUT, POST
104109
Header params are supported through a pluggable mechanism in [swagger-js](https://github.com/swagger-api/swagger-js). You can see the [index.html](https://github.com/swagger-api/swagger-ui/blob/master/dist/index.html) for a sample of how to dynamically set headers:
105110

106111
```js
107-
// add a new ApiKeyAuthorization when the api-key changes in the ui.
112+
// add a new SwaggerClient.ApiKeyAuthorization when the api-key changes in the ui.
108113
$('#input_apiKey').change(function() {
109114
var key = $('#input_apiKey')[0].value;
110115
if(key && key.trim() != "") {
111-
window.authorizations.add("key", new ApiKeyAuthorization("api_key", key, "header"));
116+
swaggerUi.api.clientAuthorizations.add("key", new SwaggerClient.ApiKeyAuthorization("api_key", key, "header"));
112117
}
113118
})
114119
```
@@ -119,11 +124,36 @@ This will add header `api_key` with value `key` on every call to the server. Yo
119124
If you have some header parameters which you need to send with every request, use the headers as below:
120125

121126
```js
122-
window.authorizations.add("key", new ApiKeyAuthorization("Authorization", "XXXX", "header"));
127+
swaggerUi.api.clientAuthorizations.add("key", new SwaggerClient.ApiKeyAuthorization("Authorization", "XXXX", "header"));
123128
```
124129

125130
Note! You can pass multiple header params on a single request, just use unique names for them (`key` is used in the above example).
126131

132+
### Localization and translation
133+
The localization files are in the dist/lang directory.
134+
135+
To enable translation you should append next two lines in your Swagger's index.html (or another entry point you use)
136+
```html
137+
<script src='lang/translator.js' type='text/javascript'></script>
138+
<script src='lang/en.js' type='text/javascript'></script>
139+
```
140+
The first line script is a translator and the second one is your language lexemes.
141+
142+
If you wish to append support for new language you just need to create lang/your_lang.js and fill it like it's done in existing files.
143+
144+
To append new lexemex for translation you shoul do two things:
145+
1. Add lexeme into the language file.
146+
Example of new line: "new sentence":"translation of new sentence".
147+
2. Mark this lexeme in source html with attribute data-sw-translate.
148+
Example of changed source:
149+
```html
150+
<anyHtmlTag data-sw-translate>new sentence</anyHtmlTag>
151+
or <anyHtmlTag data-sw-translate value='new sentence'/>
152+
```
153+
.
154+
155+
At this moment only inner html, title-attribute and value-attribute are going to be translated.
156+
127157
## CORS Support
128158

129159
CORS is a technique to prevent websites from doing bad things with your personal data. Most browsers + javascript toolkits not only support CORS but enforce it, which has implications for your API server which supports Swagger.
@@ -191,7 +221,8 @@ Create your own fork of [swagger-api/swagger-ui](https://github.com/swagger-api/
191221

192222
To share your changes, [submit a pull request](https://github.com/swagger-api/swagger-ui/pull/new/master).
193223

194-
Since the javascript files are compiled from coffeescript, please submit changes in the *.coffee files! We have to reject changes only in the .js files as they will be lost on each build of the ui.
224+
## Change Log
225+
Plsee see [releases](https://github.com/swagger-api/swagger-ui/releases) for change log.
195226

196227
## License
197228

bower.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "swagger-ui",
3+
"main": "dist/index.html",
4+
"version": "2.1.8-M1",
5+
"authors": [
6+
"Mohsen Azimi <[email protected]>"
7+
],
8+
"description": "Swagger UI",
9+
"moduleType": [
10+
"globals"
11+
],
12+
"keywords": [
13+
"Swagger",
14+
"API"
15+
],
16+
"license": "Copyright 2015 Reverb Technologies, Inc.",
17+
"homepage": "http://swagger.io",
18+
"private": true,
19+
"ignore": [
20+
"**/.*",
21+
"node_modules",
22+
"bower_components",
23+
"test",
24+
"tests"
25+
]
26+
}

0 commit comments

Comments
 (0)