API reference documentation skill. Produces and updates API endpoint documentation from contract files in .sdd/docs/api-reference.md.
Installation
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
API reference documentation skill. Produces and updates API endpoint documentation from contract files in .sdd/docs/api-reference.md.
argument-hint
Invoked by Docs Agent Coordinator - do not call directly
doc-api-reference - API Reference Documentation Skill
This skill is invoked by the Docs Agent Coordinator as a subagent. It produces and updates .sdd/docs/api-reference.md with endpoint documentation generated from contract files. API docs are generated from contract files (api-contracts.<ext>, error-catalog.<ext>), NOT from prose interpretation. Contract files are the source of truth.
Input Contract (FR-005)
This skill receives the following 7 inputs via the coordinator's subagent prompt, as defined in DOC-SKILL-CONTRACT.md:
#
Input
Type
Description
1
skill_path
Path
Path to this SKILL.md file
2
wp_path
Path
Path to the approved WP file and its task list
3
spec_path
Path
Path to the spec file; includes contract files directory (.sdd/plans/contracts/<WP-slug>/)
4
source_files
List(Path)
Implementation source files modified by the WP
5
docs_dir
Path
Path to existing documentation directory (.sdd/docs/) for incremental updates
6
patterns
Text
Active doc-domain patterns to avoid (from .sdd/reviews/doc-patterns.md)
7
contracts_dir
Path
Path to contract files for this WP (.sdd/plans/contracts/<WP-slug>/)
Output Contract
Field
Value
Target file
.sdd/docs/api-reference.md
Action
Create if missing; update incrementally if existing
Content
One section per API endpoint with method, path, description, request/response schemas, error codes, auth requirements, and examples
Execution Sequence (FR-006)
Read SKILL.md -- Load this file for documentation generation instructions
Read existing docs -- Read .sdd/docs/api-reference.md if it exists to understand current content
Read source material -- Read contract files (api-contracts.<ext>, error-catalog.<ext>), WP file, and spec for context. Read multiple independent files in parallel via concurrent tool calls.
Write documentation -- Update or create .sdd/docs/api-reference.md incrementally (do NOT recreate from scratch)
Constraints
Do NOT modify spec files, plan files, contract files, or implementation source files
Do NOT recreate api-reference.md from scratch on incremental updates -- preserve existing content
Do NOT generate API docs from spec prose -- contract files are the source of truth (FR-013)
Use plain ASCII only -- no em dashes, smart quotes, or curly apostrophes
Follow the canonical section order defined below
Contract File Discovery (FR-013)
Before generating API documentation, discover and validate the contract files for the current WP.
Discovery Sequence
Determine the WP slug from the WP filename (e.g., WP03-review-spec.md has slug review-spec)
Check for a contracts directory at .sdd/plans/contracts/<WP-slug>/
Scan for these contract file types:
api-contracts.<ext> -- API endpoint definitions (paths, methods, request/response types)
error-catalog.<ext> -- Error codes, messages, HTTP status codes
data-schemas.<ext> -- Entity/model definitions (referenced by request/response types)
The <ext> matches the target language (e.g., .ts, .py, .go, .rs)
No Contracts Handling (FR-013 Error)
If no contract files exist for the WP:
Log: "No contract files found for WP in .sdd/plans/contracts/<WP-slug>/. Skipping API doc generation."
Do NOT fall back to generating API docs from spec prose
Do NOT generate placeholder or stub API documentation
Exit the skill cleanly with no changes to api-reference.md
Contract Parsing by Language
Contract files may use different programming languages depending on the project. The skill must handle the target language's syntax for type and endpoint definitions.
TypeScript Contracts
Read TypeScript interfaces, types, and endpoint definitions:
Generate one section per API endpoint found in the contract files.
Instructions
Read api-contracts.<ext> from the contracts directory
For each endpoint defined (identified by method + path comments, route decorators, or type naming conventions):
a. Extract the HTTP method (GET, POST, PUT, PATCH, DELETE)
b. Extract the URL path (e.g., /api/users, /api/users/:id)
c. Write a brief description of the endpoint's purpose (from type names and spec context)
Create a subsection for each endpoint using the format below
Output Format
# API Reference## POST /api/users
Create a new user account.
Section 2 -- Request Parameters and Body (FR-012.4)
Document request parameters and body from contract type definitions.
Instructions
For each endpoint, identify the input/request type from the contract file
Extract all fields with their names, types, required/optional status, and constraints
Distinguish between:
Path parameters: Parameters in the URL path (e.g., :id in /users/:id)
Query parameters: Parameters passed as query strings
Request body: JSON body fields from the input type definition
For union types or enums, list all valid values
Output Format
### Request**Body** (`application/json`):
| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `email` | string | Yes | User email address |
| `name` | string | Yes | User display name |
| `role` | string | Yes | One of: `admin`, `user` |
Section 3 -- Response Schema (FR-012.5)
Document response schemas from contract type definitions.
Instructions
For each endpoint, identify the output/response type from the contract file
Extract all fields with their names, types, and descriptions
Document the success response (typically 200 or 201)
Note the response content type (typically application/json)
Output Format
### Response**Success** (`200 OK`):
| Field | Type | Description |
|-------|------|-------------|
| `id` | string | Unique user identifier |
| `email` | string | User email address |
| `name` | string | User display name |
| `role` | string | User role |
| `createdAt` | string | ISO 8601 creation timestamp |
Section 4 -- Error Codes (FR-012.6)
Document error codes and meanings from the error catalog contract.
Instructions
Read error-catalog.<ext> from the contracts directory
For each error code relevant to the endpoint:
a. Extract the error code identifier
b. Extract the HTTP status code
c. Extract the error message or description
Group errors by endpoint where possible
Include a general errors section for errors that apply across all endpoints (e.g., 401 Unauthorized, 500 Internal Server Error)
Output Format
### Errors
| Status | Code | Description |
|--------|------|-------------|
| 400 | `VALIDATION_ERROR` | Request body failed validation |
| 404 | `USER_NOT_FOUND` | No user exists with the given ID |
| 409 | `EMAIL_ALREADY_EXISTS` | A user with this email already exists |
API documentation SHALL be generated from contract files, NOT from prose interpretation. These rules enforce that contract files are the single source of truth.
Context only: Spec file -- used only to understand the purpose and context of endpoints, NOT to determine field names, types, or structures
NEVER a source: Prose descriptions, user stories, or acceptance scenarios -- these are informational and must never override contract definitions
Accuracy Rules
Field names match contracts exactly -- If the contract defines createdAt, the docs use createdAt, not created_at or dateCreated
Types match contracts exactly -- If the contract defines email: string, the docs show type string, not email address or varchar
Required/optional matches contracts -- If a field has ? (TypeScript), Optional (Python), or omitempty (Go), it is optional in the docs
Enum values match contracts -- If the contract defines role: "admin" | "user", the docs list exactly admin and user, not additional values
Error codes match error catalog -- Error identifiers, HTTP status codes, and messages come from error-catalog.<ext>, not invented
Endpoint paths match contracts -- URL paths come from route decorators, comments, or naming conventions in the contract files
Violation Detection
If a discrepancy is detected between the spec prose and the contract files:
Always use the contract file's definition
Add a note: <!-- Note: spec describes <X> but contract defines <Y>. Using contract definition. -->
Do NOT attempt to reconcile or merge the two sources
Incremental Update Protocol (FR-011)
When api-reference.md already exists with content from prior work packages:
Rules
Read before write -- Always read the existing api-reference.md content before making any changes
Identify endpoints by heading -- Use endpoint headings (e.g., ## POST /api/users) to locate existing endpoint sections
Update existing endpoints -- If the current WP modifies an existing endpoint (changes fields, adds parameters), update that endpoint's section in place
Add new endpoints -- If the current WP adds new endpoints, append new endpoint sections after existing ones
Preserve unmodified endpoints -- Endpoint sections not affected by the current WP SHALL remain unchanged
Remove deprecated endpoints -- If the current WP removes an endpoint (marked deprecated in contracts), add a deprecation notice rather than deleting the section
Incremental Update Sequence
Read existing api-reference.md into memory
Parse into sections by ## endpoint headings
For each endpoint in the current WP's contracts:
a. If the endpoint exists in the docs, update its section with current contract data
b. If the endpoint is new, create a new section with all subsections (request, response, errors, auth, example)
For endpoints in the docs but not in the current WP's contracts, leave them unchanged
Write the updated content back to api-reference.md
Error Handling
If api-reference.md does not exist, create it from scratch with an # API Reference heading and all endpoint sections
If an endpoint section has non-standard formatting, preserve it and add a <!-- Format note: this section uses non-standard formatting --> comment
Quality Checklist
Before completing, verify:
Every endpoint has method, path, and description (FR-012.1, FR-012.2, FR-012.3)
Request parameters/body match contract type definitions exactly (FR-012.4)
Response schemas match contract type definitions exactly (FR-012.5)
Error codes come from error-catalog contract, not invented (FR-012.6)
Authentication requirements are documented per endpoint (FR-012.7)
Example request/response pairs are valid JSON matching schemas (FR-012.8)
All field names, types, and enum values match contracts exactly (FR-013)
No API docs generated from prose -- contracts are the sole source (FR-013)
If no contracts exist, skill skipped cleanly with a log message (FR-013 error)