api-doc-generator
Generate and validate API documentation from source code, route definitions, and existing endpoints. Use when a user asks to generate API docs, create OpenAPI specs, document endpoints, sync docs with code, detect documentation drift, or produce Swagger files from a codebase.
Usage
Getting Started
- Install the skill using the command above
- Open your AI coding agent (Claude Code, Codex, Gemini CLI, or Cursor)
- Reference the skill in your prompt
- The AI will use the skill's capabilities automatically
Example Prompts
- "Review the open pull requests and summarize what needs attention"
- "Generate a changelog from the last 20 commits on the main branch"
Documentation
Overview
Generates accurate API documentation by analyzing route definitions, controller logic, request/response types, and middleware chains in your codebase. Detects drift between existing docs and actual implementation, then produces updated OpenAPI 3.x specs.
Instructions
When asked to generate or update API documentation:
-
Identify the framework by scanning
package.json,requirements.txt,Gemfile,pom.xml, orgo.mod. -
Locate route definitions:
- Express/NestJS: scan for
router.get/post/put/delete,@Get()/@Post()decorators - FastAPI: scan for
@app.get,@router.postdecorators - Django REST: scan for
urlpatterns,ViewSetclasses - Rails: parse
config/routes.rb - Spring Boot: scan for
@RequestMapping,@GetMappingannotations
- Express/NestJS: scan for
-
Extract for each endpoint:
- HTTP method and path (including path parameters)
- Request body schema (from TypeScript types, Pydantic models, serializers, or annotations)
- Response schema and status codes
- Authentication requirements (middleware, decorators, guards)
- Query parameters and headers
-
If existing OpenAPI/Swagger spec exists:
- Parse it and compare against discovered endpoints
- Report added endpoints (in code but not in docs)
- Report removed endpoints (in docs but not in code)
- Report changed schemas (field additions, type changes, new required fields)
-
Generate output as a valid OpenAPI 3.0.x YAML document with:
- Proper
info,servers, andcomponents/schemassections - Realistic
examplevalues for every field - Error response schemas (400, 401, 403, 404, 500)
- Proper
-
Generate a human-readable changelog listing all differences found.
Examples
Example 1: Generate docs from Express app
Input:
Generate API documentation for this Express app in src/routes/
Output:
openapi: "3.0.3"
info:
title: User Management API
version: "2.1.0"
paths:
/api/users:
get:
summary: List users with pagination
parameters:
- name: page
in: query
schema:
type: integer
default: 1
- name: limit
in: query
schema:
type: integer
default: 20
responses:
"200":
description: Paginated user list
content:
application/json:
schema:
$ref: "#/components/schemas/UserListResponse"
example:
users:
- id: "usr_8f2k3j"
email: "maria@example.com"
role: "editor"
createdAt: "2025-11-03T14:22:00Z"
total: 847
page: 1
limit: 20
Example 2: Detect documentation drift
Input:
Compare our OpenAPI spec in docs/api.yaml against the actual routes in src/controllers/
Output:
Documentation Drift Report
===========================
3 endpoints added in code (missing from docs):
POST /api/users/bulk-import — src/controllers/users.ts:142
GET /api/users/:id/activity — src/controllers/users.ts:198
PUT /api/settings/notifications — src/controllers/settings.ts:55
1 endpoint removed from code (stale in docs):
DELETE /api/users/:id/avatar — last seen in git at commit a3f8c21
2 schema changes detected:
POST /api/users — added required field "organizationId" (string)
GET /api/users/:id — response now includes "lastLoginAt" (datetime, nullable)
Guidelines
- Always validate generated OpenAPI against the spec using structural checks before outputting.
- Use
$reffor shared schemas — never duplicate the same object definition. - Include authentication info (
securitySchemes) when auth middleware is detected. - Mark deprecated endpoints with
deprecated: trueinstead of removing them. - When unsure about a response type, inspect test files or integration tests for actual payloads.
- Prefer inferring types from TypeScript interfaces, Pydantic models, or serializer classes over guessing from raw handler code.
Information
- Version
- 1.0.0
- Author
- terminal-skills
- Category
- Development
- License
- Apache-2.0