route-to-openapi — скилл для Claude Code: OpenAPI из кода
Сканирует определения маршрутов в исходниках и собирает спецификацию OpenAPI 3.0.3. Пригодится, когда документация API нужна, а писать её руками не хочется.
npx skills add zebbern/claude-code-guide --skill route-to-openapi -a claude-codeЧто делает route-to-openapi
Скилл проходит по каталогу с кодом, находит эндпоинты и вытаскивает методы, пути, параметры, тела запросов и модели ответов. Формат параметров приводится к виду {param} — <int:user_id> из Flask, :user_id из Express и Gin превращаются в один и тот же {user_id}. Описания берутся из docstring, JSDoc и комментариев, а теги группируются по имени модуля.
Работает через python scripts/generate_api_doc.py ./src. Формат вывода задаётся флагом --format (json или yaml), файл — через --output, метаданные API — --title, --version, --description, адреса серверов — повторяющимся --server. Фреймворк определяется сам, но его можно зафиксировать через --framework. Поддержаны Flask, FastAPI, Django REST Framework, Express.js, Gin и Echo.
Нужен Python 3.8 или новее, сторонние библиотеки не требуются — скрипт обходится стандартной библиотекой. Разбор идёт по AST для Python-фреймворков и регулярками для Express, Gin и Echo, поэтому нестандартные обёртки над роутами в спецификацию не попадут. Сканируемый проект должен быть на одном из перечисленных фреймворков.
Какие задачи решает
- собрать спецификацию OpenAPI из уже написанных маршрутов
- вытащить список эндпоинтов и их параметров из чужого репозитория
- привести пути Flask и Express к единому формату
{param} - подготовить файл для импорта в Swagger UI или Redoc
- обновить документацию API после переименования роутов
Примеры запросов агенту
- Просканируй
./srcи собери спецификацию OpenAPI вapi-spec.yaml - Сгенерируй документацию по маршрутам Flask с заголовком «My API» и версией 2.0.0
- Найди все эндпоинты в
./routesи добавь серверhttp://localhost:3000
Как установить route-to-openapi
1Через Skills CLI (Vercel)
npx skills add zebbern/claude-code-guide --skill route-to-openapi -a claude-code2Вручную: положить файлы
~/.claude/skills/route-to-openapi/SKILL.mdПапка скилла целиком; для одного проекта — .claude/skills/route-to-openapi/
1Через Skills CLI (Vercel)
npx skills add zebbern/claude-code-guide --skill route-to-openapi -a codex2Вручную: положить файлы
.agents/skills/route-to-openapi/SKILL.mdДля всех проектов — ~/.agents/skills/
1Через Skills CLI (Vercel)
npx skills add zebbern/claude-code-guide --skill route-to-openapi -a cursor2Вручную: положить файлы
.cursor/skills/route-to-openapi/SKILL.mdCursor читает и .agents/skills/, и .claude/skills/
1GitHub CLI
gh skill install zebbern/claude-code-guide route-to-openapi2Вручную: положить файлы
.github/skills/route-to-openapi/SKILL.md1Через Skills CLI (Vercel)
npx skills add zebbern/claude-code-guide --skill route-to-openapi -a gemini-cli2Командой платформы
gemini skills install https://github.com/zebbern/claude-code-guide --path skills/route-to-openapiВручную: положить файлы
.devin/skills/route-to-openapi/SKILL.mdСтарый путь .windsurf/skills/ тоже читается
Через Skills CLI (Vercel)
npx skills add zebbern/claude-code-guide --skill route-to-openapi -a opencodeClaude.ai
Упакуйте папку в zip и загрузите в Settings → Capabilities → Skills
По шагам, с командами для каждой платформы: Как установить скилл в Claude Code: пять способов
Вопросы о route-to-openapi
Как установить route-to-openapi в Claude Code?
Выполните npx skills add zebbern/claude-code-guide --skill route-to-openapi -a claude-code. Скилл появится в ~/.claude/skills/route-to-openapi/SKILL.md.
Что делает route-to-openapi?
Сканирует определения маршрутов и собирает из них спецификацию OpenAPI 3.0.3: методы, пути, параметры, тела запросов, модели ответов и описания из комментариев.
Какие фреймворки поддерживаются?
Flask, FastAPI и Django REST Framework разбираются через AST, Express.js, Gin и Echo — регулярками. Фреймворк определяется автоматически, но его можно задать флагом --framework.
Исходный текст
SKILL.md · MIT
---
name: route-to-openapi
description: "Generates RESTful API documentation (OpenAPI 3.0 / Swagger spec) by scanning route definitions in code for Flask, FastAPI, Express, Gin, and other frameworks. Trigger when users ask about API documentation, OpenAPI, Swagger, endpoint docs, generating docs from code, or extracting endpoints."
license: MIT
---
# route-to-openapi
Automatically scan route/endpoint definitions in source code and generate RESTful API documentation conforming to the [OpenAPI 3.0.3](https://spec.openapis.org/oas/v3.0.3) specification.
Supports major web frameworks with automatic framework detection. Extracts HTTP methods, paths, parameters, request bodies, response models, and doc comments, then outputs a standard OpenAPI spec file ready to import into Swagger UI or Redoc.
## Quick Start
```bash
# Scan source directory, output OpenAPI spec in JSON format
python scripts/generate_api_doc.py ./src
# Specify output format and file
python scripts/generate_api_doc.py ./src --format yaml --output api-spec.yaml
# Specify framework and API metadata
python scripts/generate_api_doc.py ./app --framework flask --title "My API" --version 2.0.0
# Add server URLs
python scripts/generate_api_doc.py ./routes --server http://localhost:3000 --server https://api.example.com
```
## Supported Frameworks
| Language | Framework | Parsing Method |
|---|---|---|
| Python | Flask | AST parsing (decorators + type annotations + docstrings) |
| Python | FastAPI | AST parsing (decorators + Pydantic models + type annotations) |
| Python | Django REST Framework | AST parsing (`@api_view` decorators) |
| JavaScript/TypeScript | Express.js | Regex matching (`app.get()` / `router.get()` + JSDoc) |
| Go | Gin | Regex matching (`r.GET()` / `group.GET()` + comments) |
| Go | Echo | Regex matching (`e.GET()` + comments) |
## Extraction Capabilities
The script automatically extracts the following information:
- **HTTP Methods**: GET / POST / PUT / DELETE / PATCH, etc.
- **Route Paths**: Automatically converts each framework's path parameter format to the OpenAPI `{param}` format
- **Path Parameters**: Extracted from route patterns (with type inference)
- **Query Parameters**: Extracted from function signatures (Python frameworks)
- **Request Bodies**: Inferred from type annotations and Pydantic models (FastAPI)
- **Response Models**: Extracted from the `response_model` parameter (FastAPI)
- **Endpoint Descriptions**: Extracted from docstrings / JSDoc / inline comments
- **Tag Grouping**: Automatically grouped by source file module name
## Path Parameter Format Conversion
| Framework | Source Format | Converted Result |
|---|---|---|
| Flask | `<int:user_id>` | `{user_id}` (type: integer) |
| FastAPI | `{user_id}` | `{user_id}` (unchanged) |
| Express | `:user_id` | `{user_id}` |
| Gin/Echo | `:user_id` | `{user_id}` |
## Parameters
| Parameter | Description | Default |
|---|---|---|
| `source_dir` | Source directory to scan (required) | - |
| `-f, --format` | Output format: `json` or `yaml` | `json` |
| `-o, --output` | Output file path | stdout |
| `--framework` | Force a specific framework (skip auto-detection) | Auto-detect |
| `--title` | API documentation title | `API Documentation` |
| `--version` | API version number | `1.0.0` |
| `--description` | API description text | Empty |
| `--server` | Server URL (can be specified multiple times) | None |
## Output Example
```json
{
"openapi": "3.0.3",
"info": {
"title": "My API",
"version": "1.0.0"
},
"paths": {
"/users": {
"get": {
"summary": "List all users",
"operationId": "list_users",
"tags": ["users"],
"parameters": [
{
"name": "limit",
"in": "query",
"required": false,
"schema": { "type": "integer" }
}
],
"responses": {
"200": { "description": "Successful response" }
}
}
},
"/users/{user_id}": {
"get": {
"summary": "Get user by ID",
"operationId": "get_user",
"tags": ["users"],
"parameters": [
{
"name": "user_id",
"in": "path",
"required": true,
"schema": { "type": "integer" }
}
],
"responses": {
"200": { "description": "Successful response" }
}
}
}
}
}
```
## Prerequisites
- Python 3.8+
- No additional dependencies required — uses only the Python standard library
- The scanned project must use one of the supported web frameworks listed above
© zebbern · MIT · zebbern/claude-code-guide