MkDocs Swagger UI Tag
mkdocs-swagger-ui-tag is an active MkDocs plugin that allows developers to embed interactive Swagger UI (OpenAPI) documentation directly into their MkDocs-generated pages. It supports both online OpenAPI Specification files via URL and static files stored within the `docs` directory, offering features like multiple Swagger UIs on a single page, and synchronized dark mode with themes like Material for MkDocs. The plugin handles all its JavaScript and CSS dependencies locally, making it suitable for environments without direct CDN access. It is currently at version 0.8.0.
Common errors
-
Swagger UI not loading or appearing blank in the documentation page.
cause The `swagger-ui-tag` plugin might not be enabled in `mkdocs.yml`, the OpenAPI specification file path in the `<swagger-ui>` tag is incorrect, or the OpenAPI file itself is invalid.fix1. Ensure `swagger-ui-tag` is listed under `plugins:` in your `mkdocs.yml` file. 2. Verify that the `src` attribute in your `<swagger-ui src="...">` tag points to a valid and accessible OpenAPI (YAML/JSON) file relative to your `docs` directory. 3. Check the browser's developer console for any loading errors or JavaScript issues related to the Swagger UI iframe. -
ERROR - Config value 'plugins': 'swagger-ui-tag' is not installed.
cause The `mkdocs-swagger-ui-tag` Python package has not been installed in your environment.fixRun `pip install mkdocs-swagger-ui-tag` to install the plugin. Ensure your Python environment is active where MkDocs is also installed. -
Dark mode styling of Swagger UI does not match the MkDocs Material theme or appears inconsistent.
cause Prior to v0.8.0, custom dark mode solutions might have been used or specific `swagger-ui-dist` versions behaved differently. The plugin now uses Swagger UI's built-in dark mode which might override previous custom styles.fixUpgrade to `mkdocs-swagger-ui-tag` version 0.8.0 or higher, as it includes built-in dark mode synchronization. Ensure your `mkdocs-material` theme is up-to-date. If issues persist, review the plugin's documentation for relevant dark mode configuration options and check for any conflicting custom CSS.
Warnings
- breaking Version 0.8.0 switched to Swagger UI's built-in dark mode and added support for deactivating browser cache for OpenAPI files. This may alter the appearance of dark mode in your documentation if you had custom styling or relied on previous dark mode implementations, and could affect caching behavior.
- gotcha Swagger UI instances might not display properly or fully load when navigating to pages via the sidebar while running `mkdocs serve`, but often work correctly after building the static site with `mkdocs build`.
- gotcha The plugin frequently updates its embedded `swagger-ui-dist` library, sometimes with significant version jumps. While this keeps the UI current, it can introduce subtle visual or behavioral changes in the Swagger UI itself, which are outside the control of the `mkdocs-swagger-ui-tag` plugin's configuration.
- gotcha Swagger UI configuration options can be applied globally in `mkdocs.yml` or locally using attributes on the `<swagger-ui>` tag. Local tag attributes will override global plugin settings.
Install
-
pip install mkdocs-swagger-ui-tag
Quickstart
site_name: My API Docs theme: material plugins: - swagger-ui-tag nav: - Home: index.md - API Reference: api.md # api.md content example: # # My API Documentation # # <swagger-ui src="./openapi.yaml" />