OpenAPI integration
DocsLit can generate full API reference documentation from an OpenAPI 3.x specification file. It extracts endpoints, parameters, request bodies, response schemas, and examples, then renders them using the built-in API components.
Quick start
Run the openapi scaffold command with your OpenAPI spec file:
This creates one Markdown page per endpoint in docs/api/, generates an introduction.md from the spec's info block, and updates docslit.json with the openapi config and sidebar structure.
Start the dev server to see the generated API reference:
The dev server loads the OpenAPI spec, resolves all <wc-endpoint ref="..."> tags, and renders the full endpoint documentation with parameters, request bodies, and response schemas.
The static build enriches all API pages with full spec data and generates Markdown files with complete endpoint documentation for AI agents.
Configuration
The scaffold command adds an openapi field to your docslit.json:
If you use an overlay file, the config is an object:
The scaffold command
What gets generated
For each endpoint in the spec, the scaffold command creates a Markdown file in docs/api/:
The ref attribute links the component to the operation by its operationId. At build time (and in the dev server), DocsLit resolves this ref against the loaded spec and injects all endpoint data: method, URL, parameters, request body fields, response schemas, and examples.
Introduction page
If the spec has an info block with a title, the scaffold command also generates an introduction.md page with the API title, version, contact details, license, and description.
Sidebar structure
The scaffold command builds the sidebar from your spec's metadata:
x-tagGroupscreate top-level sidebar groups- Tags create sub-sections within groups
- Operations appear as individual pages with method badges
Each sidebar entry includes the operation's summary as the display title and an HTTP method badge (GET, POST, PUT, DELETE, PATCH) aligned to the right.
How spec resolution works
When the dev server or build process encounters a <wc-endpoint ref="operationId"> tag, it:
- Loads and bundles the OpenAPI spec using Redocly, fully dereferencing all
$refpointers - Applies the overlay file if configured
- Extracts all endpoints with their parameters, request bodies, and responses
- Matches each
refattribute to anoperationIdin the spec - Injects the full endpoint data into the HTML as web component attributes and child elements
What gets extracted
Field grouping
Parameters are grouped by their location into separate sections:
- Headers — parameters with
in: header - Path Parameters — parameters with
in: path - Query Parameters — parameters with
in: query - Cookie Parameters — parameters with
in: cookie - Body — request body fields, with the content type shown in the title
Each group renders as its own <wc-fields> block with a descriptive title.
The layout: api frontmatter
Pages with layout: api in their frontmatter get the API-specific three-column layout with a wider content area and an examples panel on the right. The scaffold command sets this automatically.
Markdown output for AI agents
API pages serve enriched Markdown instead of raw <wc-endpoint ref="..."> tags. When an AI agent requests a page via Accept: text/markdown or fetches the .md file directly, it receives fully rendered documentation with parameter tables, request body field trees, response schemas, and code examples.
This works in both the dev server and static builds. Non-API pages serve their original Markdown source as before.
Overlays
OpenAPI overlays let you customize the spec without modifying the original file. This is useful when you're working with an auto-generated spec and want to add descriptions, examples, or custom extensions.
Custom code examples
Add code examples to any endpoint using the x-docslit-examples extension in your spec or overlay:
These examples appear as tabbed code blocks in the examples panel alongside any spec-defined request/response examples.
Next steps
- Learn about the API reference components used to render endpoint documentation
- Set up AI agent discovery for your API docs
- Deploy your API reference with static hosting