.NET CORE & SWAGGER PROGRAMMING
Deep linking is using a URL to get to a specific piece of content. A deep link is a URL that can be parsed by an application, for particular data & app navigation.
This article demonstrates steps to enable deep linking in swagger UI inside a .Net Core API.
What is deep linking?
Deep linking allows the user to provide UI fragments at runtime, i.e., it will automatically expand and scroll to specific tag & operation.
Similarly, collapsing the UI, both tag and operation will be removed from UI.
The below example demonstrates how deep linking looks like in swagger URL.
![](https://cdn-images-1.medium.com/max/800/1*2mtxVQQuQrprbJ_CmVdGlQ.png)
Fragment formats:
- #/{tagName} : trigger focus to specific tag.
- #/{tagName}/{operationId} : trigger focus to specific operation inside a tag.
NOTE: By default, deep linking is disabled.
Pros
- Consider a scenario where there are too many tag names & operation ids inside a swagger UI. In that case, deep linking is beneficial to share particular operations inside a tag name with other developers.
- Fragmentation is more flexible & allows us to focus on a particular section.
Demo
Please find the below-attached demo. Observe URL changes with each expands and collapse.
![](https://cdn-images-1.medium.com/max/1200/1*euwjoLjS9dbO9NdJR-Nydw.gif)
Prerequisites
How to enable Swagger UI in a .Net Core solution?
How to enable deep linking?
Please find below-attached code, which shows deep linking can be enabled by calling out EnableDeepLinking() method.
app.UseSwaggerUI(c =>{ c.SwaggerEndpoint("/swagger/v1/swagger.json", "Swagger Configuration V1");
c.EnableDeepLinking();
c.DisplayOperationId();
});
NOTE: DisplayOperationId() function is used to display operation ids on swagger UI.
GitHub Sample
Thank you for reading. Keep visiting and share this in your network. Please put your thoughts and feedback in the comments section.