OpenAPI (Swagger) Renderer for Sphinx

0.9.0 · active · verified Wed Apr 15

sphinxcontrib-openapi is a Sphinx extension that renders OpenAPI (formerly Swagger) specifications directly within Sphinx documentation. It leverages `sphinxcontrib-httpdomain` to provide an HTTP domain for describing RESTful HTTP APIs, avoiding the need to re-implement core functionality. It is actively maintained with its latest version 0.9.0 released in February 2026.

Warnings

Install

Imports

Quickstart

To quickly use `sphinxcontrib-openapi`, first ensure it's added to the `extensions` list in your Sphinx project's `conf.py`. Then, create an OpenAPI specification file (e.g., `openapi.yml`) and use the `.. openapi::` directive in your reStructuredText files, pointing to the spec file. Optional parameters like `:paths:`, `:examples:`, and `:group:` can control what parts of the spec are rendered and how.

# conf.py
# Add 'sphinxcontrib.openapi' to your extensions list
extensions = [
    'sphinx.ext.autodoc',
    'sphinx.ext.napoleon',
    'sphinxcontrib.httpdomain', # Ensure this is also included if not already
    'sphinxcontrib.openapi'
]

# docs/api.rst
# Create a sample OpenAPI spec file at docs/specs/openapi.yml
# For example:
# swagger: "2.0"
# info:
#   title: My API
#   version: "1.0.0"
# paths:
#   /greet:
#     get:
#       summary: Greet a user
#       responses:
#         200:
#           description: A greeting message

# In your .rst file, use the directive:
"""
API Documentation
=================

.. openapi:: specs/openapi.yml
   :paths: /greet
   :examples:
   :group:
"""

view raw JSON →