Swagger UI¶
To use Swagger UI, dist 5.22.0
has been built into the docs and a special swagger-ui.html
template has been added to provide:
- Swagger UI Bundle with its
swagger-ui-bundle.js
andswagger-ui.css
- Additional
swagger-ui.extra.css
to syncronize styles with Material for MkDocs - Default
deepLinking
enabled, models collapsed and singledom_id
specified
Adding a Swagger UI page¶
Required dependencies are included in the swagger-ui.html
template, just
- Use this template as described below
- Initialize
SwaggerUI
with the necessary parameters
---
# title: You page title <!-- (1)! -->
template: swagger-ui.html <!-- (2)! -->
hide:
# - navigation <!-- (3)! -->
- toc <!-- (4)! -->
---
<!-- (5)! -->
<script>
SwaggerUI({
url: "openapi.json" // (6)!
});
</script>
-
Optionally title your page accodring to the
info.title
from yoursopenapi.json
By default, the page title will be the same as the name of the corresponding
nav
element frommkdocs.yml
-
Use this template to have a embedded
swagger-ui-bundle
and custom styles applied to match Material for MkDocs theme - Consider hiding the navigation to increase the width of the Swagger UI interface
- Preferably hide the table of contents, especially if you do not have any additional content on the page
-
You can add any markdown content here if you want. Swagger UI will be displayed below this content, regardless of the script location.
Warning
The
swagger-ui.html
template does not insert an implicith1
header for the page, as the Swagger UI has its own header that has the same style.Therefore, if you add your own markdown content above the Swagger UI, add an explicit
# Page header
-
Provide required root-related path or an external link to the
openapi.json
and optionally configure anything you wantThe
swagger-ui.html
template hasto embed single Swagger UI below page content and<div id="swagger-ui"></div>
adds this default values to theSwaggerUI
configuration:dom_id: '#swagger-ui'
for the general usecase with single Swagger UI per pagedeepLinking: true
, so if for some reason you don't want to use deep links, disable them explicitlydefaultModelsExpandDepth: 0
to collapse models
You can override them in this configuration object
Example
See API Reference page
Do not use SwaggerUIBundle
Always use custom SwaggerUI
wrapper from the swagger-ui.html
template as it is compartible with instant loading and initializes SwaggerUIBundle
internally when possible
Multiple Swagger UI on a single page
By default, there is only one Swagger UI below optional markdown content per page. If you need more, add new div
inside your markdown content manually, specifying its id
and passing this id
as dom_id
to the SwaggerUI