Docs WIP
This commit is contained in:
30
docs/usage/configuration.md
Normal file
30
docs/usage/configuration.md
Normal file
@@ -0,0 +1,30 @@
|
||||
# Configuration
|
||||
|
||||
Parameters with dots in their names are single strings used to organize subordinate parameters, and are not indicative of a nested structure.
|
||||
|
||||
Parameter Name | Description
|
||||
--- | ---
|
||||
url | The url pointing to API definition (normally `swagger.json` or `swagger.yaml`). Will be ignored if `urls` or `spec` is used.
|
||||
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.
|
||||
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`.
|
||||
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.
|
||||
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.
|
||||
dom_id | The id of a dom element inside which SwaggerUi will put the user interface for swagger.
|
||||
domNode | The HTML DOM element inside which SwaggerUi will put the user interface for swagger. Overrides `dom_id`.
|
||||
oauth2RedirectUrl | OAuth redirect URL
|
||||
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.
|
||||
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.
|
||||
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'.
|
||||
defaultModelExpandDepth | The default expansion depth for models. The default value is 1.
|
||||
configUrl | Configs URL
|
||||
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
|
||||
modelPropertyMacro | MUST be a function. Function to set default values to each property in model. Accepts one argument modelPropertyMacro(property), property is immutable
|
||||
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'.
|
||||
displayOperationId | Controls the display of operationId in operations list. The default is `false`.
|
||||
displayRequestDuration | Controls the display of the request duration (in milliseconds) for `Try it out` requests. The default is `false`.
|
||||
maxDisplayedTags | If set, limits the number of tagged operations displayed to at most this many. The default is to show all operations.
|
||||
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.
|
||||
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)
|
||||
requestInterceptor | MUST be a function. Function to intercept try-it-out requests. Accepts one argument requestInterceptor(request) and must return the potentially modified request.
|
||||
responseInterceptor | MUST be a function. Function to intercept try-it-out responses. Accepts one argument responseInterceptor(response) and must return the potentially modified response.
|
||||
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.
|
||||
36
docs/usage/deep-linking.md
Normal file
36
docs/usage/deep-linking.md
Normal file
@@ -0,0 +1,36 @@
|
||||
# `deepLinking` parameter
|
||||
|
||||
Swagger-UI allows you to deeply link into tags and operations within a spec. When Swagger-UI is provided a URL fragment at runtime, it will automatically expand and scroll to a specified tag or operation.
|
||||
|
||||
## Usage
|
||||
|
||||
👉🏼 Add `deepLinking: true` to your Swagger-UI configuration to enable this functionality.
|
||||
|
||||
When you expand a tag or operation, Swagger-UI will automatically update its URL fragment with a deep link to the item.
|
||||
Conversely, when you collapse a tag or operation, Swagger-UI will clear the URL fragment.
|
||||
|
||||
You can also right-click a tag name or operation path in order to copy a link to that tag or operation.
|
||||
|
||||
#### Fragment format
|
||||
|
||||
The fragment is formatted in one of two ways:
|
||||
|
||||
- `#/{tagName}`, to trigger the focus of a specific tag
|
||||
- `#/{tagName}/{operationId}`, to trigger the focus of a specific operation within a tag
|
||||
|
||||
`operationId` is the explicit operationId provided in the spec, if one exists.
|
||||
Otherwise, Swagger-UI generates an implicit operationId by combining the operation's path and method, and escaping non-alphanumeric characters.
|
||||
|
||||
## FAQ
|
||||
|
||||
> I'm using Swagger-UI in an application that needs control of the URL fragment. How do I disable deep-linking?
|
||||
|
||||
This functionality is disabled by default, but you can pass `deepLinking: false` into Swagger-UI as a configuration item to be sure.
|
||||
|
||||
> Can I link to multiple tags or operations?
|
||||
|
||||
No, this is not supported.
|
||||
|
||||
> Can I collapse everything except the operation or tag I'm linking to?
|
||||
|
||||
Sure - use `docExpansion: none` to collapse all tags and operations. Your deep link will take precedence over the setting, so only the tag or operation you've specified will be expanded.
|
||||
46
docs/usage/installation.md
Normal file
46
docs/usage/installation.md
Normal file
@@ -0,0 +1,46 @@
|
||||
# Installation
|
||||
|
||||
Swagger-UI is available
|
||||
|
||||
## Distribution channels
|
||||
|
||||
### NPM Registry
|
||||
|
||||
We publish two modules to npm: **`swagger-ui`** and **`swagger-ui-dist`**.
|
||||
|
||||
**`swagger-ui`** is meant for consumption by JavaScript web projects that include module bundlers, such as Webpack, Browserify, and Rollup. Its main file exports Swagger-UI's main function, and the module also includes a namespaced stylesheet at `swagger-ui/dist/swagger-ui.css`. Here's an example:
|
||||
|
||||
```javascript
|
||||
import SwaggerUI from 'swagger-ui'
|
||||
// or use require, if you prefer
|
||||
const SwaggerUI = require('swagger-ui')
|
||||
|
||||
SwaggerUI({
|
||||
dom_id: '#myDomId'
|
||||
})
|
||||
```
|
||||
|
||||
In contrast, **`swagger-ui-dist`** is meant for server-side projects that need assets to serve to clients. The module, when imported, includes an `absolutePath` helper function that returns the absolute filesystem path to where the `swagger-ui-dist` module is installed.
|
||||
|
||||
The module's contents mirrors the `dist` folder you see in the Git repository. The most useful file is `swagger-ui-bundle.js`, which is a build of Swagger-UI that includes all the code it needs to run in one file. The folder also has an `index.html` asset, to make it easy to serve Swagger-UI like so:
|
||||
|
||||
```javascript
|
||||
const express = require('express')
|
||||
const pathToSwaggerUi = require('swagger-ui').absolutePath()
|
||||
|
||||
const app = express()
|
||||
|
||||
app.use(express.static(pathToSwaggerUi))
|
||||
|
||||
app.listen(3000)
|
||||
```
|
||||
|
||||
|
||||
|
||||
### Docker Hub
|
||||
|
||||
### Packagist
|
||||
|
||||
### unpkg
|
||||
|
||||
# Integration
|
||||
54
docs/usage/version-detection.md
Normal file
54
docs/usage/version-detection.md
Normal file
@@ -0,0 +1,54 @@
|
||||
# Detecting your Swagger-UI version
|
||||
|
||||
At times, you're going to need to know which version of Swagger-UI you use.
|
||||
|
||||
The first step would be to detect which major version you currently use, as the method of detecting the version has changed. If your Swagger-UI has been heavily modified and you cannot detect from the look and feel which major version you use, you'd have to try both methods to get the exact version.
|
||||
|
||||
To help you visually detect which version you're using, we've included supporting images.
|
||||
|
||||
|
||||
# Swagger-UI 3.X
|
||||
|
||||

|
||||
|
||||
Some distinct identifiers to Swagger-UI 3.X:
|
||||
- The API version appears as a badge next to its title.
|
||||
- If there are schemes or authorizations, they'd appear in a bar above the operations.
|
||||
- Try it out functionality is not enabled by default.
|
||||
- All the response codes in the operations appear at after the parameters.
|
||||
- There's a models section after the operations.
|
||||
|
||||
If you've determined this is the version you have, to find the exact version:
|
||||
- Open your browser's web console (changes between browsers)
|
||||
- Type `versions` in the console and execute the call.
|
||||
- You might need to expand the result, until you get a string similar to `swaggerUi : Object { version: "3.1.6", gitRevision: "g786cd47", gitDirty: true, … }`.
|
||||
- The version taken from that example would be `3.1.6`.
|
||||
|
||||
Note: This functionality was added in 3.0.8. If you're unable to execute it, you're likely to use an older version, and in that case the first step would be to upgrade.
|
||||
|
||||
|
||||
# Swagger-UI 2.X and under
|
||||
|
||||

|
||||
|
||||
Some distinct identifiers to Swagger-UI 3.X:
|
||||
- The API version appears at the bottom of the page.
|
||||
- Schemes are not rendered.
|
||||
- Authorization, if rendered, will appear next to the navigation bar.
|
||||
- Try it out functionality is enabled by default.
|
||||
- The successful response code would appear above the parameters, the rest below them.
|
||||
- There's no models section after the operations.
|
||||
|
||||
If you've determined this is the version you have, to find the exact version:
|
||||
- Navigate to the sources of the UI. Either on your disk or via the view page source functionality in your browser.
|
||||
- Find an open the `swagger-ui.js`
|
||||
- At the top of the page, there would be a comment containing the exact version of swagger-ui. This example shows version `2.2.9`:
|
||||
|
||||
```
|
||||
/**
|
||||
* swagger-ui - Swagger UI is a dependency-free collection of HTML, JavaScript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API
|
||||
* @version v2.2.9
|
||||
* @link http://swagger.io
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
```
|
||||
Reference in New Issue
Block a user