API Documentation Generator
Produce a single .docx document describing a system's API contract in
enough detail that another team could integrate against it without asking
questions. If a machine-readable spec (OpenAPI/Swagger) already exists, this
document should summarize and link to it rather than duplicate every field —
the .docx is for human-readable context, conventions, and examples.
Sections (in this order)
Cover page, Version History, Document Approval, Revision Log, and TOC are
automatic — your sections array starts at "1. API Overview".
| # |
Section |
Content |
Diagram? |
| 1 |
API Overview |
Base URL(s), versioning scheme (e.g., /v1/), auth method, content-type conventions |
|
| 2 |
Authentication & Authorization |
How clients authenticate (API key, OAuth2, JWT), scopes/permissions model |
|
| 3 |
Endpoint Catalog |
Table: Method, Path, Description, Auth Required — the full list |
API Flow Diagram — a typical request's path through gateway/services |
| 4 |
Request & Response Schemas |
Key schemas per resource, or a link to the full OpenAPI spec if one exists |
|
| 5 |
Error Handling |
Standard error response format; table of error codes and meanings |
|
| 6 |
Rate Limiting & Throttling |
Limits per client/tier, headers used, behavior when exceeded |
|
| 7 |
Versioning & Deprecation Policy |
How breaking changes are introduced, deprecation notice period |
|
| 8 |
Webhooks / Callbacks |
If applicable: events, payload format, retry behavior |
|
| 9 |
Example Requests |
A few realistic curl or code examples covering common operations |
|
| 10 |
Appendix |
OpenAPI spec link, Postman collection link, related documents |
|
If the API has no webhooks/callbacks, keep the heading and mark it "Not
applicable for this API" rather than deleting the section — consistency
across generated documents matters more than omitting an empty section.
Diagram Policy
Applies to the .docx path only — Markdown embeds Mermaid source
directly instead of rendering anything (see "Output Format" below).
Prefer a real Mermaid diagram — rendered via mmdc and embedded with
B.diagramImage() — over diagramPlaceholder(), but only once you have
concrete structure to draw (real names, not "TBD"). Read
references/diagram-generation.md when you're actually about to render one
— it has the full build order, the bundled config
(assets/mermaid-config.json), the exact mmdc flags, and token-saving
tips. Skip it entirely if this document ends up needing no diagrams.
Missing Information Policy
Never invent endpoints, parameters, or response fields you have no basis for
— a fabricated field is actively harmful here, since another team may write
integration code against it. Use toBeCompleted("...") for endpoints or
sections you lack real input for, explaining what's needed (e.g., "point me
at the OpenAPI spec or route definitions"), and still generate everything
else.
Output Format
Ask the user which output format they want, unless they've already said so in
this request (e.g., "as a docx", "in markdown," "just give me an .md file") —
a quick single-choice question is enough, don't block on it otherwise:
Word document (.docx) — the default assumption if the person hasn't
specified and their context suggests a formal deliverable. Follow "Using
the builder" below.
Markdown (.md) — no script needed, write the file directly. Use these
conventions so it stays structurally equivalent to the docx version:
Front matter: instead of a cover page, open with the title as an #
heading, the project name as an italic subtitle line, then a metadata
table instead of separate Version History / Approval / Revision Log
tables:
# API Documentation
*Acme Order Platform*
| Field | Value |
|---|---|
| Version | 0.1 |
| Author | Jane Doe |
| Date | 2026-07-19 |
| Status | Draft |
| Approved By | Jane Doe (Tech Lead) |
Headings: #/##/###/#### matching the same section levels used in
the table above — don't flatten everything to one level, that's what
keeps the document skimmable and consistent with the docx version.
Tables: standard Markdown tables.
Diagrams — unlike the .docx path, don't render or embed an image here.
Write the actual Mermaid source directly in a fenced code block; GitHub,
GitLab, Obsidian, and most modern Markdown viewers render mermaid code
blocks natively, so this is a real diagram, not a placeholder:
```mermaid
flowchart TD
A[Client] --> B[API Gateway]
B --> C[Order Service]
C --> D[(Database)]
```
Only fall back to a text placeholder if you don't yet have concrete
enough detail to draw something real (mirrors toBeCompleted above):
> 📊 **DIAGRAM PLACEHOLDER — TO BE COMPLETED**
> Not enough detail yet to draw the System Architecture Diagram — need
> the actual component names and how they connect.
"To be completed" callout — same blockquote treatment:
> ⚠️ **TO BE COMPLETED**
> Explanation of what input is needed to fill this in.
Save as API_Documentation.md instead of API_Documentation.docx.
Workflow
Ask the output format first (see "Output Format" above). For Markdown, skip straight to writing the file using those conventions — the numbered steps below describe the .docx path.
- Gather what's available — ideally an OpenAPI/Swagger spec or the actual
route definitions in the codebase; otherwise ask for the endpoint list.
- Draft each section as data using the builder functions below.
- Build with
scripts/docx_builder.js.
- Skip PDF conversion by default —
docx_builder.js is already tested and
hardened (table widths and text alignment are enforced at the library
level), so routine generations don't need a re-render just to confirm it
worked. Only convert to PDF and view it if the user explicitly asks for
visual verification, or if something about this generation is unusual
(e.g., a new kind of content the library hasn't handled before, or a
reported rendering problem). When you do need it: soffice --headless --convert-to pdf <file>.docx (or libreoffice --headless ...), then
pdftoppm -jpeg -r 100 <file>.pdf page and view the images.
- Save to
/mnt/user-data/outputs/API_Documentation.docx (or .md if that's the chosen format) and present it.
Using the builder (for the .docx path)
This library requires the docx npm package. Before running any script,
check it's available with node -e "require('docx')"; if that fails, install
it with npm install docx in the working directory first — don't assume it's
pre-installed, since that varies by environment.
const B = require("./scripts/docx_builder.js");
const sections = [
B.h1("1. API Overview"),
B.para("Base URL: https://api.acme.com/v1/. All requests and responses use JSON. Auth via Bearer token."),
B.h1("3. Endpoint Catalog"),
B.table(["Method", "Path", "Description", "Auth Required"],
[
["GET", "/v1/orders", "List orders for the authenticated account", "Yes"],
["POST", "/v1/orders", "Create a new order", "Yes"],
],
[1300, 2600, 3600, 1700]),
// Prefer B.diagramImage(path, {caption}) with a real mmdc render when
// possible (see "Diagram Policy" above) — diagramPlaceholder() is the fallback:
B.diagramPlaceholder({
name: "API Flow Diagram",
purpose: "Show a typical request's path from client through gateway to backend services.",
recommendedContent: ["Client", "API Gateway", "Auth Service", "Order Service", "Database"],
}),
B.h1("5. Error Handling"),
B.table(["Code", "Meaning"], [["400", "Validation error — see `errors` array in response body"]], [1800, 7200]),
B.h1("7. Versioning & Deprecation Policy"),
B.toBeCompleted("Versioning/deprecation policy wasn't provided — ask whether the API follows a formal deprecation window."),
];
await B.buildDocument("/mnt/user-data/outputs/API_Documentation.docx", {
docLabel: "API Documentation",
title: "API Documentation",
subtitle: "Acme Order Platform",
versionHistory: [["0.1", "2026-07-19", "Jane Doe", "Initial draft"]],
approvers: [["Jane Doe", "Tech Lead", "", ""]],
revisionLog: [],
sections,
});
Available functions: h1/h2/h3/h4, para, bullets, table(headers, rows, widths), pageBreak, toBeCompleted(explanation),
diagramPlaceholder({name, purpose, recommendedContent, notes}), and
buildDocument(path, options). Always use heading functions for titles so
Word's Table of Contents and Navigation Pane work correctly.
Success Criteria
An engineer on a different team should be able to integrate against this API
using only this document — correct base URL, auth, endpoints, error format,
and enough examples to get a first successful call working.
1---2name: api-documentation-doc3description: Generate professional API Documentation as a formatted Word (.docx) file — API overview, authentication, endpoint catalog, request/response schemas, error handling, rate limiting, versioning, and example requests. Use this whenever someone asks for "API docs," "API reference," "endpoint documentation," or wants a standalone document describing a system's API contract (as distinct from the system's overall architecture or database schema, which have their own companion skills). Part of an enterprise handover documentation suite (see also: project-overview-doc, architecture-document, high-level-design, operations-deployment-guide, support-runbook, database-design, release-maintenance-guide) but fully usable standalone.4---56# API Documentation Generator78Produce a single `.docx` document describing a system's API contract in9enough detail that another team could integrate against it without asking10questions. If a machine-readable spec (OpenAPI/Swagger) already exists, this11document should summarize and link to it rather than duplicate every field —12the `.docx` is for human-readable context, conventions, and examples.1314## Sections (in this order)1516Cover page, Version History, Document Approval, Revision Log, and TOC are17automatic — your `sections` array starts at "1. API Overview".1819| # | Section | Content | Diagram? |20|---|---|---|---|21| 1 | API Overview | Base URL(s), versioning scheme (e.g., `/v1/`), auth method, content-type conventions | |22| 2 | Authentication & Authorization | How clients authenticate (API key, OAuth2, JWT), scopes/permissions model | |23| 3 | Endpoint Catalog | Table: Method, Path, Description, Auth Required — the full list | **API Flow Diagram** — a typical request's path through gateway/services |24| 4 | Request & Response Schemas | Key schemas per resource, or a link to the full OpenAPI spec if one exists | |25| 5 | Error Handling | Standard error response format; table of error codes and meanings | |26| 6 | Rate Limiting & Throttling | Limits per client/tier, headers used, behavior when exceeded | |27| 7 | Versioning & Deprecation Policy | How breaking changes are introduced, deprecation notice period | |28| 8 | Webhooks / Callbacks | If applicable: events, payload format, retry behavior | |29| 9 | Example Requests | A few realistic curl or code examples covering common operations | |30| 10 | Appendix | OpenAPI spec link, Postman collection link, related documents | |3132If the API has no webhooks/callbacks, keep the heading and mark it "Not33applicable for this API" rather than deleting the section — consistency34across generated documents matters more than omitting an empty section.3536## Diagram Policy3738**Applies to the `.docx` path only** — Markdown embeds Mermaid source39directly instead of rendering anything (see "Output Format" below).4041Prefer a real Mermaid diagram — rendered via `mmdc` and embedded with42`B.diagramImage()` — over `diagramPlaceholder()`, but only once you have43concrete structure to draw (real names, not "TBD"). Read44`references/diagram-generation.md` when you're actually about to render one45— it has the full build order, the bundled config46(`assets/mermaid-config.json`), the exact `mmdc` flags, and token-saving47tips. Skip it entirely if this document ends up needing no diagrams.4849## Missing Information Policy5051Never invent endpoints, parameters, or response fields you have no basis for52— a fabricated field is actively harmful here, since another team may write53integration code against it. Use `toBeCompleted("...")` for endpoints or54sections you lack real input for, explaining what's needed (e.g., "point me55at the OpenAPI spec or route definitions"), and still generate everything56else.5758## Output Format5960Ask the user which output format they want, unless they've already said so in61this request (e.g., "as a docx", "in markdown," "just give me an .md file") —62a quick single-choice question is enough, don't block on it otherwise:6364- **Word document (.docx)** — the default assumption if the person hasn't65 specified and their context suggests a formal deliverable. Follow "Using66 the builder" below.67- **Markdown (.md)** — no script needed, write the file directly. Use these68 conventions so it stays structurally equivalent to the docx version:6970 - Front matter: instead of a cover page, open with the title as an `#`71 heading, the project name as an italic subtitle line, then a metadata72 table instead of separate Version History / Approval / Revision Log73 tables:7475 ```markdown76 # API Documentation77 *Acme Order Platform*7879 | Field | Value |80 |---|---|81 | Version | 0.1 |82 | Author | Jane Doe |83 | Date | 2026-07-19 |84 | Status | Draft |85 | Approved By | Jane Doe (Tech Lead) |86 ```87 - Headings: `#`/`##`/`###`/`####` matching the same section levels used in88 the table above — don't flatten everything to one level, that's what89 keeps the document skimmable and consistent with the docx version.90 - Tables: standard Markdown tables.91 - Diagrams — unlike the `.docx` path, don't render or embed an image here.92 Write the actual Mermaid source directly in a fenced code block; GitHub,93 GitLab, Obsidian, and most modern Markdown viewers render `mermaid` code94 blocks natively, so this is a real diagram, not a placeholder:9596 ````markdown97 ```mermaid98 flowchart TD99 A[Client] --> B[API Gateway]100 B --> C[Order Service]101 C --> D[(Database)]102 ```103 ````104 Only fall back to a text placeholder if you don't yet have concrete105 enough detail to draw something real (mirrors `toBeCompleted` above):106 ```markdown107 > 📊 **DIAGRAM PLACEHOLDER — TO BE COMPLETED**108 > Not enough detail yet to draw the System Architecture Diagram — need109 > the actual component names and how they connect.110 ```111 - "To be completed" callout — same blockquote treatment:112113 ```markdown114 > ⚠️ **TO BE COMPLETED**115 > Explanation of what input is needed to fill this in.116 ```117 - Save as `API_Documentation.md` instead of `API_Documentation.docx`.118119## Workflow120121Ask the output format first (see "Output Format" above). For Markdown, skip straight to writing the file using those conventions — the numbered steps below describe the `.docx` path.1221231. Gather what's available — ideally an OpenAPI/Swagger spec or the actual124 route definitions in the codebase; otherwise ask for the endpoint list.1252. Draft each section as data using the builder functions below.1263. Build with `scripts/docx_builder.js`.1274. Skip PDF conversion by default — `docx_builder.js` is already tested and128 hardened (table widths and text alignment are enforced at the library129 level), so routine generations don't need a re-render just to confirm it130 worked. Only convert to PDF and view it if the user explicitly asks for131 visual verification, or if something about this generation is unusual132 (e.g., a new kind of content the library hasn't handled before, or a133 reported rendering problem). When you do need it: `soffice --headless134 --convert-to pdf <file>.docx` (or `libreoffice --headless ...`), then135 `pdftoppm -jpeg -r 100 <file>.pdf page` and view the images.1365. Save to `/mnt/user-data/outputs/API_Documentation.docx` (or `.md` if that's the chosen format) and present it.137138## Using the builder (for the .docx path)139140This library requires the `docx` npm package. Before running any script,141check it's available with `node -e "require('docx')"`; if that fails, install142it with `npm install docx` in the working directory first — don't assume it's143pre-installed, since that varies by environment.144145```javascript146const B = require("./scripts/docx_builder.js");147148const sections = [149 B.h1("1. API Overview"),150 B.para("Base URL: https://api.acme.com/v1/. All requests and responses use JSON. Auth via Bearer token."),151152 B.h1("3. Endpoint Catalog"),153 B.table(["Method", "Path", "Description", "Auth Required"],154 [155 ["GET", "/v1/orders", "List orders for the authenticated account", "Yes"],156 ["POST", "/v1/orders", "Create a new order", "Yes"],157 ],158 [1300, 2600, 3600, 1700]),159160 // Prefer B.diagramImage(path, {caption}) with a real mmdc render when161 // possible (see "Diagram Policy" above) — diagramPlaceholder() is the fallback:162 B.diagramPlaceholder({163 name: "API Flow Diagram",164 purpose: "Show a typical request's path from client through gateway to backend services.",165 recommendedContent: ["Client", "API Gateway", "Auth Service", "Order Service", "Database"],166 }),167168 B.h1("5. Error Handling"),169 B.table(["Code", "Meaning"], [["400", "Validation error — see `errors` array in response body"]], [1800, 7200]),170171 B.h1("7. Versioning & Deprecation Policy"),172 B.toBeCompleted("Versioning/deprecation policy wasn't provided — ask whether the API follows a formal deprecation window."),173];174175await B.buildDocument("/mnt/user-data/outputs/API_Documentation.docx", {176 docLabel: "API Documentation",177 title: "API Documentation",178 subtitle: "Acme Order Platform",179 versionHistory: [["0.1", "2026-07-19", "Jane Doe", "Initial draft"]],180 approvers: [["Jane Doe", "Tech Lead", "", ""]],181 revisionLog: [],182 sections,183});184```185186Available functions: `h1`/`h2`/`h3`/`h4`, `para`, `bullets`, `table(headers,187rows, widths)`, `pageBreak`, `toBeCompleted(explanation)`,188`diagramPlaceholder({name, purpose, recommendedContent, notes})`, and189`buildDocument(path, options)`. Always use heading functions for titles so190Word's Table of Contents and Navigation Pane work correctly.191192## Success Criteria193194An engineer on a different team should be able to integrate against this API195using only this document — correct base URL, auth, endpoints, error format,196and enough examples to get a first successful call working.