К основному содержанию
команда

doc-api — команда для Claude Code: документация API из кода

Разбирает код проекта и собирает документацию по API: спецификацию, примеры запросов и ответов, интерактивную страницу. Пригодится, когда эндпоинтов много, а описывать их руками не хочется.

Установить в Claude Code · Через claude-code-templates Все способы и платформы ↓
npx claude-code-templates@latest --command documentation/doc-api
Открыть на GitHub

Что делает doc-api

Команда doc-api сканирует репозиторий в поисках роутов, контроллеров и схем. Дальше выбирает инструмент под стек: OpenAPI/Swagger для REST, GraphiQL или Apollo Studio для GraphQL, Postman, Redoc, API Blueprint. На выходе — спецификация с методами, параметрами, кодами ответов и моделями данных.

Внутри есть шаги под аутентификацию (API-ключи, JWT, OAuth), обработку ошибок, версионирование, лимиты и пагинацию. Отдельно описана генерация клиентских библиотек и настройка Swagger UI. Для Node.js/Express приводится связка swagger-jsdoc и swagger-ui-express, для FastAPI — docstrings, для Java — аннотации @ApiOperation и @ApiParam.

Аргумент задаёт тип API: --openapi, --graphql, --rest, --grpc или --interactive. Команда ищет файлы по именам вроде *route*, *controller*, *openapi*, *.graphql и читает package.json — если структура проекта нетипичная, часть эндпоинтов она просто не найдёт, и это повод проверить выдачу перед публикацией. Инструменты ограничены: Read, Write, Edit, Bash.

Какие задачи решает

  • собрать спецификацию OpenAPI по существующим роутам
  • описать коды ошибок и схемы ответов для каждого эндпоинта
  • поднять интерактивную страницу Swagger UI рядом с проектом
  • задокументировать авторизацию: ключи, JWT, OAuth-схемы
  • сгенерировать коллекцию тестов из описания API

Примеры запросов агенту

  • /doc-api --openapi
  • /doc-api --graphql
  • /doc-api --rest --interactive

Как установить doc-api

1Через claude-code-templates

npx claude-code-templates@latest --command documentation/doc-api

2Вручную: положить файлы

.claude/commands/doc-api.md

Вызов — /doc-api. Для всех проектов — ~/.claude/commands/

Из того же набора184

Весь набор →
optimize-database-performance Слэш-команда для Claude, которая разбирает запросы, индексы и схему базы и предлагает, что переписать. Пригодится, когда страница тормозит на выборке. 794установок mcp-protocol-specialist Субагент для работы со спецификацией Model Context Protocol: транспорт, JSON-RPC 2.0, версионирование и совместимость реализаций. 781установок draw-io Скилл для Claude, который правит .drawio XML, конвертирует файлы в PNG и подгоняет расположение элементов на схеме. 757установок comprehensive-researcher Субагент для Claude, который разбирает тему на вопросы, ищет источники и собирает отчёт со ссылками. Пригодится, когда нужен обзор, а не ответ по памяти. 735установок vault-optimizer Субагент Claude для оптимизации хранилища Obsidian: находит тяжёлые файлы, разбирается с вложениями и ускоряет поиск. 727установок bright-data-mcp Скилл заставляет агента брать любые веб-данные через MCP-сервер Bright Data вместо встроенных WebFetch и WebSearch. Пригодится, когда страницы закрыты бот-защитой или нужен готовый JSON. 722установок planning Ведёт markdown-файлы с целями, находками и логом сессии, чтобы агент не потерял задачу на длинной цепочке шагов. 712установок setup-development-environment Слэш-команда разворачивает окружение разработки: рантаймы, инструменты, сборку, линтеры и конфиги. Пригодится, когда проект только разворачивают на новой машине. 651установок

Похожие

api-reference-documentation aj-geddes Скилл помогает агенту собрать справочник по API: эндпоинты, аутентификация, примеры запросов и ответов, спецификация OpenAPI. CX Codex +1 494установок api-documentation bobmatnyc Набор правил, по которым агент пишет докстринги, JSDoc, Godoc и описания эндпоинтов. Пригодится, когда API документируют в нескольких агентах и текст расползается. CX Codex +1 379установок api-documenter zhaono1 Скилл для описания REST и GraphQL API в формате OpenAPI/Swagger. Пригодится, когда нужно превратить россыпь эндпоинтов в читаемую спецификацию. CX Codex +1 717установок doc-generator luongnv89 Скилл читает исходники и собирает документацию API: спецификации OpenAPI, описания эндпоинтов, примеры на cURL, JavaScript и Python. CX Codex +1 ★ 45 153звёзд репо openapi-generator patricio0312rev Собирает спецификацию OpenAPI 3.0/3.1 из маршрутов Express, Next.js, Fastify, Hono или NestJS — со схемами, примерами и описаниями. CX Codex +1 306установок api-recon-and-docs yaklang Скилл помогает исследовать структуру REST, mobile и GraphQL API перед тестированием. Он ищет скрытые эндпоинты, схемы и старые версии интерфейсов. CX Codex +1 3 800установок

Рядом в теме «Бэкенд и API»

Всё по теме «Бэкенд и API» →

Вопросы о doc-api

Как установить doc-api в Claude?

Через шаблоны: npx claude-code-templates@latest --command documentation/doc-api. Файл появится по пути .claude/commands/doc-api.md.

Что делает doc-api?

Находит эндпоинты и схемы в коде, а затем пишет по ним документацию: спецификацию, примеры запросов и ответов, разделы про аутентификацию и ошибки. Может собрать интерактивную страницу на Swagger UI.

Какие типы API поддерживаются?

REST, GraphQL и gRPC — через аргументы --rest, --graphql, --grpc. Есть также --openapi и --interactive.

Исходный текст

doc-api.md · MIT
---
allowed-tools: Read, Write, Edit, Bash
argument-hint: "[api-type] | --openapi | --graphql | --rest | --grpc | --interactive"
description: Generate comprehensive API documentation from code with interactive examples and testing capabilities
---

# API Documentation Generator

Generate API documentation from code: $ARGUMENTS

## Current API Context

- API endpoints: !`find . -name "*route*" -o -name "*controller*" -o -name "*api*" | head -5`
- API specs: !`find . -name "*openapi*" -o -name "*swagger*" -o -name "*.graphql" | head -3`
- Server framework: @package.json or detect from imports
- Existing docs: @docs/api/ or @api-docs/ (if exists)
- Test files: !`find . -name "*test*" -path "*/api/*" | head -3`

## Task

Generate comprehensive API documentation with interactive features: $ARGUMENTS

1. **Code Analysis and Discovery**
   - Scan the codebase for API endpoints, routes, and handlers
   - Identify REST APIs, GraphQL schemas, and RPC services
   - Map out controller classes, route definitions, and middleware
   - Discover request/response models and data structures

2. **Documentation Tool Selection**
   - Choose appropriate documentation tools based on stack:
     - **OpenAPI/Swagger**: REST APIs with interactive documentation
     - **GraphQL**: GraphiQL, GraphQL Playground, or Apollo Studio
     - **Postman**: API collections and documentation
     - **Insomnia**: API design and documentation
     - **Redoc**: Alternative OpenAPI renderer
     - **API Blueprint**: Markdown-based API documentation

3. **API Specification Generation**
   
   **For REST APIs with OpenAPI:**
   ```yaml
   openapi: 3.0.0
   info:
     title: $ARGUMENTS API
     version: 1.0.0
     description: Comprehensive API for $ARGUMENTS
   servers:
     - url: https://api.example.com/v1
   paths:
     /users:
       get:
         summary: List users
         parameters:
           - name: page
             in: query
             schema:
               type: integer
         responses:
           '200':
             description: Successful response
             content:
               application/json:
                 schema:
                   type: array
                   items:
                     $ref: '#/components/schemas/User'
   components:
     schemas:
       User:
         type: object
         properties:
           id:
             type: integer
           name:
             type: string
           email:
             type: string
   ```

4. **Endpoint Documentation**
   - Document all HTTP methods (GET, POST, PUT, DELETE, PATCH)
   - Specify request parameters (path, query, header, body)
   - Define response schemas and status codes
   - Include error responses and error codes
   - Document authentication and authorization requirements

5. **Request/Response Examples**
   - Provide realistic request examples for each endpoint
   - Include sample response data with proper formatting
   - Show different response scenarios (success, error, edge cases)
   - Document content types and encoding

6. **Authentication Documentation**
   - Document authentication methods (API keys, JWT, OAuth)
   - Explain authorization scopes and permissions
   - Provide authentication examples and token formats
   - Document session management and refresh token flows

7. **Data Model Documentation**
   - Define all data schemas and models
   - Document field types, constraints, and validation rules
   - Include relationships between entities
   - Provide example data structures

8. **Error Handling Documentation**
   - Document all possible error responses
   - Explain error codes and their meanings
   - Provide troubleshooting guidance
   - Include rate limiting and throttling information

9. **Interactive Documentation Setup**
   
   **Swagger UI Integration:**
   ```html
   <!DOCTYPE html>
   <html>
   <head>
     <title>API Documentation</title>
     <link rel="stylesheet" type="text/css" href="./swagger-ui-bundle.css" />
   </head>
   <body>
     <div id="swagger-ui"></div>
     <script src="./swagger-ui-bundle.js"></script>
     <script>
       SwaggerUIBundle({
         url: './api-spec.yaml',
         dom_id: '#swagger-ui'
       });
     </script>
   </body>
   </html>
   ```

10. **Code Annotation and Comments**
    - Add inline documentation to API handlers
    - Use framework-specific annotation tools:
      - **Java**: @ApiOperation, @ApiParam (Swagger annotations)
      - **Python**: Docstrings with FastAPI or Flask-RESTX
      - **Node.js**: JSDoc comments with swagger-jsdoc
      - **C#**: XML documentation comments

11. **Automated Documentation Generation**
    
    **For Node.js/Express:**
    ```javascript
    const swaggerJsdoc = require('swagger-jsdoc');
    const swaggerUi = require('swagger-ui-express');
    
    const options = {
      definition: {
        openapi: '3.0.0',
        info: {
          title: 'API Documentation',
          version: '1.0.0',
        },
      },
      apis: ['./routes/*.js'],
    };
    
    const specs = swaggerJsdoc(options);
    app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(specs));
    ```

12. **Testing Integration**
    - Generate API test collections from documentation
    - Include test scripts and validation rules
    - Set up automated API testing
    - Document test scenarios and expected outcomes

13. **Version Management**
    - Document API versioning strategy
    - Maintain documentation for multiple API versions
    - Document deprecation timelines and migration guides
    - Track breaking changes between versions

14. **Performance Documentation**
    - Document rate limits and throttling policies
    - Include performance benchmarks and SLAs
    - Document caching strategies and headers
    - Explain pagination and filtering options

15. **SDK and Client Library Documentation**
    - Generate client libraries from API specifications
    - Document SDK usage and examples
    - Provide quickstart guides for different languages
    - Include integration examples and best practices

16. **Environment-Specific Documentation**
    - Document different environments (dev, staging, prod)
    - Include environment-specific endpoints and configurations
    - Document deployment and configuration requirements
    - Provide environment setup instructions

17. **Security Documentation**
    - Document security best practices
    - Include CORS and CSP policies
    - Document input validation and sanitization
    - Explain security headers and their purposes

18. **Maintenance and Updates**
    - Set up automated documentation updates
    - Create processes for keeping documentation current
    - Review and validate documentation regularly
    - Integrate documentation reviews into development workflow

**Framework-Specific Examples:**

**FastAPI (Python):**
```python
from fastapi import FastAPI
from pydantic import BaseModel

app = FastAPI(title="My API", version="1.0.0")

class User(BaseModel):
    id: int
    name: str
    email: str

@app.get("/users/{user_id}", response_model=User)
async def get_user(user_id: int):
    """Get a user by ID."""
    return {"id": user_id, "name": "John", "email": "[email protected]"}
```

**Spring Boot (Java):**
```java
@RestController
@Api(tags = "Users")
public class UserController {
    
    @GetMapping("/users/{id}")
    @ApiOperation(value = "Get user by ID")
    public ResponseEntity<User> getUser(
        @PathVariable @ApiParam("User ID") Long id) {
        // Implementation
    }
}
```

Remember to keep documentation up-to-date with code changes and make it easily accessible to both internal teams and external consumers.

© davila7 · MIT · davila7/claude-code-templates

Смотрите также

Спонсоры проекта

Компании, которые помогают держать аналитику открытой