# API Documentation Components Reference Complete guide for documenting APIs with Mintlify using OpenAPI/AsyncAPI specs and API components. ## OpenAPI Integration ### Automatic Page Generation Use OpenAPI frontmatter to auto-generate API documentation from OpenAPI specs. ```mdx --- title: "Get User" openapi: "GET /users/{id}" --- ``` Mintlify automatically extracts: - Request parameters (path, query, header, body) - Request examples in multiple languages - Response schemas - Response examples - Authentication requirements ### OpenAPI Configuration Configure in `docs.json`: ```json { "api": { "openapi": "/openapi.yaml", "params": { "expanded": true }, "playground": { "display": "interactive", "proxy": "https://api.example.com" }, "examples": { "languages": ["bash", "python", "javascript", "go", "ruby", "php", "java"], "defaults": { "bash": "curl", "python": "requests" }, "prefill": { "apiKey": "your-api-key", "baseUrl": "https://api.example.com" }, "autogenerate": true } } } ``` **Configuration options:** - `openapi` - Path to OpenAPI spec file (YAML or JSON) - `params.expanded` - Expand parameter details by default - `playground.display` - API playground mode (interactive, simple, none) - `playground.proxy` - Proxy URL for API requests - `examples.languages` - Supported code example languages - `examples.defaults` - Default library per language - `examples.prefill` - Pre-fill values in examples - `examples.autogenerate` - Auto-generate examples from spec ### Multiple OpenAPI Specs ```json { "api": { "openapi": [ "/specs/v1.yaml", "/specs/v2.yaml" ] } } ``` ### OpenAPI Validation ```bash mint openapi-check ``` Validates OpenAPI specs for: - Syntax errors - Schema compliance - Missing required fields - Invalid references ## AsyncAPI Integration Document asynchronous APIs (WebSockets, message queues, event streams). ```json { "api": { "asyncapi": "/asyncapi.yaml" } } ``` Use in frontmatter: ```mdx --- title: "User Events" asyncapi: "subscribe user.created" --- ``` ## ParamField Component Document API parameters with detailed type information. ### Path Parameters ```mdx The unique identifier of the user The ID of the post to retrieve ``` ### Query Parameters ```mdx Page number for pagination (1-indexed) Number of items per page (max 100) Field to sort by Sort order (asc or desc) ``` ### Body Parameters ```mdx User's email address (must be unique) Full name of the user User's age (must be 18 or older) User preferences and settings ``` ### Header Parameters ```mdx Bearer token for authentication Format: `Bearer YOUR_API_KEY` Content type of the request body Unique identifier for request tracing ``` ### Enum Parameters ```mdx Filter users by account status ``` ### Array Parameters ```mdx Array of tag IDs to filter by Example: `?tags=1,2,3` Array of role identifiers to assign to the user ``` ### Nested Object Parameters ```mdx User's address information Street address City name State or province Postal/ZIP code ISO 3166-1 alpha-2 country code ``` ## ResponseField Component Document API response fields with type information. ### Basic Response Fields ```mdx Unique identifier of the user User's email address ISO 8601 timestamp of when the user was created Whether the user's email has been verified ``` ### Nested Response Objects ```mdx User information object User ID Full name Email address Extended profile information User biography Profile picture URL User's location ``` ### Array Responses ```mdx Array of user objects User ID User name Email address Pagination metadata Current page number Items per page Total number of items ``` ## Request Examples Show API request examples in multiple programming languages. ### Basic Request Example ```mdx ```bash cURL curl -X GET https://api.example.com/users/123 \ -H "Authorization: Bearer YOUR_API_KEY" ``` ```python Python import requests response = requests.get( "https://api.example.com/users/123", headers={"Authorization": "Bearer YOUR_API_KEY"} ) print(response.json()) ``` ```javascript JavaScript const response = await fetch("https://api.example.com/users/123", { method: "GET", headers: { "Authorization": "Bearer YOUR_API_KEY" } }); const data = await response.json(); console.log(data); ``` ```go Go package main import ( "fmt" "io" "net/http" ) func main() { client := &http.Client{} req, _ := http.NewRequest("GET", "https://api.example.com/users/123", nil) req.Header.Set("Authorization", "Bearer YOUR_API_KEY") resp, _ := client.Do(req) defer resp.Body.Close() body, _ := io.ReadAll(resp.Body) fmt.Println(string(body)) } ``` ``` ### POST Request with Body ```mdx ```bash cURL curl -X POST https://api.example.com/users \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "email": "user@example.com", "name": "John Doe", "age": 30 }' ``` ```python Python import requests data = { "email": "user@example.com", "name": "John Doe", "age": 30 } response = requests.post( "https://api.example.com/users", headers={"Authorization": "Bearer YOUR_API_KEY"}, json=data ) print(response.json()) ``` ```javascript JavaScript const data = { email: "user@example.com", name: "John Doe", age: 30 }; const response = await fetch("https://api.example.com/users", { method: "POST", headers: { "Authorization": "Bearer YOUR_API_KEY", "Content-Type": "application/json" }, body: JSON.stringify(data) }); const result = await response.json(); console.log(result); ``` ```ruby Ruby require 'net/http' require 'json' uri = URI('https://api.example.com/users') request = Net::HTTP::Post.new(uri) request['Authorization'] = 'Bearer YOUR_API_KEY' request['Content-Type'] = 'application/json' request.body = { email: 'user@example.com', name: 'John Doe', age: 30 }.to_json response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http| http.request(request) end puts response.body ``` ``` ## Response Examples Show API response examples for different scenarios. ### Success and Error Responses ```mdx ```json Success (200) { "id": "usr_abc123", "email": "user@example.com", "name": "John Doe", "created_at": "2024-01-15T10:30:00Z", "is_verified": true } ``` ```json Error (400) { "error": { "code": "validation_error", "message": "Invalid email format", "details": { "field": "email", "value": "invalid-email" } } } ``` ```json Error (401) { "error": { "code": "unauthorized", "message": "Invalid or expired API key" } } ``` ```json Error (404) { "error": { "code": "not_found", "message": "User with ID 'usr_abc123' not found" } } ``` ``` ### Paginated Response ```mdx ```json Success (200) { "data": [ { "id": "usr_001", "name": "Alice Smith", "email": "alice@example.com" }, { "id": "usr_002", "name": "Bob Jones", "email": "bob@example.com" } ], "meta": { "page": 1, "per_page": 10, "total": 45, "total_pages": 5 }, "links": { "first": "https://api.example.com/users?page=1", "last": "https://api.example.com/users?page=5", "next": "https://api.example.com/users?page=2", "prev": null } } ``` ``` ## API Playground Interactive API playground modes. ### Interactive Mode (default) Full interactive playground with request builder and live testing. ```json { "api": { "playground": { "display": "interactive" } } } ``` Features: - Live API requests from browser - Parameter input fields - Authentication management - Response preview - Copy as code snippets ### Simple Mode Simplified playground with basic request/response display. ```json { "api": { "playground": { "display": "simple" } } } ``` ### Disabled Playground Hide playground completely. ```json { "api": { "playground": { "display": "none" } } } ``` ### Playground Proxy Route API requests through proxy server (bypass CORS). ```json { "api": { "playground": { "proxy": "https://cors-proxy.example.com" } } } ``` ## Code Example Languages Configure supported languages for code examples. ```json { "api": { "examples": { "languages": [ "bash", "python", "javascript", "typescript", "go", "ruby", "php", "java", "swift", "csharp", "kotlin", "rust" ] } } } ``` ### Default Libraries Set default library/method per language. ```json { "api": { "examples": { "defaults": { "bash": "curl", "python": "requests", "javascript": "fetch", "go": "http" } } } } ``` ### Prefill Values Pre-fill common values in code examples. ```json { "api": { "examples": { "prefill": { "apiKey": "sk_test_abc123", "baseUrl": "https://api.example.com", "userId": "usr_example" } } } } ``` Values replace placeholders in examples: - `{apiKey}` → `sk_test_abc123` - `{baseUrl}` → `https://api.example.com` - `{userId}` → `usr_example` ### Auto-generate Examples Automatically generate code examples from OpenAPI spec. ```json { "api": { "examples": { "autogenerate": true } } } ``` ## SDK Integration ### Speakeasy SDK Integrate Speakeasy-generated SDKs. ```mdx --- title: "Create User" openapi: "POST /users" --- ```typescript TypeScript SDK import { SDK } from '@company/sdk'; const sdk = new SDK({ apiKey: 'YOUR_API_KEY' }); const user = await sdk.users.create({ email: 'user@example.com', name: 'John Doe' }); ``` ```python Python SDK from company_sdk import SDK sdk = SDK(api_key='YOUR_API_KEY') user = sdk.users.create( email='user@example.com', name='John Doe' ) ``` ``` ### Stainless SDK Integrate Stainless-generated SDKs. ```mdx ```typescript TypeScript SDK import { CompanyAPI } from 'company-api'; const client = new CompanyAPI({ apiKey: process.env.COMPANY_API_KEY }); const user = await client.users.create({ email: 'user@example.com', name: 'John Doe' }); ``` ``` ## Complete API Endpoint Example Full example of documented API endpoint. ```mdx --- title: "Create User" description: "Create a new user account" openapi: "POST /users" --- Creates a new user with the provided information. Email must be unique. ## Request User's email address (must be unique) Full name of the user User's password (minimum 8 characters) User's role in the system ## Response Unique identifier of the created user User's email address User's full name User's assigned role ISO 8601 timestamp of creation ```bash cURL curl -X POST https://api.example.com/users \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "email": "john@example.com", "name": "John Doe", "password": "SecurePass123", "role": "user" }' ``` ```python Python import requests response = requests.post( "https://api.example.com/users", headers={"Authorization": "Bearer YOUR_API_KEY"}, json={ "email": "john@example.com", "name": "John Doe", "password": "SecurePass123", "role": "user" } ) ``` ```json Success (201) { "id": "usr_abc123", "email": "john@example.com", "name": "John Doe", "role": "user", "created_at": "2024-01-15T10:30:00Z" } ``` ```json Error (400) { "error": { "code": "validation_error", "message": "Email already exists", "field": "email" } } ``` ```