mkdocs-openapi
Generate predictable, native MkDocs API reference pages from an OpenAPI document.
mkdocs-openapi converts an OpenAPI 3.x JSON or YAML document into Markdown
pages during the MkDocs build. Because the pages participate in the normal
MkDocs pipeline, they work with site navigation, search, tags, Markdown
extensions, link validation, and theme customization.
[!IMPORTANT]
mkdocs-openapiis designed and tested around Material for MkDocs. Its generated markup and bundled navigation styles take advantage of Material's layout and CSS conventions. Other themes may render the generated Markdown, but are not currently a supported or tested target.
Status
This project is currently alpha software. It supports one or more local OpenAPI 3.x documents per MkDocs site.
See the changelog for release history.
Requirements
- Python 3.10 or later
- MkDocs 1.6 or later
- Material for MkDocs 9.6 or later (recommended and tested theme)
Installation
Install the plugin and Material for MkDocs:
python -m pip install mkdocs-openapi mkdocs-material
If you already have a Material for MkDocs project, install only the plugin:
python -m pip install mkdocs-openapi
Confirm that MkDocs can discover the plugin:
mkdocs get-deps
Quick start
Place your OpenAPI document under the MkDocs docs_dir. With the default
docs/ directory, a minimal project might look like this:
.
├── docs
│ ├── index.md
│ └── openapi
│ └── spec.yaml
└── mkdocs.yml
Enable the plugin in mkdocs.yml, then reference the OpenAPI document directly
from nav:
site_name: My API
theme:
name: material
plugins:
- search
- openapi
nav:
- Home: index.md
- API Reference: openapi/spec.yaml
Build or preview the site normally:
mkdocs serve
The OpenAPI nav entry is replaced with generated API pages:
API Reference
├── Overview
├── First tag
│ ├── Overview
│ ├── GET First operation
│ └── POST Second operation
└── Second tag
└── ...
Models
├── Overview
└── One page per component schema
The source specification is consumed during the build and is not copied into the published site.
Multiple specifications
Use specs when a site contains more than one OpenAPI document. Each entry
has a stable ID, a source path matching its nav entry, and an isolated output
directory:
plugins:
- search
- openapi:
specs:
pets:
source: openapi/pets.yaml
output_dir: api-reference/pets
orders:
source: openapi/orders.yaml
output_dir: api-reference/orders
models_dir: api-reference/orders/models
models_title: Order models
nav:
- Home: index.md
- APIs:
- Pets: openapi/pets.yaml
- Orders: openapi/orders.yaml
source and output_dir are required for every entry. models_dir defaults
to <output_dir>/models. The remaining rendering and navigation options may
be set globally and overridden for an individual specification. Every
configured source must appear in nav exactly once, and every OpenAPI document
in nav must be registered under specs.
Material for MkDocs integration
The plugin automatically:
- adds its bundled
mkdocs-openapi.cssstylesheet; - enables
admonition,attr_list,tables,pymdownx.superfences, andpymdownx.tabbed; - enables the alternate tab style used by Material;
- generates native Markdown pages that participate in Material search, tags, navigation, and table-of-contents behavior; and
- displays HTTP method badges in Material's primary navigation.
The method badge colors can be customized with CSS variables:
:root {
--api-method-get-color: #61affe;
--api-method-post-color: #49cc90;
--api-method-put-color: #fca130;
--api-method-delete-color: #f93e3e;
--api-method-text-color: #ffffff;
}
Add your override after the plugin stylesheet using the normal MkDocs
extra_css setting:
extra_css:
- stylesheets/extra.css
Configuration
Plugin options are configured below the openapi entry:
plugins:
- search
- tags
- openapi:
output_dir: api-reference
models_dir: models
models_title: Models
models_in_nav: true
| Option | Default | Description |
|---|---|---|
output_dir |
api-reference |
Virtual source directory for API and operation pages. |
models_dir |
models |
Virtual source directory for component schema pages. |
models_title |
Models |
Navigation title inserted beside the API section. |
models_in_nav |
true |
Include every model below the Models nav item. Set to false for very large schemas. |
tag_nav |
unset | Ordered tag navigation containing root-level tag names or titled groups of tag names. |
unlisted_tags |
exclude |
Handle primary tags omitted from tag_nav with exclude, append, or error. |
specs |
unset | Mapping of specification IDs to multi-spec source, output, and optional per-spec overrides. |
When specs is set, each entry accepts:
| Option | Default | Description |
|---|---|---|
source |
required | OpenAPI file below docs_dir; must match an entry in nav. |
output_dir |
required | Unique virtual source directory for this API. |
models_dir |
<output_dir>/models |
Unique virtual source directory for this API's schemas. |
models_title |
global value | Navigation title for this API's schemas. |
models_in_nav |
global value | Whether every schema is included in navigation. |
tag_nav |
global value | Tag navigation for this API. |
unlisted_tags |
global value | Handling of primary tags omitted from this API's tag_nav. |
Tag navigation
tag_nav controls which primary OpenAPI tags are rendered, their order, and
whether they appear below an additional navigation level:
plugins:
- openapi:
tag_nav:
- Phone:
- Business Hours
- Call Blocking
- Call Control
- SMS and Fax:
- Fax
- Message Store
- SMS
unlisted_tags: exclude
Plain string entries are rendered directly below the API Reference section. Group mappings create an additional navigation level.
Set unlisted_tags to:
excludeto omit tags not listed intag_nav;appendto add unlisted tags after the configured tags; orerrorto require an exhaustive tag configuration.
Unknown tags, duplicates, and empty groups fail the build. If tag_nav is
omitted, all tags retain their default order.
Rendering behavior
- Operations are grouped by their first OpenAPI tag.
- Operations without tags are placed under
Untagged. - Additional operation tags are retained as page metadata for Material's tags plugin.
- Each
components.schemasentry generates a model page. - Local schema
$refvalues link to generated model pages. - Inline schemas remain inline in operation documentation.
- Operation and model slugs are deterministic, with numeric suffixes for collisions.
Current limitations
- Swagger/OpenAPI 2.0 documents are rejected.
- External
$refdocuments are not resolved. - Callbacks and webhooks are not rendered as operations.
- The first tag is the canonical navigation group for a multi-tag operation.
- Themes other than Material for MkDocs are not currently tested or supported.
Examples
Petstore
The Petstore example demonstrates the standard rendering contract:
.venv/bin/python examples/petstore/verify.py
.venv/bin/mkdocs build --strict -f examples/petstore/mkdocs.yml
Multiple APIs
The multiple-API example generates two isolated references in one build:
.venv/bin/mkdocs build --strict -f examples/multiple/mkdocs.yml
RingCentral
The RingCentral example stress-tests the plugin with 517 operations and 1,481 reusable models:
.venv/bin/python examples/ringcentral/verify.py
.venv/bin/mkdocs build --strict -f examples/ringcentral/mkdocs.yml
Its output is written to site-ringcentral/.
Development
Clone the repository and install it in editable mode with test dependencies:
python -m venv .venv
. .venv/bin/activate
python -m pip install -e '.[test]'
Run the test suite:
pytest
Build the project documentation:
mkdocs build --strict
Or preview it locally:
mkdocs serve
License
mkdocs-openapi is distributed under the MIT License. See
LICENSE for details.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mkdocs_openapi-0.2.1.tar.gz.
File metadata
- Download URL: mkdocs_openapi-0.2.1.tar.gz
- Upload date:
- Size: 246.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
70a46d7fbf97cf2c67111eb491a38cb0cbf54144e144056a280585414d1678c1
|
|
| MD5 |
a83217726c9f12bfd5cfdb8261348e53
|
|
| BLAKE2b-256 |
42517245899615dda5037ee60a4db96abebdb4c799c74bcaaf1a317199a85ba0
|
Provenance
The following attestation bundles were made for mkdocs_openapi-0.2.1.tar.gz:
Publisher:
publish.yml on byrnereese/mkdocs-openapi
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mkdocs_openapi-0.2.1.tar.gz -
Subject digest:
70a46d7fbf97cf2c67111eb491a38cb0cbf54144e144056a280585414d1678c1 - Sigstore transparency entry: 2281345820
- Sigstore integration time:
-
Permalink:
byrnereese/mkdocs-openapi@6c03590847657337f4d5b6932bbc19a637d0e8cf -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/byrnereese
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@6c03590847657337f4d5b6932bbc19a637d0e8cf -
Trigger Event:
push
-
Statement type:
File details
Details for the file mkdocs_openapi-0.2.1-py3-none-any.whl.
File metadata
- Download URL: mkdocs_openapi-0.2.1-py3-none-any.whl
- Upload date:
- Size: 22.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
61ca7ade13ab25a9cc42ea440f7fd695da53ffcef3b27a3747dea453a8882feb
|
|
| MD5 |
4c7e9563f198b65914e6c2043a321e95
|
|
| BLAKE2b-256 |
7c581211313dec3f673df39d069772de8fe46b61fddc04a1fcb3ce2420b1b7a7
|
Provenance
The following attestation bundles were made for mkdocs_openapi-0.2.1-py3-none-any.whl:
Publisher:
publish.yml on byrnereese/mkdocs-openapi
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mkdocs_openapi-0.2.1-py3-none-any.whl -
Subject digest:
61ca7ade13ab25a9cc42ea440f7fd695da53ffcef3b27a3747dea453a8882feb - Sigstore transparency entry: 2281345888
- Sigstore integration time:
-
Permalink:
byrnereese/mkdocs-openapi@6c03590847657337f4d5b6932bbc19a637d0e8cf -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/byrnereese
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@6c03590847657337f4d5b6932bbc19a637d0e8cf -
Trigger Event:
push
-
Statement type: