Docusaurus OpenAPI Doc Generator
OpenAPI plugin for generating API reference docs in Docusaurus v3 (compatible with Docusaurus Faster).
Overview
The docusaurus-plugin-openapi-docs package extends the Docusaurus CLI with commands for generating MDX using the OpenAPI specification as the source. The resulting MDX is fully compatible with plugin-content-docs and can be used to render beautiful reference API docs when combined with the docusaurus-theme-openapi-docs theme.
Key Features:
- Compatible: Works with Swagger 2.0 and OpenAPI 3.x.
- Fast: Convert large OpenAPI specs into MDX docs in seconds. 🔥
- Stylish: Based on the same Infima styling framework that powers the Docusaurus UI.
- Flexible: Supports single, multi and even micro OpenAPI specs.
- Extensible: Recognizes common vendor extensions for customizing your docs. See Supported Vendor Extensions for details.
Compatibility Matrix
| Docusaurus OpenAPI Docs |
Docusaurus |
| 5.x.x (current) |
3.10.0+ |
| 4.x.x (legacy) |
3.5.0 - 3.9.2 |
| 3.0.x (end-of-support) |
3.0.1 - 3.4.0 |
| 2.2.3 (end-of-support) |
2.4.1 - 2.4.3 |
| 1.7.3 (end-of-support) |
2.0.1 - 2.2.0 |
Quick Start (new Docusaurus site)
Run the following to bootstrap a Docusaurus v3 site (classic theme) with docusaurus-openapi-docs:
npx create-docusaurus-openapi-docs my-website
cd my-website
yarn start
If all goes well, you should be greeted by a brand new Docusaurus site that includes API reference docs for the ubiquitous Petstore API!
CLI Options
| Option |
Description |
-p, --package-manager <manager> |
Use a specific package manager (yarn, npm, pnpm, bun) |
-s, --skip-install |
Skip automatic dependency installation |
Installation (existing Docusaurus site)
Both the plugin and theme are currently designed to pair with a specific Docusaurus release. The Docusaurus badge in the README.md and at the top of this page will always reflect the current compatible versions.
Plugin
yarn add docusaurus-plugin-openapi-docs
Theme
yarn add docusaurus-theme-openapi-docs
Configuring docusaurus.config.ts (Plugin and theme usage)
Here is an example of properly configuring docusaurus.config.ts for docusaurus-plugin-openapi-docs and docusaurus-theme-openapi-docs usage.
Note: Instructions may differ slightly for sites that haven't migrated to typescript.
// docusaurus.config.ts
// note that parts of the complete config were left out for brevity
import type * as Preset from "@docusaurus/preset-classic";
import type { Config } from "@docusaurus/types";
import type * as Plugin from "@docusaurus/types/src/plugin";
import type * as OpenApiPlugin from "docusaurus-plugin-openapi-docs";
{
presets: [
[
"classic",
{
docs: {
sidebarPath: "./sidebars.ts",
docItemComponent: "@theme/ApiItem", // Derived from docusaurus-theme-openapi
},
theme: {
customCss: "./src/css/custom.css",
},
} satisfies Preset.Options,
],
],
plugins: [
[
'docusaurus-plugin-openapi-docs',
{
id: "api", // plugin id
docsPluginId: "classic", // configured for preset-classic
config: {
petstore: {
specPath: "examples/petstore.yaml",
outputDir: "docs/petstore",
maskCredentials: false, // Disable credential masking in code snippets
sidebarOptions: {
groupPathsBy: "tag",
},
} satisfies OpenApiPlugin.Options,
}
},
]
],
themes: ["docusaurus-theme-openapi-docs"], // export theme components
}
Note: You may optionally configure a dedicated @docusaurus/plugin-content-docs instance for use with docusaurus-theme-openapi-docs by setting docItemComponent to @theme/ApiItem.
Plugin Configuration Options
The docusaurus-plugin-openapi-docs plugin can be configured with the following options:
| Name |
Type |
Default |
Description |
id |
string |
null |
A unique plugin ID. |
docsPlugin |
string |
@docusaurus/plugin-content-docs |
The plugin used to render the OpenAPI docs (ignored if the plugin instance referenced by docsPluginId is a preset). |
docsPluginId |
string |
null |
The plugin ID associated with the preset or configured docsPlugin instance used to render the OpenAPI docs (e.g. "your-plugin-id", "classic", "default"). |
config
config can be configured with the following options:
| Name |
Type |
Default |
Description |
specPath |
string |
null |
Designated URL or path to the source of an OpenAPI specification file or directory of multiple OpenAPI specification files. |
outputDir |
string |
null |
Desired output path for generated MDX and sidebar files. |
proxy |
string |
null |
Optional: Proxy URL to prepend to base URL when performing API requests from browser. Overrides site-wide themeConfig.api.proxy if set. |
template |
string |
null |
Optional: Customize MDX content with a desired template. |
infoTemplate |
string |
null |
Optional: Customize MDX content for info pages only. |
tagTemplate |
string |
null |
Optional: Customize MDX content for tag pages only. |
schemaTemplate |
string |
null |
Optional: Customize MDX content for schema pages only. |
downloadUrl |
string |
null |
Optional: Designated URL for downloading OpenAPI specification. (requires info section/doc) |
hideSendButton |
boolean |
null |
Optional: If set to true, hides the “Send API Request” button in the API demo panel. |
showExtensions |
boolean |
null |
Optional: If set to true, renders operation‑level vendor‑extensions in descriptions. |
maskCredentials |
boolean |
true |
Optional: If set to false, disables credential masking in generated code snippets. By default, credentials are masked for security. |
sidebarOptions |
object |
null |
Optional: Set of options for sidebar configuration. See below for a list of supported options. |
version |
string |
null |
Optional: Version assigned to a single or micro‑spec API specified in specPath. |
label |
string |
null |
Optional: Version label used when generating the version‑selector dropdown menu. |
baseUrl |
string |
null |
Optional: Base URL for versioned docs in the version‑selector dropdown. |
versions |
object |
null |
Optional: Options for versioning configuration. See below for a list of supported options. |
markdownGenerators |
object |
null |
Optional: Customize MDX content via generator functions. See below for a list of supported options. |
showSchemas |
boolean |
null |
Optional: If set to true, generates standalone schema pages and adds them to the sidebar. |
showInfoPage |
boolean |
true |
Optional: If set to false, disables generation of the info page (overview page with API title and description). |
schemasOnly |
boolean |
false |
Optional: If set to true, generates only schema pages (no API endpoint pages). Also available as --schemas-only CLI flag. |
externalJsonProps |
boolean |
true |
Optional: If set to false, disables externalization of large JSON props. By default, large JSON is written to external files for better build performance. |
markdownExport |
boolean |
false |
Optional: If set to true, the build writes a markdown version of each generated page to <page>.md. See Markdown export. |
Markdown export
Set markdownExport: true on a spec to give AI agents, headless browsers and other text-only clients a plain markdown version of every generated page. During docusaurus build, the plugin writes <page>.md next to each page route, for example /docs/petstore/add-pet.md for /docs/petstore/add-pet. The markdown includes everything that the page hides behind tabs or collapsed sections: all parameters with their serialization style, all request and response content types, every oneOf/anyOf option and discriminator mapping, conditional rules, multipart encoding, response links, callbacks, and all nested fields with their full dotted paths. It includes examples from the spec, but not generated code samples.
Info and tag pages list their operations with links to the operation markdown pages. If downloadUrl is set, API and info pages also link to the OpenAPI specification. Versions configured under versions inherit the setting.
Each page also gets a <link rel="alternate" type="text/markdown"> tag and a "Copy page" menu with "Copy page" and "View as Markdown" actions. If downloadUrl is set, the menu also has a "Download API spec" action on every page. These need the markdown_export and download_url front matter that gen-api-docs adds when the option is enabled, so regenerate the MDX files after you enable it. The keys are added to custom template, infoTemplate, tagTemplate and schemaTemplate output too.
The markdown files are written only by docusaurus build. They are not available with docusaurus start.
sidebarOptions
sidebarOptions can be configured with the following options:
| Name |
Type |
Default |
Description |
groupPathsBy |
string |
null |
Organize and group sidebar slice by specified option. Note: Currently, groupPathsBy contains support for grouping by tag, tagGroup, and tagParent (OpenAPI 3.2 hierarchical tags via tags[].parent). |
categoryLinkSource |
string |
null |
Defines what source to use for rendering category link pages when grouping paths by tag.
The supported options are as follows:
tag: Sets the category link config type to doc and uses the generated tag index page as the category link.
info: Sets the category link config type to doc and renders the info section as the category link (recommended only for multi/micro-spec scenarios).
auto: Sets the category link config type to generated-index and auto-generates an index page for each tag category.
When omitted, no link config is generated and categories render as expand/collapse groups only. |
sidebarCollapsible |
boolean |
true |
Whether sidebar categories are collapsible by default. |
sidebarCollapsed |
boolean |
true |
Whether sidebar categories are collapsed by default. |
customProps |
object |
null |
Additional props for customizing a sidebar item. |
sidebarGenerators |
object |
null |
Optional: Customize sidebar rendering with callback functions. |
You may optionally configure a sidebarOptions. In doing so, an individual sidebar.js slice with the configured options will be generated within the respective outputDir