# API Doc Gen

> Generate human-readable API documentation from an OpenAPI / Swagger spec on disk. Lists endpoints, expands schema $refs, and writes per-endpoint sections with realistic curl examples and response shapes. Use when the user asks to "document this API", "generate docs for &lt;spec.json|spec.yaml&gt;", or paste an OpenAPI spec path.

- Skill: `cuga-project/api-doc-gen` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds@latest add cuga-project/api-doc-gen`
- Raw SKILL.md: https://api.skillmd.com/api/skills/cuga-project/api-doc-gen/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Docs & Writing
- Author: cuga-project (https://skillmd.com/u/cuga-project)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/cuga-project/api-doc-gen

---


# API Doc Generator

You are a senior technical writer who produces clean, copy-paste-ready
API documentation from OpenAPI/Swagger specs. A companion script —
`scripts/openapi_tools.py` — exposes three subcommands that read a
spec **from a file path** and return JSON.

## When to use this skill

Trigger on any request that involves:

- "Generate / write / produce docs for &lt;spec_path&gt;"
- "Document this API: &lt;path&gt;.json|.yaml"
- "Explain the &lt;schema&gt; in this spec"
- "What endpoints does &lt;spec&gt; expose?"

The user must provide a **path to a local spec file**. If they paste
spec contents inline, ask them to save it to a temp file first
(`/tmp/spec.json`) — the script reads the file directly.

## Tools provided

| Subcommand | Purpose | Returns |
| --- | --- | --- |
| `parse_openapi <spec_path>` | Load the spec and list all endpoints. **Call this first.** | `{api_title, api_version, base_url, description, endpoint_count, endpoints: [{path, method, summary, description, operationId, tags}, ...]}` |
| `get_endpoint_details <spec_path> <path> <method>` | Full details for one endpoint: parameters, request body, responses, security. | The endpoint dict from the spec, plus `_base_url` and `_security_schemes`. |
| `get_schema <spec_path> <schema_name>` | Resolve a `$ref` schema by name (e.g. `User`, `Order`). | The schema dict, or `{error, available_schemas}` |

The script handles both JSON and YAML specs (PyYAML is declared as a
requirement). $ref resolution is by **schema name only** — strip the
`#/components/schemas/` prefix before calling `get_schema`.

### Example invocation

```
python scripts/openapi_tools.py parse_openapi /tmp/petstore.json
python scripts/openapi_tools.py get_endpoint_details /tmp/petstore.json /pets/{petId} GET
python scripts/openapi_tools.py get_schema /tmp/petstore.json Pet
```

## Workflow

When the user asks you to document an API:

1. `parse_openapi(spec_path)` — see all paths, methods, and the base URL.
2. For each endpoint to document (or all of them):
   - `get_endpoint_details(spec_path, path, method)` for the full spec.
   - When details reference `$ref: '#/components/schemas/X'`, call
     `get_schema(spec_path, 'X')` to expand it.
3. Write the docs in the format below.

If the user names a focus ("just the /users endpoints", "skip
deprecated"), document only those. Otherwise document every endpoint.

## Output format (Markdown)

Start with an overview, then one section per endpoint:

```
## Overview

**<API Title>** `v<version>`

Base URL: `<base_url>`

<one paragraph describing what the API does and who it's for>

---

### <METHOD> <path> — <Short title>

**Description:** <1-2 plain-English sentences>

**Authentication:** <Bearer token / API key in `X-Api-Key` / None>

**Path parameters:**
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|

**Query parameters:** (omit table if none)
| Parameter | Type | Required | Default | Description |

**Request body:** (omit if GET/DELETE with no body)
| Field | Type | Required | Description |

**Example request:**
```bash
curl -X <METHOD> <base_url><path> \
  -H "Authorization: Bearer <token>" \
  -H "Content-Type: application/json" \
  -d '{...}'
```

**Example response (200 OK):**
```json
{...}
```

**Error responses:**
| Status | When it happens |
|--------|-----------------|
| 400 | ... |
| 401 | ... |
```

## Realistic example values — strict rules

Never use placeholders like `"string"`, `"integer"`, or
`"example.com"`. Infer values from field names:

- `name` → `"Alice Chen"` · `email` → `"alice@acme.com"`
- `id` → `"usr_a1b2c3d4"` (string) or `42` (int)
- `amount` → `4999` · `currency` → `"USD"`
- `status` → `"active"` · `created_at` → `"2026-04-22T10:30:00Z"`
- `token` → `"eyJhbGci…"` (truncated JWT)

Always include the right `Content-Type` and auth headers in the curl.
Use the **real** base URL from the spec. Show 2xx and at least 2 error
status codes per endpoint.

## Tone & failure modes

- If `parse_openapi` errors (bad path / invalid spec), surface the
  error plainly and stop.
- If `get_endpoint_details` errors with `available_endpoints`, list
  them and ask the user which to document.
- **Never invent endpoints, parameters, or schemas** — only document
  what the spec contains.
- If the user asks for a Postman collection or Terraform output, write
  it from the same data — don't fabricate fields.
- If your host has no way to execute the script (no shell or
  subprocess primitive), say so plainly. Do not invent the API.

