Managing API Documentation
1. Generating OpenAPI Specifications
Example: OpenAPI 3.1 spec
openapi: 3.1.0
info:
title: Orders API
version: 2.0.0
servers:
- url: https://api.example.com/v2
paths:
/orders/{id}:
get:
summary: Get order
parameters:
- { name: id, in: path, required: true, schema: { type: string } }
responses:
"200":
description: OK
content:
application/json:
schema: { $ref: "#/components/schemas/Order" }
2. Configuring Swagger UI Integration
| Setting | Value |
|---|---|
| UI route | /docs |
| Spec URL | /openapi.json |
| Try-it-out | Enable for non-destructive |
| OAuth flow | Embed PKCE in UI |
| Theme | Custom CSS |
3. Using ReDoc Integration
| Aspect | vs Swagger UI |
|---|---|
| Layout | Three-column, read-focused |
| Search | Built-in, no plugin |
| Theming | Object-based config |
| Try-it-out | Pro version only |
4. Setting Up API Documentation Endpoints
| Endpoint | Returns |
|---|---|
/openapi.json | Spec (machine-readable) |
/openapi.yaml | YAML variant |
/docs | Swagger UI |
/redoc | ReDoc UI |
/.well-known/openapi | Discovery (proposed) |
5. Implementing Auto-Discovery
| Method | Detail |
|---|---|
| Code annotations | Spring @Operation, FastAPI types |
| Gateway introspection | Build spec from route configs |
| Service registry pull | Each service exposes its spec |
| Spectral lint | CI gates on schema quality |
6. Configuring Documentation Versioning
| Strategy | URL |
|---|---|
| Per major | /docs/v1, /docs/v2 |
| Switcher | Dropdown in UI |
| Git tags | Match spec to release tag |
| Changelog | Auto-diff between versions |
7. Using Markdown Documentation
| Use | Detail |
|---|---|
| Guides | Getting started, tutorials |
OpenAPI description | CommonMark supported |
| SDK pages | Per-language quickstart |
| Tools | Docusaurus, Mintlify, Mkdocs |
8. Setting Up Code Examples
Example: x-codeSamples in OpenAPI
paths:
/orders:
post:
x-codeSamples:
- lang: curl
source: |
curl -X POST https://api.example.com/orders \
-H "Authorization: Bearer $TOKEN" \
-d '{"sku":"abc","qty":1}'
- lang: javascript
source: |
const r = await fetch("/orders", {
method: "POST",
headers: { Authorization: `Bearer ${token}` },
body: JSON.stringify({ sku: "abc", qty: 1 })
});
9. Implementing Interactive Documentation
| Feature | Tool |
|---|---|
| Live console | Swagger UI, Postman |
| Auto-generated tokens | Dev portal sandbox |
| Embedded playground | GraphiQL, Apollo Sandbox |
| Mock responses | Prism, MockServer |
10. Configuring Documentation Access Control
| Audience | Visibility |
|---|---|
| Public APIs | Anonymous OK |
| Partner APIs | Login + NDA |
| Internal APIs | VPN or SSO |
| Beta features | x-internal: true filter |