deep-linking.md 1.8 KB
Newer Older
K
Kyle Shockey 已提交
1
# `deepLinking` parameter
K
Kyle Shockey 已提交
2

3
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.
K
Kyle Shockey 已提交
4 5 6

## Usage

7
👉🏼 Add `deepLinking: true` to your Swagger UI configuration to enable this functionality. This is demonstrated in [`dist/index.html`](https://github.com/swagger-api/swagger-ui/blob/master/dist/index.html).
K
Kyle Shockey 已提交
8

9 10
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.
K
Kyle Shockey 已提交
11

12
You can also right-click a tag name or operation path to copy a link to that tag or operation.
K
Kyle Shockey 已提交
13 14 15 16 17 18 19 20 21

#### 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.
22
Otherwise, Swagger UI generates an implicit operationId by combining the operation's path and method, while escaping non-alphanumeric characters.
K
Kyle Shockey 已提交
23 24 25

## FAQ

26
> I'm using Swagger UI in an application that needs control of the URL fragment. How do I disable deep-linking?
K
Kyle Shockey 已提交
27

28
This functionality is disabled by default, but you can pass `deepLinking: false` into Swagger UI as a configuration item to be sure.
K
Kyle Shockey 已提交
29 30 31 32 33 34 35 36

> 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.