Skip to content

Commit 49333df

Browse files
committed
Merge branch 'master' of github.com:swagger-api/swagger-ui into feature/small-tweaks
2 parents d65d7b3 + e594392 commit 49333df

File tree

126 files changed

+4108
-1029
lines changed

Some content is hidden

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

126 files changed

+4108
-1029
lines changed

.github/issue_template.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<!---
22
Thanks for filing an issue 😄 ! Before you submit, please read the following:
33
4+
If you're here to report a security issue, please STOP writing an issue and contact us
5+
at [email protected] instead!
6+
47
Search open/closed issues before submitting since someone might have asked the same thing before!
58
69
Issues on GitHub are only related to problems of Swagger-UI itself. We'll try to offer support

.github/pull_request_template.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<!--- Provide a general summary of your changes in the Title above -->
2+
3+
### Description
4+
<!--- Describe your changes in detail -->
5+
6+
7+
8+
### Motivation and Context
9+
<!--- Why is this change required? What problem does it solve? -->
10+
<!--- If it fixes an open issue, please link to the issue here. -->
11+
<!--- Use the magic "Fixes #1234" format, so the issues are -->
12+
<!--- automatically closed when this PR is merged. -->
13+
14+
15+
16+
### How Has This Been Tested?
17+
<!--- Please describe in detail how you manually tested your changes. -->
18+
<!--- Include details of your testing environment, and the tests you ran to -->
19+
<!--- see how your change affects other areas of the code, etc. -->
20+
21+
22+
23+
### Screenshots (if appropriate):
24+
25+
26+
27+
### Types of changes
28+
<!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: -->
29+
- [ ] No code changes (changes to documentation, CI, metadata, etc)
30+
- [ ] Dependency changes (any modification to dependencies in `package.json`)
31+
- [ ] Bug fix (non-breaking change which fixes an issue)
32+
- [ ] New feature (non-breaking change which adds functionality)
33+
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
34+
35+
### Checklist:
36+
<!--- Go over all the following points, and put an `x` in all the boxes that apply. -->
37+
<!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->
38+
- [ ] My code follows the code style of this project.
39+
- [ ] My change requires a change to the documentation.
40+
- [ ] I have updated the documentation accordingly.
41+
- [ ] I have added tests to cover my changes.
42+
- [ ] All new and existing tests passed.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ node_modules
22
.idea
33
.deps_check
44
.DS_Store
5+
.nyc_output
56
npm-debug.log*
67
.eslintcache
78
package-lock.json
89
*.iml
910
selenium-debug.log
1011
test/e2e/db.json
12+
docs/_book

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
!dist/swagger-ui.js.map
77
!dist/swagger-ui.css
88
!dist/swagger-ui.css.map
9+
!dist/oauth2-redirect.html

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
language: node_js
22
node_js:
33
- '6.9'
4+
cache:
5+
directories:
6+
- node_modules
47
services:
58
- docker
69
branches:
710
only:
811
- master
912
- /^v\d+\.\d+(\.\d+)?(-\S*)?$/
13+
install: "npm i && npm update"
1014
before_deploy:
1115
- npm run build
1216
env:

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ We love contributions from our community of users! This document explains our gu
44

55
#### Environment setup
66

7-
0. Install Node.js (4 or newer) and npm (3 or newer).
7+
0. Install Node.js (6 or newer) and npm (3 or newer).
88
1. Make a fork of Swagger-UI on GitHub, then clone your fork to your machine.
99
2. Run `npm install` in your Swagger-UI directory.
1010
3. Run `npm run dev`. `localhost:3200` should open automatically.

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ ENV OAUTH_APP_NAME "**None**"
1313
ENV OAUTH_ADDITIONAL_PARAMS "**None**"
1414
ENV SWAGGER_JSON "/app/swagger.json"
1515
ENV PORT 80
16+
ENV BASE_URL ""
1617

1718
RUN apk add --update nginx
1819
RUN mkdir -p /run/nginx

README.md

Lines changed: 19 additions & 203 deletions
Original file line numberDiff line numberDiff line change
@@ -22,43 +22,33 @@ The OpenAPI Specification has undergone 5 revisions since initial creation in 20
2222

2323
Swagger UI Version | Release Date | OpenAPI Spec compatibility | Notes
2424
------------------ | ------------ | -------------------------- | -----
25-
3.4.0 | 2017-10-20 | 2.0, 3.0 | [tag v3.4.0](https://github.com/swagger-api/swagger-ui/tree/v3.4.0)
25+
3.6.1 | 2017-12-01 | 2.0, 3.0 | [tag v3.6.1](https://github.com/swagger-api/swagger-ui/tree/v3.6.1)
2626
3.0.21 | 2017-07-26 | 2.0 | [tag v3.0.21](https://github.com/swagger-api/swagger-ui/tree/v3.0.21)
2727
2.2.10 | 2017-01-04 | 1.1, 1.2, 2.0 | [tag v2.2.10](https://github.com/swagger-api/swagger-ui/tree/v2.2.10)
2828
2.1.5 | 2016-07-20 | 1.1, 1.2, 2.0 | [tag v2.1.5](https://github.com/swagger-api/swagger-ui/tree/v2.1.5)
2929
2.0.24 | 2014-09-12 | 1.1, 1.2 | [tag v2.0.24](https://github.com/swagger-api/swagger-ui/tree/v2.0.24)
3030
1.0.13 | 2013-03-08 | 1.1, 1.2 | [tag v1.0.13](https://github.com/swagger-api/swagger-ui/tree/v1.0.13)
3131
1.0.1 | 2011-10-11 | 1.0, 1.1 | [tag v1.0.1](https://github.com/swagger-api/swagger-ui/tree/v1.0.1)
3232

33+
## Documentation
3334

34-
### How to run
35+
#### Usage
36+
- [Installation](docs/usage/installation.md)
37+
- [Configuration](docs/usage/configuration.md)
38+
- [CORS](docs/usage/cors.md)
39+
- [OAuth2](docs/usage/oauth2.md)
40+
- [Deep Linking](docs/usage/deep-linking.md)
41+
- [Limitations](docs/usage/limitations.md)
42+
- [Version detection](docs/usage/version-detection.md)
3543

36-
##### Easy start! Docker
37-
You can pull a pre-built docker image of the swagger-ui directly from Dockerhub:
38-
39-
```
40-
docker pull swaggerapi/swagger-ui
41-
docker run -p 80:8080 swaggerapi/swagger-ui
42-
```
43-
44-
Will start nginx with swagger-ui on port 80.
45-
46-
Or you can provide your own swagger.json on your host
47-
48-
```
49-
docker run -p 80:8080 -e SWAGGER_JSON=/foo/swagger.json -v /bar:/foo swaggerapi/swagger-ui
50-
```
51-
52-
##### Prerequisites
53-
- Node 6.x
54-
- NPM 3.x
55-
56-
If you just want to see your specs, open `dist/index.html` in your browser directly from your filesystem.
57-
58-
If you'd like to make modifications to the codebase, run the dev server with: `npm run dev`. A development server will open on `3200`.
59-
60-
If you'd like to rebuild the `/dist` folder with your codebase changes, run `npm run build`.
44+
#### Customization
45+
- [Overview](docs/customization/overview.md)
46+
- [Plugin API](docs/customization/plugin-api.md)
47+
- [Custom layout](docs/customization/custom-layout.md)
6148

49+
#### Development
50+
- [Setting up](docs/development/setting-up.md)
51+
- [Scripts](docs/development/scripts.md)
6252

6353
##### Integration Tests
6454

@@ -67,193 +57,19 @@ http://nightwatchjs.org/gettingstarted#selenium-server-setup
6757

6858
Integration tests can be run locally with `npm run e2e` - be sure you aren't running a dev server when testing!
6959

70-
71-
##### Browser support
60+
### Browser support
7261
Swagger UI works in the latest versions of Chrome, Safari, Firefox, Edge and IE11.
7362

7463
### Known Issues
7564

7665
To help with the migration, here are the currently known issues with 3.X. This list will update regularly, and will not include features that were not implemented in previous versions.
7766

78-
- Only part of the [parameters](#parameters) previously supported are available.
67+
- Only part of the parameters previously supported are available.
7968
- The JSON Form Editor is not implemented.
8069
- Support for `collectionFormat` is partial.
8170
- l10n (translations) is not implemented.
8271
- Relative path support for external files is not implemented.
8372

84-
### Direct use of JS and CSS assets
85-
To include the JS, CSS and image assets directly into a webpage, use the [swagger-ui-dist](https://www.npmjs.com/package/swagger-ui-dist) package.
86-
The root directory of this package contains the contents of the _dist/_ directory of this repo.
87-
As a node module, `swagger-ui-dist` also exports the `swagger-ui-bundle` and `swagger-ui-standalone-preset` objects.
88-
89-
### SwaggerUIBundle
90-
To use swagger-ui's bundles, 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 as below:
91-
92-
```javascript
93-
const ui = SwaggerUIBundle({
94-
url: "http://petstore.swagger.io/v2/swagger.json",
95-
dom_id: '#swagger-ui',
96-
presets: [
97-
SwaggerUIBundle.presets.apis,
98-
SwaggerUIStandalonePreset
99-
],
100-
plugins: [
101-
SwaggerUIBundle.plugins.DownloadUrl
102-
],
103-
layout: "StandaloneLayout"
104-
})
105-
```
106-
107-
#### OAuth2 configuration
108-
You can configure OAuth2 authorization by calling `initOAuth` method with passed configs under the instance of `SwaggerUIBundle`
109-
default `client_id` and `client_secret`, `realm`, an application name `appName`, `scopeSeparator`, `additionalQueryStringParams`,
110-
`useBasicAuthenticationWithAccessCodeGrant`.
111-
112-
Config Name | Description
113-
--- | ---
114-
client_id | Default clientId. MUST be a string
115-
client_secret | Default clientSecret. MUST be a string
116-
realm | realm query parameter (for oauth1) added to `authorizationUrl` and `tokenUrl` . MUST be a string
117-
appName | application name, displayed in authorization popup. MUST be a string
118-
scopeSeparator | scope separator for passing scopes, encoded before calling, default value is a space (encoded value `%20`). MUST be a string
119-
additionalQueryStringParams | Additional query parameters added to `authorizationUrl` and `tokenUrl`. MUST be an object
120-
useBasicAuthenticationWithAccessCodeGrant | Only activated for the `accessCode` flow. During the `authorization_code` request to the `tokenUrl`, pass the [Client Password](https://tools.ietf.org/html/rfc6749#section-2.3.1) using the HTTP Basic Authentication scheme (`Authorization` header with `Basic base64encoded[client_id:client_secret]`). The default is `false`
121-
122-
```javascript
123-
const ui = SwaggerUIBundle({...})
124-
125-
// Method can be called in any place after calling constructor SwaggerUIBundle
126-
ui.initOAuth({
127-
clientId: "your-client-id",
128-
clientSecret: "your-client-secret-if-required",
129-
realm: "your-realms",
130-
appName: "your-app-name",
131-
scopeSeparator: " ",
132-
additionalQueryStringParams: {test: "hello"}
133-
})
134-
```
135-
136-
If you'd like to use the bundle files via npm, check out the [`swagger-ui-dist` package](https://www.npmjs.com/package/swagger-ui-dist).
137-
138-
#### Parameters
139-
140-
Parameters with dots in their names are single strings used to organize subordinate parameters, and are not indicative of a nested structure.
141-
142-
Parameter Name | Description
143-
--- | ---
144-
url | The url pointing to API definition (normally `swagger.json` or `swagger.yaml`). Will be ignored if `urls` or `spec` is used.
145-
urls | An array of API definition objects (`{url: "<url>", name: "<name>"}`) used by Topbar plugin. When used and Topbar plugin is enabled, the `url` parameter will not be parsed. Names and URLs must be unique among all items in this array, since they're used as identifiers.
146-
urls.primaryName | When using `urls`, you can use this subparameter. If the value matches the name of a spec provided in `urls`, that spec will be displayed when Swagger-UI loads, instead of defaulting to the first spec in `urls`.
147-
spec | A JSON object describing the OpenAPI Specification. When used, the `url` parameter will not be parsed. This is useful for testing manually-generated specifications without hosting them.
148-
validatorUrl | By default, Swagger-UI attempts to validate specs against swagger.io's online validator. You can use this parameter to set a different validator URL, for example for locally deployed validators ([Validator Badge](https://github.com/swagger-api/validator-badge)). Setting it to `null` will disable validation.
149-
dom_id | The id of a dom element inside which SwaggerUi will put the user interface for swagger.
150-
domNode | The HTML DOM element inside which SwaggerUi will put the user interface for swagger. Overrides `dom_id`.
151-
oauth2RedirectUrl | OAuth redirect URL
152-
tagsSorter | Apply a sort to the tag list of each API. It can be 'alpha' (sort by paths alphanumerically) or a function (see [Array.prototype.sort()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort) to learn how to write a sort function). Two tag name strings are passed to the sorter for each pass. Default is the order determined by Swagger-UI.
153-
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.
154-
defaultModelRendering | Controls how models are shown when the API is first rendered. (The user can always switch the rendering for a given model by clicking the 'Model' and 'Example Value' links.) It can be set to 'model' or 'example', and the default is 'example'.
155-
defaultModelExpandDepth | The default expansion depth for models. The default value is 1.
156-
configUrl | Configs URL
157-
parameterMacro | MUST be a function. Function to set default value to parameters. Accepts two arguments parameterMacro(operation, parameter). Operation and parameter are objects passed for context, both remain immutable
158-
modelPropertyMacro | MUST be a function. Function to set default values to each property in model. Accepts one argument modelPropertyMacro(property), property is immutable
159-
docExpansion | Controls the default expansion setting for the operations and tags. It can be 'list' (expands only the tags), 'full' (expands the tags and operations) or 'none' (expands nothing). The default is 'list'.
160-
displayOperationId | Controls the display of operationId in operations list. The default is `false`.
161-
displayRequestDuration | Controls the display of the request duration (in milliseconds) for `Try it out` requests. The default is `false`.
162-
maxDisplayedTags | If set, limits the number of tagged operations displayed to at most this many. The default is to show all operations.
163-
filter | If set, enables filtering. The top bar will show an edit box that you can use to filter the tagged operations that are shown. Can be true/false to enable or disable, or an explicit filter string in which case filtering will be enabled using that string as the filter expression. Filtering is case sensitive matching the filter expression anywhere inside the tag.
164-
deepLinking | If set to `true`, enables dynamic deep linking for tags and operations. [Docs](https://github.com/swagger-api/swagger-ui/blob/master/docs/deep-linking.md)
165-
requestInterceptor | MUST be a function. Function to intercept try-it-out requests. Accepts one argument requestInterceptor(request) and must return the potentially modified request.
166-
responseInterceptor | MUST be a function. Function to intercept try-it-out responses. Accepts one argument responseInterceptor(response) and must return the potentially modified response.
167-
showMutatedRequest | If set to `true` (the default), uses the mutated request returned from a rquestInterceptor to produce the curl command in the UI, otherwise the request before the requestInterceptor was applied is used.
168-
169-
### Plugins
170-
171-
#### Topbar plugin
172-
Topbar plugin enables top bar with input for spec path and explore button or a dropdown if `urls` is used. By default the plugin is enabled, and to disable it you need to remove Topbar plugin from presets in `src/standalone/index.js`:
173-
174-
```javascript
175-
let preset = [
176-
// TopbarPlugin,
177-
ConfigsPlugin,
178-
() => {
179-
return {
180-
components: { StandaloneLayout }
181-
}
182-
}
183-
]
184-
```
185-
186-
#### Configs plugin
187-
Configs plugin allows to fetch external configs instead of passing them to `SwaggerUIBundle`. Fetched configs support two formats: JSON or yaml. The plugin is enabled by default.
188-
There are three options of passing config:
189-
- add a query parameter `config` with URL to a server where the configs are hosted. For ex. http://petstore.swagger.io/?config=http://localhost:3001/config.yaml
190-
- add a config `configUrl` with URL to SwaggerUIBundle
191-
- change default configs in `swagger-config.yaml` *Note: after changing, the project must be re-built*
192-
193-
These options can be used altogether, the order of inheritance is following (from the lowest priority to the highest):
194-
`swagger-config.yaml` -> config passed to `SwaggerUIBundle` -> config fetched from `configUrl` passed to `SwaggerUIBundle` -> config fetched from URL passed as a query parameter `config`
195-
196-
## CORS Support
197-
198-
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.
199-
200-
You can read about CORS here: http://www.w3.org/TR/cors.
201-
202-
There are two cases where no action is needed for CORS support:
203-
204-
1. swagger-ui is hosted on the same server as the application itself (same host *and* port).
205-
2. The application is located behind a proxy that enables the required CORS headers. This may already be covered within your organization.
206-
207-
Otherwise, CORS support needs to be enabled for:
208-
209-
1. Your Swagger docs. For Swagger 2.0 it's the `swagger.json`/`swagger.yaml` and any externally `$ref`ed docs.
210-
2. For the `Try it now` button to work, CORS needs to be enabled on your API endpoints as well.
211-
212-
### Testing CORS Support
213-
214-
You can verify CORS support with one of three techniques:
215-
216-
- Curl your API and inspect the headers. For instance:
217-
218-
```bash
219-
$ curl -I "http://petstore.swagger.io/v2/swagger.json"
220-
HTTP/1.1 200 OK
221-
Date: Sat, 31 Jan 2015 23:05:44 GMT
222-
Access-Control-Allow-Origin: *
223-
Access-Control-Allow-Methods: GET, POST, DELETE, PUT, PATCH, OPTIONS
224-
Access-Control-Allow-Headers: Content-Type, api_key, Authorization
225-
Content-Type: application/json
226-
Content-Length: 0
227-
```
228-
229-
This tells us that the petstore resource listing supports OPTIONS, and the following headers: `Content-Type`, `api_key`, `Authorization`.
230-
231-
- Try swagger-ui from your file system and look at the debug console. If CORS is not enabled, you'll see something like this:
232-
233-
```
234-
XMLHttpRequest cannot load http://sad.server.com/v2/api-docs. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
235-
```
236-
237-
Swagger-UI cannot easily show this error state.
238-
239-
- Using the http://www.test-cors.org website. Keep in mind this will show a successful result even if `Access-Control-Allow-Headers` is not available, which is still required for Swagger-UI to function properly.
240-
241-
### Enabling CORS
242-
243-
The method of enabling CORS depends on the server and/or framework you use to host your application. http://enable-cors.org provides information on how to enable CORS in some common web servers.
244-
245-
Other servers/frameworks may provide you information on how to enable it specifically in their use case.
246-
247-
### CORS and Header Parameters
248-
249-
Swagger lets you easily send headers as parameters to requests. The name of these headers *MUST* be supported in your CORS configuration as well. From our example above:
250-
251-
```
252-
Access-Control-Allow-Headers: Content-Type, api_key, Authorization
253-
```
254-
255-
Only headers with these names will be allowed to be sent by Swagger-UI.
256-
25773
## Security contact
25874

25975
Please disclose any security-related issues or vulnerabilities by emailing [[email protected]](mailto:[email protected]), instead of using the public issue tracker.

docker-run.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ replace_or_delete_in_index () {
2121
fi
2222
}
2323

24+
if [ "${BASE_URL}" ]; then
25+
NGINX_WITH_BASE_URL="${NGINX_ROOT}${BASE_URL}"
26+
27+
mkdir -p ${NGINX_WITH_BASE_URL}
28+
mv ${NGINX_ROOT}/*.* ${NGINX_WITH_BASE_URL}/
29+
30+
INDEX_FILE=$NGINX_WITH_BASE_URL/index.html
31+
NGINX_ROOT=$NGINX_WITH_BASE_URL
32+
fi
33+
2434
replace_in_index myApiKeyXXXX123456789 $API_KEY
2535
replace_or_delete_in_index your-client-id $OAUTH_CLIENT_ID
2636
replace_or_delete_in_index your-client-secret-if-required $OAUTH_CLIENT_SECRET

docs/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Swagger-UI
2+
3+
Welcome to the Swagger-UI documentation!
4+
5+
A table of contents can be found at `SUMMARY.md`.

0 commit comments

Comments
 (0)