Skip to main content

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-openapi is 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 local OpenAPI 3.x document per MkDocs site.

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.

Material for MkDocs integration

The plugin automatically:

  • adds its bundled mkdocs-openapi.css stylesheet;
  • enables admonition, attr_list, tables, pymdownx.superfences, and pymdownx.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.

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:

  • exclude to omit tags not listed in tag_nav;
  • append to add unlisted tags after the configured tags; or
  • error to 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.schemas entry generates a model page.
  • Local schema $ref values 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.
  • Only one OpenAPI document is supported per MkDocs site.
  • External $ref documents 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

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

mkdocs_openapi-0.1.0.tar.gz (242.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mkdocs_openapi-0.1.0-py3-none-any.whl (20.5 kB view details)

Uploaded Python 3

File details

Details for the file mkdocs_openapi-0.1.0.tar.gz.

File metadata

  • Download URL: mkdocs_openapi-0.1.0.tar.gz
  • Upload date:
  • Size: 242.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for mkdocs_openapi-0.1.0.tar.gz
Algorithm Hash digest
SHA256 237dd536f3e9627bed4bf1b158ce4ce320e72782cb16c06cbee47eeba23b1aa8
MD5 d827075f0b1c0770e1c213f0fbd396f1
BLAKE2b-256 5772223abd5184c0f531d8b95cc8a14defe3c8fdfd98e50f71f74d503216fe9e

See more details on using hashes here.

Provenance

The following attestation bundles were made for mkdocs_openapi-0.1.0.tar.gz:

Publisher: publish.yml on byrnereese/mkdocs-openapi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mkdocs_openapi-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: mkdocs_openapi-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 20.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for mkdocs_openapi-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ff5de8b46dc03753b3e2467c986cce91f56170df01f7743e4b332c82c2530b11
MD5 47819e76495b9732c1925ccd8b02b98e
BLAKE2b-256 37598b9a23b46f755a9bc48a33516c1d53f8fa207d82d66b70fe128e04742a07

See more details on using hashes here.

Provenance

The following attestation bundles were made for mkdocs_openapi-0.1.0-py3-none-any.whl:

Publisher: publish.yml on byrnereese/mkdocs-openapi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

This release

0.1.0 This release

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page