Logo

Getting Started

IntroductionInstallationQuick Start
Logo
DocumentationAPI ReferenceChangelog

OpenAPI

OpenAPI Setup

Configure OpenAPI specification for automatic API documentation

Overview

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.

What You Get

When configured, OpenAPI integration provides:

  • Automatic parameter documentation
  • Request body schemas with examples
  • Response schemas for all status codes
  • Interactive "Try It" button
  • Code generation in 7+ languages
  • Authentication handling
  • Schema visualization

Quick Setup

1

Add OpenAPI Specification

Place your OpenAPI JSON file in the public/ directory:

# Download or copy your OpenAPI spec
cp openapi.json public/openapi.json

Or use a remote URL.

2

Configure Path

Update config/docs.config.ts:

{
  "openapi": {
    "specPath": "public/openapi.json"
  }
}
3

Create API Page

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...
4

Restart Server

Restart the development server to load the spec:

bun dev

OpenAPI Spec Location

Local File

Store the spec in your project:

{
  "openapi": {
    "specPath": "public/openapi.json"
  }
}

Directory structure:

public/
  static/
    openapi.json

Remote URL

Reference a hosted specification:

{
  "openapi": {
    "specPath": "https://api.example.com/openapi.json"
  }
}

Benefits:

  • Always up-to-date with API changes
  • No need to commit large spec files
  • Shared across multiple documentation sites

OpenAPI Specification Format

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": {...}
  }
}

Configuration Options

openapi.specPath
stringrequired

Path to OpenAPI specification file (local or remote URL).

Local file:

"specPath": "public/openapi.json"

Remote URL:

"specPath": "https://api.example.com/spec.json"

Validating Your Spec

Before using your spec, validate it:

Online Validators

  • Swagger Editor - Paste and validate
  • OpenAPI.tools - Validation tools

CLI Validation

# 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

Common Issues

Spec Not Loading

If the spec doesn't load, check:

  1. File path - Verify specPath matches actual location
  2. Valid JSON - Ensure proper JSON syntax
  3. OpenAPI version - Use OpenAPI 3.0+
  4. Server restart - Restart dev server after config changes

CORS Issues with Remote Specs

If using a remote URL, ensure the API server sends proper CORS headers:

Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET

Large Spec Files

For large specs (>5MB), consider:

  1. Splitting into multiple smaller specs
  2. Hosting remotely and using URL
  3. Removing unused schemas/paths

Multiple API Versions

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/...

Best Practices

Keep Spec Updated

  • Automated: Generate spec from code (code-first approach)
  • Version control: Commit spec to repository
  • CI/CD: Validate spec in pipeline

Use Descriptions

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.",
        "..."
      }
    }
  }
}

Include Examples

Provide examples in your spec:

{
  "components": {
    "schemas": {
      "User": {
        "properties": {
          "email": {
            "type": "string",
            "example": "user@example.com"
          }
        }
      }
    }
  }
}

Define Security Schemes

Document authentication requirements:

{
  "components": {
    "securitySchemes": {
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer"
      }
    }
  }
}

Next Steps

1

Create API Pages

Learn how to create API documentation pages with openapi frontmatter.

2

Interactive Features

Explore interactive features like the "Try It" button and code generation.

3

Configure Authentication

Set up authentication for testing API endpoints.


Continue to Creating API Pages to start documenting your endpoints.

Built with Chakra UI

On this page
OverviewWhat You GetQuick SetupOpenAPI Spec LocationLocal FileRemote URLOpenAPI Specification FormatConfiguration OptionsValidating Your SpecOnline ValidatorsCLI ValidationCommon IssuesSpec Not LoadingCORS Issues with Remote SpecsLarge Spec FilesMultiple API VersionsBest PracticesKeep Spec UpdatedUse DescriptionsInclude ExamplesDefine Security SchemesNext Steps