OpenAPI
Configure OpenAPI specification for automatic API documentation
Docs Kit integrates with OpenAPI (Swagger) specifications to automatically generate interactive API documentation. Simply provide your OpenAPI spec and reference endpoints in your MDX files.
When configured, OpenAPI integration provides:
Place your OpenAPI JSON file in the public/ directory:
# Download or copy your OpenAPI spec
cp openapi.json public/openapi.jsonOr use a remote URL.
Update config/docs.config.ts:
{
"openapi": {
"specPath": "public/openapi.json"
}
}Create an MDX file with openapi frontmatter:
---
title: "Get User"
description: "Retrieve user by ID"
openapi: "GET /api/users/{id}"
published: true
---
Additional context about this endpoint...Restart the development server to load the spec:
bun devStore the spec in your project:
{
"openapi": {
"specPath": "public/openapi.json"
}
}
Directory structure:
public/
static/
openapi.json
Reference a hosted specification:
{
"openapi": {
"specPath": "https://api.example.com/openapi.json"
}
}
Benefits:
Docs Kit supports OpenAPI 3.0+ specifications:
{
"openapi": "3.0.0",
"info": {
"title": "My API",
"version": "1.0.0"
},
"servers": [
{
"url": "https://api.example.com"
}
],
"paths": {
"/users/{id}": {
"get": {
"summary": "Get user by ID",
"parameters": [...],
"responses": {...}
}
}
},
"components": {
"schemas": {...},
"securitySchemes": {...}
}
}
Path to OpenAPI specification file (local or remote URL).
Local file:
"specPath": "public/openapi.json"Remote URL:
"specPath": "https://api.example.com/spec.json"Before using your spec, validate it:
# Using Swagger CLI
npm install -g @apidevtools/swagger-cli
swagger-cli validate public/openapi.json
# Using Redocly CLI
npm install -g @redocly/cli
redocly lint public/openapi.json
If the spec doesn't load, check:
specPath matches actual locationIf using a remote URL, ensure the API server sends proper CORS headers:
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET
For large specs (>5MB), consider:
Document different API versions using separate specs:
{
"openapi": {
"specPath": "public/openapi-v2.json"
}
}
Create version-specific pages:
content/
api-reference-v1/
endpoints/...
api-reference-v2/
endpoints/...
Add rich descriptions to all endpoints:
{
"paths": {
"/users": {
"get": {
"summary": "List users",
"description": "Retrieve a paginated list of users with optional filtering. Supports sorting by creation date, email, or username.",
"..."
}
}
}
}
Provide examples in your spec:
{
"components": {
"schemas": {
"User": {
"properties": {
"email": {
"type": "string",
"example": "user@example.com"
}
}
}
}
}
}
Document authentication requirements:
{
"components": {
"securitySchemes": {
"BearerAuth": {
"type": "http",
"scheme": "bearer"
}
}
}
}
Learn how to create API documentation pages with openapi frontmatter.
Explore interactive features like the "Try It" button and code generation.
Set up authentication for testing API endpoints.
Continue to Creating API Pages to start documenting your endpoints.