home / skills / ovachiever / droid-tings / api-documenter

api-documenter skill

/skills/api-documenter

This skill auto-generates OpenAPI/Swagger documentation from code changes, producing accurate API specs and examples to speed documentation and onboarding.

npx playbooks add skill ovachiever/droid-tings --skill api-documenter

Review the files below or copy the command above to add this skill to your agents.

Files (2)
SKILL.md
5.7 KB
---
name: api-documenter
description: Auto-generate API documentation from code and comments. Use when API endpoints change, or user mentions API docs. Creates OpenAPI/Swagger specs from code. Triggers on API file changes, documentation requests, endpoint additions.
allowed-tools: Read, Write, Grep
---

# API Documenter Skill

Auto-generate API documentation from code.

## When I Activate

- ✅ API endpoints added/modified
- ✅ User mentions API docs, OpenAPI, or Swagger
- ✅ Route files changed
- ✅ Controller files modified
- ✅ Documentation needed

## What I Generate

### OpenAPI 3.0 Specifications
- Endpoint descriptions
- Request/response schemas
- Authentication requirements
- Example payloads
- Error responses

### Formats Supported
- OpenAPI 3.0 (JSON/YAML)
- Swagger 2.0
- API Blueprint
- RAML

## Examples

### Express.js Endpoint

```javascript
// You write:
/**
 * Get user by ID
 * @param {string} id - User ID
 * @returns {User} User object
 */
app.get('/api/users/:id', async (req, res) => {
  const user = await User.findById(req.params.id);
  res.json(user);
});

// I auto-generate OpenAPI spec:
paths:
  /api/users/{id}:
    get:
      summary: Get user by ID
      parameters:
        - name: id
          in: path
          required: true
          description: User ID
          schema:
            type: string
      responses:
        '200':
          description: User found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/User'
              example:
                id: "123"
                name: "John Doe"
                email: "[email protected]"
        '404':
          description: User not found
```

### FastAPI Endpoint

```python
# You write:
@app.get("/users/{user_id}")
def get_user(user_id: int) -> User:
    """Get user by ID"""
    return db.query(User).filter(User.id == user_id).first()

// I auto-generate:
paths:
  /users/{user_id}:
    get:
      summary: Get user by ID
      parameters:
        - name: user_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/User'
```

### Complete OpenAPI Document

```yaml
openapi: 3.0.0
info:
  title: User API
  version: 1.0.0
  description: API for user management

servers:
  - url: https://api.example.com/v1

paths:
  /api/users:
    get:
      summary: List all users
      responses:
        '200':
          description: Users array
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/User'

components:
  schemas:
    User:
      type: object
      properties:
        id:
          type: string
        name:
          type: string
        email:
          type: string
          format: email
```

## Detection Logic

### Framework Detection

I recognize these frameworks automatically:
- **Express.js** (Node.js)
- **FastAPI** (Python)
- **Django REST** (Python)
- **Spring Boot** (Java)
- **Gin** (Go)
- **Rails** (Ruby)

### Comment Parsing

I extract documentation from:
- JSDoc comments (`/** */`)
- Python docstrings
- JavaDoc
- Inline comments with decorators

## Documentation Enhancement

### Missing Information

```javascript
// Your code:
app.post('/api/users', (req, res) => {
  User.create(req.body);
});

// I suggest additions:
/**
 * Create new user
 * @param {Object} req.body - User data
 * @param {string} req.body.name - User name (required)
 * @param {string} req.body.email - User email (required)
 * @returns {User} Created user
 * @throws {400} Invalid input
 * @throws {409} Email already exists
 */
```

### Example Generation

I generate realistic examples:

```json
{
  "id": "usr_1234567890",
  "name": "John Doe",
  "email": "[email protected]",
  "createdAt": "2025-10-24T10:30:00Z",
  "verified": true
}
```

## Relationship with @docs-writer

**Me (Skill):** Auto-generate API specs from code
**@docs-writer (Sub-Agent):** Comprehensive user guides and tutorials

### Workflow
1. I generate OpenAPI spec
2. You need user guide → Invoke **@docs-writer** sub-agent
3. Sub-agent creates complete documentation site

## Integration

### With Swagger UI

```javascript
// app.js
const swaggerUi = require('swagger-ui-express');
const spec = require('./openapi.json'); // Generated by skill

app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(spec));
```

### With Postman

Export generated OpenAPI spec:
```bash
# Import into Postman for API testing
File → Import → openapi.json
```

### With Documentation Sites

- **Docusaurus**: API docs plugin
- **MkDocs**: OpenAPI plugin
- **Redoc**: OpenAPI renderer
- **Stoplight**: API design platform

## Customization

Add company-specific documentation standards:

```bash
cp -r ~/.claude/skills/documentation/api-documenter \
      ~/.claude/skills/documentation/company-api-documenter

# Edit to add:
# - Company API standards
# - Custom response formats
# - Internal schemas
```

## Sandboxing Compatibility

**Works without sandboxing:** ✅ Yes
**Works with sandboxing:** ✅ Yes

- **Filesystem**: Writes OpenAPI files
- **Network**: None required
- **Configuration**: None required

## Best Practices

1. **Keep comments updated** - Documentation follows code
2. **Use type hints** - TypeScript, Python types help
3. **Include examples** - Real-world request/response
4. **Document errors** - All possible error responses
5. **Version your API** - Include version in endpoints

## Related Tools

- **@docs-writer sub-agent**: User guides and tutorials
- **readme-updater skill**: Keep README current
- **/docs-gen command**: Full documentation generation

Overview

This skill auto-generates API documentation and OpenAPI/Swagger specifications directly from code and comments. It detects route and controller changes, extracts docstrings and annotations, and produces complete API specs ready for Swagger UI, Postman, or documentation sites. Use it to keep API docs accurate when endpoints change or when documentation is requested.

How this skill works

The skill scans project files for recognized frameworks (Express, FastAPI, Django REST, Spring Boot, Gin, Rails) and parses JSDoc, Python docstrings, JavaDoc, and inline decorators. It maps routes, parameters, request/response schemas, auth requirements, examples, and error responses into OpenAPI/Swagger/RAML/API Blueprint outputs. It can also suggest missing documentation and realistic example payloads, then write the generated spec to a file for downstream tooling.

When to use it

  • After adding or modifying API endpoints or route files
  • When a stakeholder requests updated API docs or an OpenAPI spec
  • Before releasing a new API version to ensure docs match code
  • To generate docs for API testing tools like Postman or Swagger UI
  • When onboarding external developers who need machine-readable API specs

Best practices

  • Keep inline comments and docstrings up to date with code changes
  • Use type hints or typed languages (TypeScript, Python types) to improve schema accuracy
  • Include example request and response payloads for common cases
  • Document all expected error responses and status codes
  • Version your API and include the version in generated specs

Example use cases

  • Auto-generate OpenAPI 3.0 JSON/YAML from Express or FastAPI code after commits
  • Produce Swagger 2.0 or RAML for older tooling compatibility
  • Suggest enriched docstrings when a POST endpoint lacks parameter descriptions
  • Export a generated spec for import into Postman or rendering with Swagger UI
  • Integrate generated spec into a docs site (Redoc, Docusaurus, MkDocs)

FAQ

Which frameworks does this support?

It recognizes Express.js, FastAPI, Django REST, Spring Boot, Gin, and Rails automatically.

What output formats are available?

It can produce OpenAPI 3.0 (JSON/YAML), Swagger 2.0, API Blueprint, and RAML formats.