home / skills / physics91 / claude-vibe / api-documenter

api-documenter skill

/skills/api-documenter

This skill automatically generates API documentation from JSDoc/TSDoc comments, React Props, and Markdown, enhancing code documentation and Storybook readiness.

npx playbooks add skill physics91/claude-vibe --skill api-documenter

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

Files (1)
SKILL.md
6.4 KB
---
name: api-documenter
description: |
  WHEN: API documentation, JSDoc/TSDoc comments, Props documentation, Storybook story writing
  WHAT: Function/class/type JSDoc + React Props table + Markdown API docs + Storybook stories
  WHEN NOT: README writing → readme-generator, Code explanation → code-reviewer
---

# API Documenter Skill

## Purpose
Automatically generates API documentation for code including functions, components, and types with JSDoc/TSDoc comments.

## When to Use
- "API docs", "jsdoc", "documentation" requests
- Component Props documentation needed
- Adding comments to functions/classes
- Storybook story generation

## Workflow

### Step 1: Select Documentation Target
**AskUserQuestion:**
```
"What code to document?"
Options:
- Specific file/function
- Undocumented export functions
- React component Props
- All public APIs
```

### Step 2: Select Documentation Type
**AskUserQuestion:**
```
"What format to generate?"
Options:
- JSDoc/TSDoc comments
- Markdown API docs
- Storybook stories
- All of the above
multiSelect: true
```

## Documentation Templates

### JSDoc/TSDoc Comments

**Function:**
```typescript
/**
 * Formats user data for display.
 *
 * @param user - User object to format
 * @param options - Formatting options
 * @param options.locale - Locale setting (default: 'en-US')
 * @param options.includeAge - Include age (default: false)
 *
 * @returns Formatted user string
 *
 * @example
 * ```typescript
 * const formatted = formatUser({ name: 'John', age: 30 })
 * // Returns: 'John'
 *
 * const withAge = formatUser({ name: 'John', age: 30 }, { includeAge: true })
 * // Returns: 'John (30)'
 * ```
 *
 * @throws {ValidationError} When user object is invalid
 * @see {@link User} User type definition
 * @since 1.0.0
 */
export function formatUser(user: User, options?: FormatOptions): string
```

**Interface:**
```typescript
/**
 * User information interface
 *
 * @interface User
 * @property {string} id - Unique identifier (UUID)
 * @property {string} name - User name
 * @property {string} email - Email address
 * @property {number} [age] - Age (optional)
 * @property {UserRole} role - User role
 */
interface User {
  id: string
  name: string
  email: string
  age?: number
  role: UserRole
}
```

**Class:**
```typescript
/**
 * API client for REST communication
 *
 * @class ApiClient
 * @example
 * ```typescript
 * const client = new ApiClient({ baseUrl: 'https://api.example.com' })
 * const users = await client.get<User[]>('/users')
 * ```
 */
class ApiClient {
  /**
   * Creates ApiClient instance
   * @param config - Client configuration
   */
  constructor(config: ApiClientConfig) {}

  /**
   * Performs GET request
   * @template T - Response type
   * @param endpoint - API endpoint
   * @returns Response data
   */
  async get<T>(endpoint: string): Promise<T> {}
}
```

### React Component Documentation

**Props Interface:**
```typescript
/**
 * Button component Props
 */
interface ButtonProps {
  /** Button content */
  children: React.ReactNode

  /** Style variant @default 'primary' */
  variant?: 'primary' | 'secondary' | 'outline' | 'ghost'

  /** Button size @default 'medium' */
  size?: 'small' | 'medium' | 'large'

  /** Disabled state @default false */
  disabled?: boolean

  /** Loading state @default false */
  loading?: boolean

  /** Click event handler */
  onClick?: (event: React.MouseEvent<HTMLButtonElement>) => void
}

/**
 * Button component with various styles and sizes
 *
 * @component
 * @example
 * ```tsx
 * <Button onClick={handleClick}>Click me</Button>
 * <Button variant="secondary" size="large">Large Button</Button>
 * <Button loading disabled>Processing...</Button>
 * ```
 */
export function Button({ children, variant = 'primary', ...props }: ButtonProps)
```

### Markdown API Docs
```markdown
## formatUser

Formats user data for display.

### Signature
\`\`\`typescript
function formatUser(user: User, options?: FormatOptions): string
\`\`\`

### Parameters
| Parameter | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| `user` | `User` | Yes | - | User object to format |
| `options.locale` | `string` | No | `'en-US'` | Locale setting |

### Returns
`string` - Formatted user string

### Example
\`\`\`typescript
const formatted = formatUser({ name: 'John', age: 30 })
\`\`\`
```

### Storybook Stories
```typescript
import type { Meta, StoryObj } from '@storybook/react'
import { Button } from './Button'

const meta: Meta<typeof Button> = {
  title: 'Components/Button',
  component: Button,
  tags: ['autodocs'],
  argTypes: {
    variant: {
      control: 'select',
      options: ['primary', 'secondary', 'outline', 'ghost'],
    },
    size: {
      control: 'select',
      options: ['small', 'medium', 'large'],
    },
  },
}

export default meta
type Story = StoryObj<typeof Button>

/** Default button style */
export const Default: Story = {
  args: { children: 'Button', variant: 'primary' },
}

/** Primary variant for main actions */
export const Primary: Story = {
  args: { children: 'Primary', variant: 'primary' },
}

/** Various sizes */
export const Sizes: Story = {
  render: () => (
    <div style={{ display: 'flex', gap: '1rem' }}>
      <Button size="small">Small</Button>
      <Button size="medium">Medium</Button>
      <Button size="large">Large</Button>
    </div>
  ),
}
```

## Response Template
```
## API Documentation Generated

**Target**: src/components/Button.tsx

### JSDoc Comments
- ButtonProps interface: 7 properties documented
- Button component: Fully documented

### Markdown Docs
- File: docs/components/Button.md
- Sections: Props, Usage, Accessibility

### Storybook
- File: src/components/Button.stories.tsx
- Stories: 6 (Default, Primary, Secondary, Sizes, Loading, Disabled)

### Statistics
| Item | Count |
|------|-------|
| Documented Props | 7 |
| Code Examples | 5 |
| Stories | 6 |
```

## Best Practices
1. **Consistent Style**: Same documentation style across project
2. **Include Examples**: Usage examples for all public APIs
3. **Type Accuracy**: Match TypeScript types with documentation
4. **Keep Updated**: Update docs when code changes
5. **Accessibility Info**: Include a11y information for components

## Integration
- `readme-generator` skill: README API section
- `/explain-code` command: Code understanding
- `code-reviewer` skill: Documentation quality check

## Notes
- Merges or overwrites if existing docs present
- Auto-infers from TypeScript types
- Excludes @internal tagged code

Overview

This skill automatically generates API documentation for TypeScript projects, covering functions, classes, types, React props, Markdown API pages, and Storybook stories. It produces JSDoc/TSDoc comments, props tables, Markdown docs, and ready-to-use Storybook stories while respecting @internal tags and existing docs. The output is designed to be copy-paste friendly and to integrate with existing codebases without changing runtime behavior.

How this skill works

Point the tool at one or more targets (a file, an export, undocumented exports, or all public APIs). It parses TypeScript types and signatures, infers defaults and parameter shapes, then emits JSDoc/TSDoc comments, Markdown API pages, and Storybook story files based on selectable templates. It can merge with or overwrite existing documentation and skips symbols tagged @internal.

When to use it

  • Add or fill JSDoc/TSDoc for functions, classes, and interfaces
  • Generate component Props tables and inline comments for React components
  • Create Markdown API documentation for a docs site
  • Auto-generate Storybook stories and argTypes for visual testing
  • Document undocumented exported functions or all public API surfaces

Best practices

  • Select the minimal target first (single file or symbol) to review output before bulk runs
  • Include usage examples and expected errors for public APIs
  • Keep TypeScript types accurate so inferred docs reflect runtime shape
  • Use consistent comment style across the repo (JSDoc or TSDoc)
  • Run documentation generation as part of CI to catch drift

Example use cases

  • Add JSDoc to a utility module with several undocumented exported functions
  • Generate a props table and examples for a newly created Button component
  • Produce Markdown API pages for a public client library release
  • Create Storybook stories (Default, Variants, Sizes, Loading, Disabled) for UI components
  • Batch-document all public exports before publishing a package

FAQ

Will this change runtime code?

No. It only adds or updates comments and separate documentation files; runtime behavior is unaffected.

Can I control which formats are generated?

Yes. You can choose JSDoc/TSDoc, Markdown, Storybook stories, or any combination before generation.