Skip to main content
skill CX Codex

route-to-openapi — Claude Code skill: OpenAPI from routes

Reads route definitions in your source tree and writes an OpenAPI 3.0.3 spec. Useful when an API needs docs and nobody wants to type them out.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add zebbern/claude-code-guide --skill route-to-openapi -a claude-code
Open on GitHub

What route-to-openapi does

Point the skill at a source directory and it walks the code looking for endpoints. It collects HTTP methods, paths, parameters, request bodies and response models, then emits a spec you can load into Swagger UI or Redoc. Path syntax gets normalised: Flask's <int:user_id>, Express and Gin's :user_id all come out as {user_id}. Descriptions are pulled from docstrings, JSDoc and inline comments, and operations are tagged by module name.

The entry point is python scripts/generate_api_doc.py ./src. Output format is picked with --format (json or yaml), the destination with --output, and API metadata with --title, --version and --description. Repeat --server for each server URL. Framework detection is automatic; --framework overrides it. Flask, FastAPI, Django REST Framework, Express.js, Gin and Echo are covered.

Python 3.8 or newer is required, and nothing else — the script sticks to the standard library. Python frameworks are parsed as AST, while Express, Gin and Echo are matched with regexes, so routes hidden behind custom wrappers will not show up in the spec. The project you scan has to use one of the supported frameworks.

What it helps with

  • generate an OpenAPI spec from routes that already exist
  • list every endpoint and its parameters in an unfamiliar repo
  • normalise Flask and Express paths into {param} form
  • produce a file to import into Swagger UI or Redoc
  • refresh API docs after routes get renamed

Example prompts for the agent

  • Scan ./src and write the OpenAPI spec to api-spec.yaml
  • Generate docs for the Flask routes with title "My API" and version 2.0.0
  • Extract all endpoints under ./routes and add the server http://localhost:3000

How to install route-to-openapi

1Skills CLI (Vercel)

npx skills add zebbern/claude-code-guide --skill route-to-openapi -a claude-code

2Manually: put the files in place

~/.claude/skills/route-to-openapi/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/route-to-openapi/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about route-to-openapi

How do I install route-to-openapi in Claude Code?

Run npx skills add zebbern/claude-code-guide --skill route-to-openapi -a claude-code. The skill lands in ~/.claude/skills/route-to-openapi/SKILL.md.

What does route-to-openapi do?

It scans route definitions and builds an OpenAPI 3.0.3 spec from them: methods, paths, parameters, request bodies, response models and comment-derived descriptions.

Which frameworks does it support?

Flask, FastAPI and Django REST Framework go through AST parsing; Express.js, Gin and Echo are matched by regex. Detection is automatic, and --framework forces a choice.

Source text

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

Similar skills

All skills for Backend and APIs →

From the same set13

secure-code-review This skill walks your code through all ten OWASP Top 10 categories and returns a report with vulnerable examples and working fixes. Useful before a release or when reviewing unfamiliar code. CX Codex +1 ★ 4,679repo stars regression-modeler Fits OLS or logistic regression on your table and explains the coefficients in plain language. Handy when you need significance checks without writing the stats code yourself. CX Codex +1 ★ 4,679repo stars project-sizing-guide Produces effort estimates with PERT, T-shirt sizing or Function Point Analysis. Useful when someone asks how long a feature will take. CX Codex +1 ★ 4,679repo stars pipeline-blueprint The skill hands you CI/CD pipeline templates for GitHub Actions and GitLab CI, picked by project type. Useful when you're setting up CI or cleaning up a pipeline that grew messy. CX Codex +1 ★ 4,679repo stars network-101 A skill that walks the agent through standing up and testing HTTP, HTTPS, SNMP and SMB in a pentest lab, from service config to log analysis. CX Codex +1 ★ 4,679repo stars linux-shell-scripting A skill that hands your agent ready bash templates for backups, resource monitoring, user management and log parsing. Useful when you want a working script, not a sketch. CX Codex +1 ★ 4,679repo stars dev-guide-generator Turns a technical topic into a full tutorial: prerequisites, environment setup, core steps, error troubleshooting and a closing cheatsheet. CX Codex +1 ★ 4,679repo stars database-scout A read-only skill for SQLite and PostgreSQL: lists tables, inspects schemas, previews rows and renders Mermaid ER diagrams. Queries stay read-only. CX Codex +1 ★ 4,679repo stars

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor